@@ -63,11 +63,49 @@ func TestEncodeSlice(t *testing.T) {
63
63
}
64
64
65
65
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
+
71
109
}
72
110
73
111
func TestDecodeSlice (t * testing.T ) {
0 commit comments