-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathcollate_string_test.go
More file actions
44 lines (40 loc) · 1017 Bytes
/
collate_string_test.go
File metadata and controls
44 lines (40 loc) · 1017 Bytes
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
package gson
import "testing"
import "bytes"
func TestSuffixCoding(t *testing.T) {
testcases := [][]byte{
[]byte("hello\x00wo\xffrld\x00"),
[]byte("hello\x00wo\xffrld\x00ln"),
}
for _, bs := range testcases {
code, text := make([]byte, 1024), make([]byte, 1024)
n := suffixEncodeString(bs, code)
code[n] = Terminator
n++
x, y := suffixDecodeString(code[:n], text)
if bytes.Compare(bs, text[:y]) != 0 {
t.Error("Suffix coding for strings failed")
}
if l := len(code[x:n]); l != 0 {
t.Errorf("Suffix coding for strings, residue found %v", l)
}
}
}
func BenchmarkSuffixEncode(b *testing.B) {
var code [1024]byte
bs := []byte("hello\x00wo\xffrld\x00")
for i := 0; i < b.N; i++ {
suffixEncodeString(bs, code[:])
}
}
func BenchmarkSuffixDecode(b *testing.B) {
var code, text [1024]byte
bs := []byte("hello\x00wo\xffrld\x00")
n := suffixEncodeString(bs, code[:])
code[n] = Terminator
n++
b.ResetTimer()
for i := 0; i < b.N; i++ {
suffixDecodeString(code[:n], text[:])
}
}