varint_test.go 426 Bytes
Newer Older
1 2
package multiaddr

3 4 5 6 7 8 9 10
import (
	"encoding/binary"
	"testing"
)

func checkVarint(t *testing.T, x int) {
	buf := make([]byte, binary.MaxVarintLen64)
	expected := binary.PutUvarint(buf, uint64(x))
11 12 13 14 15 16 17 18

	size := VarintSize(x)
	if size != expected {
		t.Fatalf("expected varintsize of %d to be %d, got %d", x, expected, size)
	}
}

func TestVarintSize(t *testing.T) {
19 20 21 22
	max := 1 << 16
	for x := 0; x < max; x++ {
		checkVarint(t, x)
	}
23
}