OSDN Git Service

add package
[bytom/vapor.git] / vendor / github.com / multiformats / go-multiaddr / varint_test.go
diff --git a/vendor/github.com/multiformats/go-multiaddr/varint_test.go b/vendor/github.com/multiformats/go-multiaddr/varint_test.go
new file mode 100644 (file)
index 0000000..817b3dd
--- /dev/null
@@ -0,0 +1,23 @@
+package multiaddr
+
+import (
+       "encoding/binary"
+       "testing"
+)
+
+func checkVarint(t *testing.T, x int) {
+       buf := make([]byte, binary.MaxVarintLen64)
+       expected := binary.PutUvarint(buf, uint64(x))
+
+       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) {
+       max := 1 << 16
+       for x := 0; x < max; x++ {
+               checkVarint(t, x)
+       }
+}