-
Notifications
You must be signed in to change notification settings - Fork 4
/
bitvector_32_test.go
53 lines (44 loc) · 1.09 KB
/
bitvector_32_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
package bitvector_test
import (
"github.com/teivah/bitvector"
"math"
"testing"
"github.com/stretchr/testify/assert"
)
func Test_Len32(t *testing.T) {
var bv bitvector.Len32
// Set
assert.Equal(t, bitvector.Len32(0), bv)
bv = bv.Set(0, true)
assert.Equal(t, bitvector.Len32(1), bv)
bv = bv.Set(31, true)
assert.Equal(t, bitvector.Len32(2147483649), bv)
bv = bv.Set(32, true)
assert.Equal(t, bitvector.Len32(2147483649), bv)
bv = bv.Set(30, true)
assert.Equal(t, bitvector.Len32(3221225473), bv)
bv = bv.Set(30, false)
assert.Equal(t, bitvector.Len32(2147483649), bv)
// Count
assert.Equal(t, uint8(2), bv.Count())
// Get
assert.True(t, bv.Get(0))
assert.True(t, bv.Get(31))
assert.False(t, bv.Get(30))
// Toggle
bv = 0
bv = bv.Toggle(15)
assert.Equal(t, bitvector.Len32(32768), bv)
// Clear
bv = 0
var i uint8
for ; i < 32; i++ {
bv = bv.Set(i, true)
}
bv = bv.Clear(6, 2)
assert.Equal(t, bitvector.Len32(math.MaxUint32), bv)
bv = bv.Clear(2, 6)
assert.Equal(t, bitvector.Len32(4294967235), bv)
// String
assert.Equal(t, "11111111111111111111111111000011", bv.String())
}