@@ -19,41 +19,43 @@ package common
1919import (
2020 "bytes"
2121 "testing"
22-
23- checker "gopkg.in/check.v1"
2422)
2523
26- type BytesSuite struct {}
27-
28- var _ = checker .Suite (& BytesSuite {})
24+ func TestCopyBytes (t * testing.T ) {
25+ input := []byte {1 , 2 , 3 , 4 }
2926
30- func (s * BytesSuite ) TestCopyBytes (c * checker.C ) {
31- data1 := []byte {1 , 2 , 3 , 4 }
32- exp1 := []byte {1 , 2 , 3 , 4 }
33- res1 := CopyBytes (data1 )
34- c .Assert (res1 , checker .DeepEquals , exp1 )
27+ v := CopyBytes (input )
28+ if ! bytes .Equal (v , []byte {1 , 2 , 3 , 4 }) {
29+ t .Fatal ("not equal after copy" )
30+ }
31+ v [0 ] = 99
32+ if bytes .Equal (v , input ) {
33+ t .Fatal ("result is not a copy" )
34+ }
3535}
3636
37- func (s * BytesSuite ) TestLeftPadBytes (c * checker.C ) {
38- val1 := []byte {1 , 2 , 3 , 4 }
39- exp1 := []byte {0 , 0 , 0 , 0 , 1 , 2 , 3 , 4 }
40-
41- res1 := LeftPadBytes (val1 , 8 )
42- res2 := LeftPadBytes (val1 , 2 )
37+ func TestLeftPadBytes (t * testing.T ) {
38+ val := []byte {1 , 2 , 3 , 4 }
39+ padded := []byte {0 , 0 , 0 , 0 , 1 , 2 , 3 , 4 }
4340
44- c .Assert (res1 , checker .DeepEquals , exp1 )
45- c .Assert (res2 , checker .DeepEquals , val1 )
41+ if r := LeftPadBytes (val , 8 ); ! bytes .Equal (r , padded ) {
42+ t .Fatalf ("LeftPadBytes(%v, 8) == %v" , val , r )
43+ }
44+ if r := LeftPadBytes (val , 2 ); ! bytes .Equal (r , val ) {
45+ t .Fatalf ("LeftPadBytes(%v, 2) == %v" , val , r )
46+ }
4647}
4748
48- func ( s * BytesSuite ) TestRightPadBytes (c * checker. C ) {
49+ func TestRightPadBytes (t * testing. T ) {
4950 val := []byte {1 , 2 , 3 , 4 }
50- exp := []byte {1 , 2 , 3 , 4 , 0 , 0 , 0 , 0 }
51-
52- resstd := RightPadBytes (val , 8 )
53- resshrt := RightPadBytes (val , 2 )
51+ padded := []byte {1 , 2 , 3 , 4 , 0 , 0 , 0 , 0 }
5452
55- c .Assert (resstd , checker .DeepEquals , exp )
56- c .Assert (resshrt , checker .DeepEquals , val )
53+ if r := RightPadBytes (val , 8 ); ! bytes .Equal (r , padded ) {
54+ t .Fatalf ("RightPadBytes(%v, 8) == %v" , val , r )
55+ }
56+ if r := RightPadBytes (val , 2 ); ! bytes .Equal (r , val ) {
57+ t .Fatalf ("RightPadBytes(%v, 2) == %v" , val , r )
58+ }
5759}
5860
5961func TestFromHex (t * testing.T ) {
0 commit comments