1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
//go:build go1.18
package compact
import (
"testing"
)
// Test that RangeNodes returns a slice of nodes with contiguous coverage.
// https://github.com/transparency-dev/merkle/blob/main/docs/compact_ranges.md#definition
func FuzzRangeNodes(f *testing.F) {
for begin := 0; begin <= 10; begin++ {
for end := begin; end <= 20; end++ {
f.Add(uint64(end), uint64(end))
}
}
f.Fuzz(func(t *testing.T, begin, end uint64) {
if begin > end {
return
}
t.Logf("begin=%d, end=%d", begin, end)
nodes := RangeNodes(begin, end, nil)
t.Logf("nodes=%v", nodes)
// Nodes should be contiguous covering begin to end
previousEnd := begin
for _, node := range nodes {
b, e := node.Coverage()
if b != previousEnd {
t.Errorf("got=%d, want=%d", b, previousEnd)
}
previousEnd = e
}
if previousEnd != end {
t.Errorf("got=%d, want=%d", previousEnd, end)
}
})
}
|