You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
734 B
Go

package dmr
9 years ago
import (
"bytes"
"testing"
)
9 years ago
func TestBit(t *testing.T) {
var tests = []struct {
Test []byte
Want []byte
9 years ago
}{
{
[]byte{0x2a},
[]byte{0, 0, 1, 0, 1, 0, 1, 0},
9 years ago
},
{
[]byte{0xbe, 0xef},
[]byte{1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1},
9 years ago
},
}
for _, test := range tests {
got := BytesToBits(test.Test)
9 years ago
if len(got) != len(test.Want) {
t.Fatalf("expected length %d, got %d [%s]", len(test.Want), len(got), string(got))
9 years ago
}
for i, b := range got {
if b != test.Want[i] {
t.Fatalf("bit %d is off: %v != %v", i, got, test.Want)
}
}
rev := BitsToBytes(got)
if !bytes.Equal(rev, test.Test) {
t.Fatalf("reverse bits to bytes failed, %v != %v", rev, test.Test)
}
9 years ago
}
}