-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomp_test.go
More file actions
62 lines (50 loc) · 1.32 KB
/
comp_test.go
File metadata and controls
62 lines (50 loc) · 1.32 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
50
51
52
53
54
55
56
57
58
59
60
61
62
package chego
import (
"testing"
)
func TestHuffmanEncoding(t *testing.T) {
expected := []byte{
0b11101110, 0b00001010, 0b01100000,
}
got := HuffmanEncoding([]byte{9, 9, 22, 17})
for i, b := range expected {
if got[i] != b {
t.Fatalf("expected: %v, got: %v", expected, got)
}
}
}
func TestHuffmanDecoding(t *testing.T) {
indices := []int{9, 9, 22, 17}
w := bitWriter{remainingBits: intSize}
for _, i := range indices {
w.write(huffmanCodes[i].code, huffmanCodes[i].size)
}
expected := []PlayedMove{
{"e4", "rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR"},
{"e5", "rnbqkbnr/pppp1ppp/8/4p3/4P3/8/PPPP1PPP/RNBQKBNR"},
{"Bc4", "rnbqkbnr/pppp1ppp/8/4p3/2B1P3/8/PPPP1PPP/RNBQK1NR"},
{"Nf6", "rnbqkb1r/pppp1ppp/5n2/4p3/2B1P3/8/PPPP1PPP/RNBQK1NR"},
}
got := HuffmanDecoding(w.content(), len(indices))
for i, m := range expected {
if got[i] != m {
t.Fatalf("expected: %v, got: %v", expected, got)
}
}
}
func BenchmarkMakeTrie(b *testing.B) {
for b.Loop() {
makeTrie()
}
}
func BenchmarkCompressTimeDiffs(b *testing.B) {
for b.Loop() {
CompressTimeDiffs([]int{-20, -30, -40, 2, 4, 10, -200, 10})
}
}
func BenchmarkDecompressTimeDiffs(b *testing.B) {
for b.Loop() {
DecompressTimeDiffs([]byte{0b00101001, 0b01001010, 0b00000111,
0b11000001, 0b10111100, 0b10111000, 0b10001000, 0b11000001}, 6)
}
}