1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-07-02 03:35:23 +00:00
OpenDiablo2/common/BitStream_test.go

34 lines
698 B
Go
Raw Normal View History

2019-11-07 03:12:15 +00:00
package common
2019-10-25 19:06:47 +00:00
import (
"testing"
)
func TestBitStreamBits(t *testing.T) {
data := []byte{0xAA}
bitStream := CreateBitStream(data)
shouldBeOne := 0
for i := 0; i < 8; i++ {
bit := bitStream.ReadBits(1)
if bit != shouldBeOne {
t.Fatalf("Expected %d but got %d on iteration %d", shouldBeOne, bit, i)
}
if shouldBeOne == 1 {
shouldBeOne = 0
} else {
shouldBeOne = 1
}
}
}
func TestBitStreamBytes(t *testing.T) {
data := []byte{0xAA, 0xBB, 0xCC, 0xDD, 0x12, 0x34, 0x56, 0x78}
bitStream := CreateBitStream(data)
for i := 0; i < 8; i++ {
b := byte(bitStream.ReadBits(8))
if b != data[i] {
t.Fatalf("Expected %d but got %d on iteration %d", data[i], b, i)
}
}
}