neoneo-go/pkg/util/slice/array_test.go

46 lines
715 B
Go
Raw Normal View History

package slice
import (
"testing"
2019-11-24 14:55:50 +00:00
"github.com/stretchr/testify/require"
)
2020-02-06 08:56:34 +00:00
var testCases = []struct {
arr []byte
rev []byte
}{
{
arr: []byte{},
rev: []byte{},
},
{
arr: []byte{0x01},
rev: []byte{0x01},
},
{
arr: []byte{0x01, 0x02, 0x03, 0x04},
rev: []byte{0x04, 0x03, 0x02, 0x01},
},
{
arr: []byte{0x01, 0x02, 0x03, 0x04, 0x05},
rev: []byte{0x05, 0x04, 0x03, 0x02, 0x01},
},
}
func TestCopyReverse(t *testing.T) {
2020-02-06 08:56:34 +00:00
for _, tc := range testCases {
arg := make([]byte, len(tc.arr))
copy(arg, tc.arr)
have := CopyReverse(arg)
2020-02-06 08:56:34 +00:00
require.Equal(t, tc.rev, have)
// test that argument was copied
for i := range have {
have[i] = ^have[i]
}
require.Equal(t, tc.arr, arg)
2020-02-06 08:56:34 +00:00
}
}