-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgolumb_test.go
68 lines (51 loc) · 936 Bytes
/
golumb_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
package disttopk
import "testing"
import "bytes"
import "io"
import "math/rand"
import "sort"
func TestGolumbReaderWriter(t *testing.T) {
var b bytes.Buffer
n := 1000
inta := make([]uint, 0, n)
w := NewGolumbEncoder(&b, 5) //m ==32
for i := 0; i < n; i++ {
num := uint(rand.Int() % 64)
inta = append(inta, num)
w.Write(num)
}
w.Close()
r := NewGolumbDecoder(&b, 5)
for i := 0; i < n; i++ {
test, err := r.Read()
if err != nil {
t.Fail()
}
if test != inta[i] {
t.Fail()
}
}
_, err := r.Read()
if err != io.EOF {
t.Fail()
}
}
func TestGolumbSlice(t *testing.T) {
n := 1000
inta := make([]int, 0, n)
for i := 0; i < n; i++ {
num := int(rand.Int() % 10000)
inta = append(inta, num)
}
compressed := GolumbEncode(inta)
newa, err := GolumbDecode(compressed)
if err != nil {
t.Fail()
}
sort.Ints(inta)
for i := 0; i < n; i++ {
if newa[i] != inta[i] {
t.Fail()
}
}
}