-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbitstream_test.go
62 lines (52 loc) · 1.23 KB
/
bitstream_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
package prores
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestBitstream_ReadSmallUnary(t *testing.T) {
bs := &Bitstream{
Bytes: []byte{0x00, 0x08, 0x80, 0, 0, 0, 0, 1, 1},
}
var n int
assert.True(t, bs.ReadSmallUnary(&n))
assert.Equal(t, 12, n)
assert.True(t, bs.ReadSmallUnary(&n))
assert.Equal(t, 3, n)
assert.True(t, bs.ReadSmallUnary(&n))
assert.Equal(t, 46, n)
assert.True(t, bs.ReadSmallUnary(&n))
assert.Equal(t, 7, n)
assert.False(t, bs.ReadSmallUnary(&n))
}
func TestBitstream_ReadInt(t *testing.T) {
bs := &Bitstream{
Bytes: []byte{0x08, 0x08},
}
var n int
assert.True(t, bs.ReadInt(8, &n))
assert.Equal(t, 0x08, n)
assert.True(t, bs.ReadInt(6, &n))
assert.Equal(t, 2, n)
}
func TestBitstream_ReadBit(t *testing.T) {
bs := &Bitstream{
Bytes: []byte{0x08},
}
var v bool
assert.True(t, bs.ReadBit(&v))
assert.False(t, v)
assert.True(t, bs.ReadBit(&v))
assert.False(t, v)
assert.True(t, bs.ReadBit(&v))
assert.False(t, v)
assert.True(t, bs.ReadBit(&v))
assert.False(t, v)
assert.True(t, bs.ReadBit(&v))
assert.True(t, v)
assert.True(t, bs.ReadBit(&v))
assert.False(t, v)
assert.True(t, bs.ReadBit(&v))
assert.False(t, v)
assert.True(t, bs.ReadBit(&v))
assert.False(t, v)
}