lazarus/streaming/streaming_test.go

43 lines
684 B
Go
Raw Normal View History

2019-01-14 03:02:49 +00:00
package streaming
2019-01-16 02:53:13 +00:00
import (
"bytes"
"testing"
)
2019-01-14 03:02:49 +00:00
func TestBitReader(t *testing.T) {
2019-01-16 02:53:13 +00:00
data := []byte{
0x69, // 01101001
0x96, // 10010110
0xf0, // 11110000
0xaa, // 10101010
0x00, // 00000000
0xff, // 11111111
}
2019-01-14 03:02:49 +00:00
2019-01-16 03:44:02 +00:00
r := NewReader(bytes.NewReader(data))
readPass := func(c int, v uint64) {
if value, err := r.ReadBits(c); value != v || err != nil {
t.Fail()
}
}
readFail := func(c int) {
if value, err := r.ReadBits(c); value != 0 || err == nil {
t.Fail()
}
}
readPass(0, 0x00)
readFail(65)
readPass(2, 0x01)
readPass(2, 0x02)
readPass(3, 0x04)
readPass(1, 0x01)
readPass(12, 0x096f)
readPass(8, 0x000a)
readPass(20, 0x0a00ff)
readFail(1)
2019-01-14 03:02:49 +00:00
}