2020-06-08 03:29:51 +03:00
|
|
|
package bitio_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2021-08-17 13:06:32 +03:00
|
|
|
|
|
|
|
"github.com/wader/fq/pkg/bitio"
|
2020-06-08 03:29:51 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestBitString(t *testing.T) {
|
|
|
|
testCases := []string{
|
|
|
|
"",
|
|
|
|
"1",
|
|
|
|
"0",
|
|
|
|
"10",
|
|
|
|
"01",
|
|
|
|
"11",
|
|
|
|
"00",
|
|
|
|
"1000001",
|
|
|
|
"0000000",
|
|
|
|
"10000001",
|
|
|
|
"00000000",
|
|
|
|
"100000001",
|
|
|
|
"000000000",
|
|
|
|
"101010101",
|
|
|
|
"111100000",
|
|
|
|
}
|
|
|
|
for _, tC := range testCases {
|
|
|
|
t.Run(tC, func(t *testing.T) {
|
|
|
|
bb, bbBits := bitio.BytesFromBitString(tC)
|
|
|
|
actual := bitio.BitStringFromBytes(bb, bbBits)
|
|
|
|
if tC != actual {
|
|
|
|
t.Errorf("expected %s, got %s", tC, actual)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|