-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcounters_test.go
More file actions
49 lines (42 loc) · 1.01 KB
/
counters_test.go
File metadata and controls
49 lines (42 loc) · 1.01 KB
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
package fsst
import "testing"
func TestCountersBasic(t *testing.T) {
var c counters
// Test single-symbol counting
c.incSingle(5)
if c.single[5] != 1 {
t.Fatalf("incSingle first increment: got %d, want 1", c.single[5])
}
c.incSingle(5)
if c.single[5] != 2 {
t.Fatalf("incSingle second increment: got %d, want 2", c.single[5])
}
// Test pair counting
c.incPair(3, 4)
if c.pair[3][4] != 1 {
t.Fatalf("incPair first increment: got %d, want 1", c.pair[3][4])
}
// Test nextSingle
code := uint32(6)
c.incSingle(10)
count := c.nextSingle(&code)
if count == 0 || code != 10 {
t.Fatalf("nextSingle failed: code=%d count=%d", code, count)
}
// Test pairCount
c.incPair(10, 2)
pairCnt := c.pairCount(10, 2)
if pairCnt != 1 {
t.Fatalf("pairCount failed: got %d, want 1", pairCnt)
}
// Test counting to 256 and beyond
var c2 counters
for i := 0; i < 300; i++ {
c2.incSingle(0)
}
code = 0
got := c2.nextSingle(&code)
if got != 300 {
t.Fatalf("high count failed: expected 300, got %d", got)
}
}