|
|
@ -86,8 +86,7 @@ func TestHexToCompactInPlace(t *testing.T) { |
|
|
|
} { |
|
|
|
} { |
|
|
|
hexBytes, _ := hex.DecodeString(key) |
|
|
|
hexBytes, _ := hex.DecodeString(key) |
|
|
|
exp := hexToCompact(hexBytes) |
|
|
|
exp := hexToCompact(hexBytes) |
|
|
|
sz := hexToCompactInPlace(hexBytes) |
|
|
|
got := hexToCompactInPlace(hexBytes) |
|
|
|
got := hexBytes[:sz] |
|
|
|
|
|
|
|
if !bytes.Equal(exp, got) { |
|
|
|
if !bytes.Equal(exp, got) { |
|
|
|
t.Fatalf("test %d: encoding err\ninp %v\ngot %x\nexp %x\n", i, key, got, exp) |
|
|
|
t.Fatalf("test %d: encoding err\ninp %v\ngot %x\nexp %x\n", i, key, got, exp) |
|
|
|
} |
|
|
|
} |
|
|
@ -102,8 +101,7 @@ func TestHexToCompactInPlaceRandom(t *testing.T) { |
|
|
|
hexBytes := keybytesToHex(key) |
|
|
|
hexBytes := keybytesToHex(key) |
|
|
|
hexOrig := []byte(string(hexBytes)) |
|
|
|
hexOrig := []byte(string(hexBytes)) |
|
|
|
exp := hexToCompact(hexBytes) |
|
|
|
exp := hexToCompact(hexBytes) |
|
|
|
sz := hexToCompactInPlace(hexBytes) |
|
|
|
got := hexToCompactInPlace(hexBytes) |
|
|
|
got := hexBytes[:sz] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if !bytes.Equal(exp, got) { |
|
|
|
if !bytes.Equal(exp, got) { |
|
|
|
t.Fatalf("encoding err \ncpt %x\nhex %x\ngot %x\nexp %x\n", |
|
|
|
t.Fatalf("encoding err \ncpt %x\nhex %x\ngot %x\nexp %x\n", |
|
|
@ -119,6 +117,13 @@ func BenchmarkHexToCompact(b *testing.B) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func BenchmarkHexToCompactInPlace(b *testing.B) { |
|
|
|
|
|
|
|
testBytes := []byte{0, 15, 1, 12, 11, 8, 16 /*term*/} |
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ { |
|
|
|
|
|
|
|
hexToCompactInPlace(testBytes) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func BenchmarkCompactToHex(b *testing.B) { |
|
|
|
func BenchmarkCompactToHex(b *testing.B) { |
|
|
|
testBytes := []byte{0, 15, 1, 12, 11, 8, 16 /*term*/} |
|
|
|
testBytes := []byte{0, 15, 1, 12, 11, 8, 16 /*term*/} |
|
|
|
for i := 0; i < b.N; i++ { |
|
|
|
for i := 0; i < b.N; i++ { |
|
|
|