Files
x-realy/varint/varint_test.go
2025-05-31 00:32:41 +01:00

30 lines
431 B
Go

package varint
import (
"bytes"
"math"
"testing"
"lukechampine.com/frand"
"x.realy.lol/chk"
)
func TestEncode_Decode(t *testing.T) {
var v uint64
for range 10000000 {
v = uint64(frand.Intn(math.MaxInt64))
buf1 := new(bytes.Buffer)
Encode(buf1, v)
buf2 := bytes.NewBuffer(buf1.Bytes())
u, err := Decode(buf2)
if chk.E(err) {
t.Fatal(err)
}
if u != v {
t.Fatalf("expected %d got %d", v, u)
}
}
}