Example #1
0
func TestEncodeBitsMasksExcess(t *testing.T) {
	for _, tc := range []bitTestCase{
		{0, []byte{255, 255}, ""},
		{1, []byte{255, 255}, "o"},
		{2, []byte{255, 255}, "a"},
		{3, []byte{255, 255}, "h"},
		{4, []byte{255, 255}, "6"},
		{5, []byte{255, 255}, "9"},
		{6, []byte{255, 255}, "9o"},
		{7, []byte{255, 255}, "9a"},
		{8, []byte{255, 255}, "9h"},
		{9, []byte{255, 255}, "96"},
		{10, []byte{255, 255}, "99"},
		{11, []byte{255, 255}, "99o"},
		{12, []byte{255, 255}, "99a"},
		{13, []byte{255, 255}, "99h"},
		{14, []byte{255, 255}, "996"},
		{15, []byte{255, 255}, "999"},
		{16, []byte{255, 255}, "999o"},
	} {
		dst := make([]byte, zbase32.EncodedLen(len(tc.decoded)))
		n := zbase32.EncodeBits(dst, tc.decoded, tc.bits)
		dst = dst[:n]
		if g, e := string(dst), tc.encoded; g != e {
			t.Errorf("EncodeBits %d bits of %x wrong result: %q != %q", tc.bits, tc.decoded, g, e)
		}
	}
}
Example #2
0
func TestEncodeBits(t *testing.T) {
	for _, tc := range bitTests {
		dst := make([]byte, zbase32.EncodedLen(len(tc.decoded)))
		n := zbase32.EncodeBits(dst, tc.decoded, tc.bits)
		dst = dst[:n]
		if g, e := string(dst), tc.encoded; g != e {
			t.Errorf("EncodeBits %d bits of %x wrong result: %q != %q", tc.bits, tc.decoded, g, e)
			continue
		}
	}
}