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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
package generics_tree
import (
"testing"
"github.com/kentik/patricia"
"github.com/stretchr/testify/assert"
)
func TestV6MatchCount(t *testing.T) {
node := &treeNodeV6[string]{
prefixLeft: uint64(0xFFFFFFFFFFFFFFFF),
prefixRight: uint64(0xFFFFFFFFFFFFFFFF),
prefixLength: 84,
}
// test moving the non-matching bit forward, making sure we never return more than the length of the prefix
left := uint64(0xFFFFFFFFFFFFFFFF)
for i := 1; i < 128; i++ {
addressLeft := left
if i <= 64 {
addressLeft = clearBit64(addressLeft, uint64(i))
}
expected := i - 1
if i > 64 {
expected = 84
}
address := patricia.IPv6Address{
Left: addressLeft,
Right: uint64(0xFFFFFFFFFFFFFFFF),
Length: 128,
}
assert.Equal(t, uint(expected), node.MatchCount(address))
}
// test moving the non-matching bit forward, making sure we never return more than the length of the address
node.prefixLength = 128
left = uint64(0xFFFFFFFFFFFFFFFF)
for i := 1; i < 128; i++ {
addressLeft := left
if i <= 64 {
addressLeft = clearBit64(addressLeft, uint64(i))
}
expected := i - 1
if i > 64 {
expected = 84
}
address := patricia.IPv6Address{
Left: addressLeft,
Right: uint64(0xFFFFFFFFFFFFFFFF),
Length: 84,
}
assert.Equal(t, uint(expected), node.MatchCount(address))
}
}
|