MCPcopy Create free account
hub / github.com/Comcast/gaad / TestReadBitsToByteArray

Function TestReadBitsToByteArray

bitreader/bitreader_test.go:138–173  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

136}
137
138func TestReadBitsToByteArray(t *testing.T) {
139
140 // Input: 01010101 01010101
141 byteArray := []byte{0x55, 0x55}
142 reader := NewBitReader(byteArray)
143
144 reader.Reset()
145 buf, _ := reader.ReadBitsToByteArray(3)
146 if reflect.DeepEqual([]byte{0x02}, buf) == false {
147 t.Errorf("buf %#v must equal {0x02}", buf)
148 }
149
150 reader.Reset()
151 buf, _ = reader.ReadBitsToByteArray(4)
152 if reflect.DeepEqual([]byte{0x05}, buf) == false {
153 t.Errorf("buf %#v must equal {0x05}", buf)
154 }
155
156 reader.Reset()
157 buf, _ = reader.ReadBitsToByteArray(8)
158 if reflect.DeepEqual([]byte{0x55}, buf) == false {
159 t.Errorf("buf %#v must equal {0x55}", buf)
160 }
161
162 reader.Reset()
163 buf, _ = reader.ReadBitsToByteArray(12)
164 if reflect.DeepEqual([]byte{0x05, 0x55}, buf) == false {
165 t.Errorf("buf %#v must equal {0x05, 0x55}", buf)
166 }
167
168 reader.Reset()
169 buf, _ = reader.ReadBitsToByteArray(16)
170 if reflect.DeepEqual([]byte{0x55, 0x55}, buf) == false {
171 t.Errorf("buf %#v must equal {0x55, 0x55}", buf)
172 }
173}
174
175func TestReadBytes(t *testing.T) {
176

Callers

nothing calls this directly

Calls 3

ResetMethod · 0.95
ReadBitsToByteArrayMethod · 0.95
NewBitReaderFunction · 0.85

Tested by

no test coverage detected