-
Notifications
You must be signed in to change notification settings - Fork 20
/
bitset_test.go
102 lines (78 loc) · 1.99 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package goga_test
import (
"github.com/tomcraven/goga"
. "gopkg.in/check.v1"
)
type BitsetSuite struct {
bitset *goga.Bitset
}
func (s *BitsetSuite) SetUpTest(t *C) {
s.bitset = &goga.Bitset{}
}
func (s *BitsetSuite) TearDownTest(t *C) {
s.bitset = nil
}
var _ = Suite(&BitsetSuite{})
func (s *BitsetSuite) TestShouldInstantiate(t *C) {
// Tested as part of fixture setup
}
func (s *BitsetSuite) TestShouldCreate(t *C) {
s.bitset.Create(10)
}
func (s *BitsetSuite) TestShouldGetSize(t *C) {
t.Assert(0, Equals, s.bitset.GetSize())
s.bitset.Create(10)
t.Assert(10, Equals, s.bitset.GetSize())
b := goga.Bitset{}
b.Create(100)
t.Assert(100, Equals, b.GetSize())
t.Assert(b.Set(99, 1), IsTrue)
}
func (s *BitsetSuite) TestShouldSetAndGet(t *C) {
s.bitset.Create(10)
index := 0
value := 1
t.Assert(s.bitset.Set(index, value), IsTrue)
t.Assert(value, Equals, s.bitset.Get(index))
index = 1
value = 0
t.Assert(s.bitset.Set(index, value), IsTrue)
t.Assert(value, Equals, s.bitset.Get(index))
}
func (s *BitsetSuite) TestShouldFailSetAndGetWhenNotCreated(t *C) {
t.Assert(s.bitset.Set(0, 1), IsFalse)
t.Assert(s.bitset.Get(0), Equals, -1)
s.bitset.Create(10)
t.Assert(s.bitset.Set(10, 1), IsFalse)
}
func (s *BitsetSuite) TestShouldSetAll(t *C) {
bitsetSize := 10
s.bitset.Create(bitsetSize)
for i := 0; i < bitsetSize; i {
t.Assert(s.bitset.Get(i), Equals, 0)
}
s.bitset.SetAll(1)
for i := 0; i < bitsetSize; i {
t.Assert(s.bitset.Get(i), Equals, 1)
}
}
func (s *BitsetSuite) TestShouldSlice(t *C) {
s.bitset.Create(10)
s.bitset.SetAll(1)
slice := s.bitset.Slice(0, 3)
t.Assert(slice, FitsTypeOf, goga.Bitset{})
t.Assert(slice.GetSize(), Equals, 3)
for i := 0; i < 3; i {
t.Assert(slice.Get(i), Equals, 1)
}
}
func (s *BitsetSuite) TestShouldGetAll(t *C) {
const kBitsetSize = 10
s.bitset.Create(kBitsetSize)
s.bitset.SetAll(1)
bits := s.bitset.GetAll()
t.Assert(len(bits), Equals, kBitsetSize)
for i := 0; i < kBitsetSize; i {
t.Assert(bits[i], Equals, 1)
}
}