// TestWriteAndCommitBit checks that bits can be written.
TestWriteAndCommitBit checks that bits can be written.
// TestWriteAndCommitBit checks that bits can be written .
func TestWriteAndCommitBit(t *testing.T) {
	var b bytes.Buffer
	w := NewWriter(&b, 2)
	bits := []Bit{
		0, 1, 0, 1, 1, 0, 1, 0,
		1, 1, 1, 1,
	}
	for i, bit := range bits {
		var wantWritten int
		if i%16 == 15 {
			wantWritten = 16
		}
		written, err := w.WriteBit(bit)
		if written != wantWritten {
			t.Errorf(`Writing bit %d: written = %v, want %v`, i, written, wantWritten)
		}
		if err != nil {
			t.Fatalf(`err = %v, want nil`, err)
		}
	}
	written, err := w.Commit()
	if written != 16 {
		t.Errorf(`written = %v, want 16`, written)
	}
	if err != nil {
		t.Fatalf(`err = %v, want nil`, err)
	}
	expected := []byte{0b01011010, 0b11110000}
	for i, actual := range b.Bytes() {
		if want := expected[i]; actual != want {
			t.Errorf(`Byte %d = %08b, want %08b`, i, actual, want)
		}
	}
}
func TestWriteAndCommitBit ( t * testing . T ) { var b bytes . Buffer w := NewWriter ( & b , 2 ) bits := [ ] Bit { 0 , 1 , 0 , 1 , 1 , 0 , 1 , 0 , 1 , 1 , 1 , 1 , } for i , bit := range bits { var wantWritten int if i % 16 == 15 { wantWritten = 16 } written , err := w . WriteBit ( bit ) if written != wantWritten { t . Errorf ( `Writing bit %d: written = %v, want %v` , i , written , wantWritten ) } if err != nil { t . Fatalf ( `err = %v, want nil` , err ) } } written , err := w . Commit ( ) if written != 16 { t . Errorf ( `written = %v, want 16` , written ) } if err != nil { t . Fatalf ( `err = %v, want nil` , err ) } expected := [ ] byte { 0b01011010 , 0b11110000 } for i , actual := range b . Bytes ( ) { if want := expected [ i ] ; actual != want { t . Errorf ( `Byte %d = %08b, want %08b` , i , actual , want ) } } }
TestWriteAndCommitBit checks that bits can be written.
TestWriteAndCommitBit checks that bits can be written .