Example #1
0
func BenchmarkMohaeUvarintMaxLen(b *testing.B) {
	var res uint64
	b.SetBytes(8)
	for i := 0; i < b.N; i++ {
		res, _ = uvarint.Uvarint(tests[17].encoded)
	}
	_ = res
}
Example #2
0
func BenchmarkMohaeUvarintAll(b *testing.B) {
	var res uint64
	b.SetBytes(8)
	for i := 0; i < b.N; i++ {
		for _, test := range tests {
			res, _ = uvarint.Uvarint(test.encoded)
		}
	}
	_ = res
}
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)
		}
	}
}