-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patharithmetic_test.go
66 lines (54 loc) · 2.65 KB
/
arithmetic_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
package protean
import (
"bytes"
"encoding/hex"
"testing"
)
// The encoding input is a simple numerical sequence.
// The encoding output is taken from a reference implementation.
func TestEncodingShort(t *testing.T) {
frequencies := sampleDecompressionConfig().Frequencies
encoder := NewEncoder(frequencies)
plain, _ := hex.DecodeString("00010203")
target, _ := hex.DecodeString("CA0001020300000008")
result := encoder.Encode(plain)
if !bytes.Equal(result, target) {
t.Fail()
}
}
// The decoding input is taken from the output of the encoding test.
// The decoding output is taken from the input of the encoding test.
func TestDecodingShort(t *testing.T) {
frequencies := sampleDecompressionConfig().Frequencies
decoder := NewDecoder(frequencies)
encoded, _ := hex.DecodeString("CA0001020300000008")
target, _ := hex.DecodeString("00010203")
result := decoder.Decode(encoded)
if !bytes.Equal(result, target) {
t.Fail()
}
}
// The encoding input is an example of a real WebRTC packet.
// The encoding output is taken from a reference implementation.
func TestEncodingLong(t *testing.T) {
frequencies := sampleDecompressionConfig().Frequencies
encoder := NewEncoder(frequencies)
plain, _ := hex.DecodeString("0001005C2112A442484E436A4E475466373145420006002134474A396549694D755955354338496A3A697A7251347772576670316B57664464000000802900089A85CD9550C8EE0A002400046E7E1EFF000800140345954222F0DA663E8EB8CC79A1F7BA010FD50080280004E2284303")
target, _ := hex.DecodeString("CA0001005C2112A442484E436A4E475466373145420006002134474A396549694D755955354338496A3A697A7251347772576670316B57664464000000802900089A85CD9550C8EE0A002400046E7E1EFF000800140345954222F0DA663E8EB8CC79A1F7BA010FD50080280004E228430300000074")
encoded := encoder.Encode(plain)
if !bytes.Equal(encoded, target) {
t.Fail()
}
}
// The decoding input is taken from the output of the encoding test.
// The decoding output is taken from the input of the encoding test.
func TestDecodingLong(t *testing.T) {
frequencies := sampleDecompressionConfig().Frequencies
decoder := NewDecoder(frequencies)
encoded, _ := hex.DecodeString("CA0001005C2112A442484E436A4E475466373145420006002134474A396549694D755955354338496A3A697A7251347772576670316B57664464000000802900089A85CD9550C8EE0A002400046E7E1EFF000800140345954222F0DA663E8EB8CC79A1F7BA010FD50080280004E228430300000074")
target, _ := hex.DecodeString("0001005C2112A442484E436A4E475466373145420006002134474A396549694D755955354338496A3A697A7251347772576670316B57664464000000802900089A85CD9550C8EE0A002400046E7E1EFF000800140345954222F0DA663E8EB8CC79A1F7BA010FD50080280004E2284303")
decoded := decoder.Decode(encoded)
if !bytes.Equal(decoded, target) {
t.Fail()
}
}