-
Notifications
You must be signed in to change notification settings - Fork 0
/
bitmap_test.go
126 lines (104 loc) · 2.29 KB
/
bitmap_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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
Copyright (C) 2024 Carl-Philip Hänsch
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package NonLockingReadMap
import "fmt"
import "testing"
func TestSimple(t *testing.T) {
bm := NewBitMap()
if bm.Size() != 48 {
t.Fatalf("empty map size")
}
if bm.Count() != 0 {
t.Fatalf("count = 0 .1")
}
if bm.Get(0) {
t.Fatalf("read 0")
}
if bm.Get(1000) {
t.Fatalf("read 1000")
}
if bm.Count() != 0 {
t.Fatalf("count = 0 .2")
}
bm.Set(5, true)
bm.Set(6, true)
bm.Set(77, true)
bm.Set(1000, true)
if bm.Count() != 4 {
t.Fatalf("count = 4")
}
if bm.CountUntil(6) != 1 {
t.Fatalf("countuntil 5: " + fmt.Sprint(bm.CountUntil(6)))
}
if bm.CountUntil(7) != 2 {
t.Fatalf("countuntil 6: " + fmt.Sprint(bm.CountUntil(7)))
}
if bm.CountUntil(100) != 3 {
t.Fatalf("countuntil 100: " + fmt.Sprint(bm.CountUntil(100)))
}
if bm.CountUntil(10000) != 4 {
t.Fatalf("countuntil 10000: " + fmt.Sprint(bm.CountUntil(10000)))
}
if bm.Get(0) {
t.Fatalf("read 0 .2")
}
if bm.Get(4) {
t.Fatalf("read 4")
}
if !bm.Get(5) {
t.Fatalf("read 5")
}
if !bm.Get(6) {
t.Fatalf("read 6")
}
if bm.Get(7) {
t.Fatalf("read 7")
}
if bm.Get(63) {
t.Fatalf("read 63")
}
if bm.Get(64) {
t.Fatalf("read 64")
}
if bm.Get(71) {
t.Fatalf("read 71")
}
if !bm.Get(77) {
t.Fatalf("read 77")
}
if !bm.Get(1000) {
t.Fatalf("read 1000 .2")
}
if bm.Get(3000) {
t.Fatalf("read over size")
}
bm.Set(6, false)
if bm.Count() != 3 {
t.Fatalf("count = 3")
}
if !bm.Get(5) {
t.Fatalf("read 5 .2")
}
if bm.Get(6) {
t.Fatalf("read 6 .2")
}
bm.Reset()
if bm.Get(0) {
t.Fatalf("read 0 .3")
}
if bm.Get(1000) {
t.Fatalf("read 1000 .3")
}
}
// TODO: parallel concurrent test