Skip to content

Commit 7aca9a0

Browse files
committed
add test case for Decode function
1 parent b460395 commit 7aca9a0

File tree

1 file changed

+43
-5
lines changed

1 file changed

+43
-5
lines changed

encoding_test.go

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,49 @@ func TestEncodeSlice(t *testing.T) {
6363
}
6464

6565
func TestDecode(t *testing.T) {
66-
var a uint64
67-
a = 123456
68-
bytes := Encode(a)
69-
t.Log(bytes)
70-
t.Log(Decode[uint64](bytes))
66+
67+
// case: value 0
68+
{
69+
v := Decode[uint]([]byte{0x0})
70+
assert.Equal(t, uint(0), v)
71+
}
72+
73+
// case: value 1
74+
{
75+
v := Decode[uint]([]byte{0x1})
76+
assert.Equal(t, uint(1), v)
77+
}
78+
79+
// case: value 2
80+
{
81+
v := Decode[uint]([]byte{0x2})
82+
assert.Equal(t, uint(2), v)
83+
}
84+
85+
// case: value 127
86+
{
87+
v := Decode[uint]([]byte{0x7f})
88+
assert.Equal(t, uint(127), v)
89+
}
90+
91+
// case: value 128
92+
{
93+
v := Decode[uint]([]byte{0x80, 0x1})
94+
assert.Equal(t, uint(128), v)
95+
}
96+
97+
// case: value 255
98+
{
99+
v := Decode[uint]([]byte{0xff, 0x1})
100+
assert.Equal(t, uint(255), v)
101+
}
102+
103+
// case: case: value 256
104+
{
105+
v := Decode[uint]([]byte{0x80, 0x2})
106+
assert.Equal(t, uint(256), v)
107+
}
108+
71109
}
72110

73111
func TestDecodeSlice(t *testing.T) {

0 commit comments

Comments
 (0)