-
Notifications
You must be signed in to change notification settings - Fork 8
/
ef_test.go
121 lines (114 loc) · 2.47 KB
/
ef_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
package ef
import (
"testing"
)
func TestMembership(t *testing.T) {
num := uint64(1000)
obj := New(num, num)
array := make([]uint64, num)
for i := range array {
array[i] = uint64(i)
}
obj.Compress(array)
for i, v := range array {
if obj.Value() != v {
t.Errorf("%d is not %d. Missing value", obj.Value(), v)
}
_, err := obj.Next()
if err != nil {
if i != len(array)-1 {
t.Error(err)
}
}
}
}
func TestPosition(t *testing.T) {
num := uint64(1000)
obj := New(num, num)
array := make([]uint64, num)
for i := range array {
array[i] = uint64(i)
}
obj.Compress(array)
for i := range array {
if obj.Position() != uint64(i) {
t.Errorf("%d is not %d. Wrong position", obj.Position(), i)
}
obj.Next()
}
}
func TestReset(t *testing.T) {
num := uint64(1000)
obj := New(num, num)
array := make([]uint64, num)
for i := range array {
array[i] = uint64(i)
}
obj.Compress(array)
if obj.Position() != 0 {
t.Errorf("Initial position is not 0.")
}
obj.Next()
obj.Reset()
if obj.Position() != 0 {
t.Errorf("Position not correctly reset.")
}
if obj.Value() != 0 {
t.Errorf("%d is not %d. Missing value", obj.Value(), 0)
}
}
func TestMove(t *testing.T) {
num := uint64(1000)
obj := New(num, num)
array := make([]uint64, num)
for i := range array {
array[i] = uint64(i)
}
obj.Compress(array)
if obj.Position() != 0 {
t.Errorf("Initial position is not 0.")
}
for i, v := range array {
obj.Move(uint64(i))
if obj.Value() != v {
t.Errorf("%d is not %d. Missing value", obj.Value(), v)
}
}
for i := range array {
obj.Move(uint64(len(array) - i - 1))
if obj.Value() != array[len(array)-i-1] {
t.Errorf("%d is not %d. Missing value", obj.Value(), array[len(array)-i-1])
}
}
}
func TestGeneric(t *testing.T) {
obj := New(1000, 5)
obj.Compress([]uint64{0, 5, 9, 800, 1000})
if obj.Value() != 0 {
t.Errorf("%d is not %d. Missing value", obj.Value(), 0)
}
obj.Move(0)
if obj.Value() != 0 {
t.Errorf("%d is not %d. Missing value", obj.Value(), 0)
}
obj.Move(4)
if obj.Value() != 1000 {
t.Errorf("%d is not %d. Missing value", obj.Value(), 1000)
}
obj.Reset()
if obj.Value() != 0 {
t.Errorf("%d is not %d. Missing value", obj.Value(), 0)
}
obj.Next()
if obj.Value() != 5 {
t.Errorf("%d is not %d. Missing value", obj.Value(), 5)
}
obj.Next()
if obj.Value() != 9 {
t.Errorf("%d is not %d. Missing value", obj.Value(), 9)
}
obj.Move(1)
if obj.Value() != 5 {
t.Errorf("%d is not %d. Missing value", obj.Value(), 5)
}
}