Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
mf
go-multiaddr
Commits
11c75668
Commit
11c75668
authored
Nov 29, 2018
by
Steven Allen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test: test all varints less than 2**16 againt VarintSize
parent
d462e342
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
5 deletions
+12
-5
varint_test.go
varint_test.go
+12
-5
No files found.
varint_test.go
View file @
11c75668
package
multiaddr
import
"testing"
import
(
"encoding/binary"
"testing"
)
func
checkVarint
(
t
*
testing
.
T
,
x
int
)
{
buf
:=
make
([]
byte
,
binary
.
MaxVarintLen64
)
expected
:=
binary
.
PutUvarint
(
buf
,
uint64
(
x
))
func
expectVarint
(
t
*
testing
.
T
,
x
,
expected
int
)
{
size
:=
VarintSize
(
x
)
if
size
!=
expected
{
t
.
Fatalf
(
"expected varintsize of %d to be %d, got %d"
,
x
,
expected
,
size
)
...
...
@@ -10,7 +16,8 @@ func expectVarint(t *testing.T, x, expected int) {
}
func
TestVarintSize
(
t
*
testing
.
T
)
{
expectVarint
(
t
,
(
1
<<
7
)
-
1
,
1
)
expectVarint
(
t
,
0
,
1
)
expectVarint
(
t
,
1
<<
7
,
2
)
max
:=
1
<<
16
for
x
:=
0
;
x
<
max
;
x
++
{
checkVarint
(
t
,
x
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment