forked from qedus/osmpbf
-
Notifications
You must be signed in to change notification settings - Fork 2
/
id_tracker_test.go
52 lines (46 loc) · 981 Bytes
/
id_tracker_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
package gosmonaut
import (
"testing"
)
func TestIDTracker(t *testing.T) {
// Test number series
for m := int64(1); m <= 10; m++ {
var c idTracker = newBitsetIDTracker()
n := 0
r := int64(5000 / m * m)
for i := r; i >= -r; i -= m {
c.set(i)
c.set(i)
n++
if c.len() != n {
t.Error("Tracker length is wrong")
}
}
for i := r; i >= -r; i -= m {
contains := i%m == 0
if c.get(i) != contains {
t.Error("Tracker failed for ID", i)
}
}
}
c := newBitsetIDTracker()
testIDTracker(t, c, 0, 1)
testIDTracker(t, c, 1, 2)
testIDTracker(t, c, -5123, 3)
testIDTracker(t, c, 5955111, 4)
testIDTracker(t, c, -92233720, 5)
testIDTracker(t, c, 92233720, 6)
}
func testIDTracker(t *testing.T, c idTracker, n int64, l int) {
if c.get(n) {
t.Error("Tracker already contained number")
}
c.set(n)
if !c.get(n) {
t.Error("Tracker does not contain number")
}
// Check length
if l != c.len() {
t.Error("Tracker length is wrong")
}
}