func BenchmarkMohaePutUvarintMaxLen(b *testing.B) { buf := make([]byte, 9) var n int b.SetBytes(8) for i := 0; i < b.N; i++ { n = uvarint.PutUvarint(buf, tests[17].decoded) } _ = n }
func BenchmarkMohaePutUvarintAll(b *testing.B) { buf := make([]byte, 9) var n int b.SetBytes(8) for i := 0; i < b.N; i++ { for _, test := range tests { n = uvarint.PutUvarint(buf, test.decoded) } } _ = n }
func TestUvarint(t *testing.T) { for i, test := range tests { b := make([]byte, len(test.encoded)) n := uvarint.PutUvarint(b, test.decoded) if n != test.n { t.Errorf("encode %d: got %d want %d", i, n, test.n) } if !bytes.Equal(b, test.encoded) { t.Errorf("encode %d: got %v want %v", i, b[0:n], test.encoded) } v, n := uvarint.Uvarint(test.encoded) if n != test.n { t.Errorf("decode %d: got %d want %d", i, n, test.n) } if v != test.decoded { t.Errorf("decode %d: got %d want %d", i, v, test.decoded) } } }