-
Notifications
You must be signed in to change notification settings - Fork 5
/
bitset_test.go
64 lines (54 loc) · 1.13 KB
/
bitset_test.go
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
59
60
61
62
63
64
package handel
import (
"testing"
"github.com/stretchr/testify/require"
)
var nb = NewWilffBitset
type bitsetTest struct {
fb func() BitSet
bitlength int
cardinality int
setBits []int
}
func TestBitSetWilff(t *testing.T) {
var tests = []bitsetTest{
{func() BitSet { return nb(10) }, 10, 0, []int{}},
{
func() BitSet {
b := nb(10)
b.Set(0, true)
b.Set(1, true)
return b
}, 10, 2, []int{0, 1},
},
{
func() BitSet {
b := nb(10)
b.Set(3, true)
return b
}, 10, 1, []int{3},
},
}
testBitSets(t, tests)
}
func testBitSets(t *testing.T, tests []bitsetTest) {
for _, tt := range tests {
bitset := tt.fb()
require.Equal(t, tt.bitlength, bitset.BitLength())
require.Equal(t, tt.cardinality, bitset.Cardinality())
for _, idx := range tt.setBits {
require.True(t, bitset.Get(idx))
}
}
}
func TestBitSetWilffMarshalling(t *testing.T) {
b := NewWilffBitset(10).(*WilffBitSet)
b.Set(1, true)
b.Set(4, true)
buff, err := b.MarshalBinary()
require.NoError(t, err)
b2 := new(WilffBitSet)
err = b2.UnmarshalBinary(buff)
require.NoError(t, err)
require.Equal(t, b.l, b2.l)
}