|
|
@@ -21,6 +21,7 @@ import (
|
|
|
"io"
|
|
|
"reflect"
|
|
|
"testing"
|
|
|
+ "testing/quick"
|
|
|
)
|
|
|
|
|
|
func TestCountValues(t *testing.T) {
|
|
|
@@ -239,3 +240,40 @@ func TestReadSize(t *testing.T) {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+func TestAppendUint64(t *testing.T) {
|
|
|
+ tests := []struct {
|
|
|
+ input uint64
|
|
|
+ slice []byte
|
|
|
+ output string
|
|
|
+ }{
|
|
|
+ {0, nil, "80"},
|
|
|
+ {1, nil, "01"},
|
|
|
+ {2, nil, "02"},
|
|
|
+ {127, nil, "7F"},
|
|
|
+ {128, nil, "8180"},
|
|
|
+ {129, nil, "8181"},
|
|
|
+ {0xFFFFFF, nil, "83FFFFFF"},
|
|
|
+ {127, []byte{1, 2, 3}, "0102037F"},
|
|
|
+ {0xFFFFFF, []byte{1, 2, 3}, "01020383FFFFFF"},
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, test := range tests {
|
|
|
+ x := AppendUint64(test.slice, test.input)
|
|
|
+ if !bytes.Equal(x, unhex(test.output)) {
|
|
|
+ t.Errorf("AppendUint64(%v, %d): got %x, want %s", test.slice, test.input, x, test.output)
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func TestAppendUint64Random(t *testing.T) {
|
|
|
+ fn := func(i uint64) bool {
|
|
|
+ enc, _ := EncodeToBytes(i)
|
|
|
+ encAppend := AppendUint64(nil, i)
|
|
|
+ return bytes.Equal(enc, encAppend)
|
|
|
+ }
|
|
|
+ config := quick.Config{MaxCountScale: 50}
|
|
|
+ if err := quick.Check(fn, &config); err != nil {
|
|
|
+ t.Fatal(err)
|
|
|
+ }
|
|
|
+}
|