-
Notifications
You must be signed in to change notification settings - Fork 0
/
slice_with_frequency_test.go
40 lines (33 loc) · 1.05 KB
/
slice_with_frequency_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
package unary_coding
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestEncodeSliceWithFrequency(t *testing.T) {
rawSlice := []uint64{
10086, 10086, 1024, 10086, 10086, 1024, 10086, 1024, 10086, 10086, 10086, 1024, 10086, 10086,
}
bytes, frequency := EncodeSliceWithFrequency(rawSlice)
assert.Equal(t, 4, len(bytes))
binaryString := ToBinaryString(bytes)
assert.Equal(t, "10101101010110101101010101101010", binaryString)
assert.Equal(t, []uint64{
uint64(10086),
uint64(1024),
}, frequency)
}
func TestDecodeSliceWithFrequency(t *testing.T) {
rawSlice := []uint64{
10086, 10086, 1024, 10086, 10086, 1024, 10086, 1024, 10086, 10086, 10086, 1024, 10086, 10086,
}
bytes, frequency := EncodeSliceWithFrequency(rawSlice)
assert.Equal(t, 4, len(bytes))
binaryString := ToBinaryString(bytes)
assert.Equal(t, "10101101010110101101010101101010", binaryString)
assert.Equal(t, []uint64{
uint64(10086),
uint64(1024),
}, frequency)
unzipSlice := DecodeSliceWithFrequency[uint64](bytes, frequency)
assert.Equal(t, rawSlice, unzipSlice)
}