-
Notifications
You must be signed in to change notification settings - Fork 0
/
decode_test.go
43 lines (35 loc) · 893 Bytes
/
decode_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
package runlength
import (
"bytes"
"testing"
)
func TestDecode(t *testing.T) {
t.Run("compress", func(tt *testing.T) {
out := bytes.NewBuffer(nil)
src := []byte{5, 1, 3, 2, 1, 3, 1, 4, 4, 5}
r := bytes.NewReader(src)
dec := NewDecoder(r)
if err := dec.Decode(out); err != nil {
tt.Errorf("no error:%+v", err)
}
b := out.Bytes()
tt.Logf("\n%v\n%v", src, b)
if bytes.Equal(b, []byte{1, 1, 1, 1, 1, 2, 2, 2, 3, 4, 5, 5, 5, 5}) != true {
tt.Errorf("actual=%v", b)
}
})
t.Run("redandant", func(tt *testing.T) {
out := bytes.NewBuffer(nil)
src := []byte{1, 1, 1, 2, 1, 3, 1, 4, 1, 5}
r := bytes.NewReader(src)
dec := NewDecoder(r)
if err := dec.Decode(out); err != nil {
tt.Errorf("no error:%+v", err)
}
b := out.Bytes()
tt.Logf("\n%v\n%v", src, b)
if bytes.Equal(b, []byte{1, 2, 3, 4, 5}) != true {
tt.Errorf("actual=%v", b)
}
})
}