mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-30 15:01:35 +00:00
24bb66e606
ArrayReverse copies it's argument only if it's len is > 1. It needs to be consistent in all cases.
45 lines
716 B
Go
45 lines
716 B
Go
package util
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
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 TestArrayReverse(t *testing.T) {
|
|
for _, tc := range testCases {
|
|
arg := make([]byte, len(tc.arr))
|
|
copy(arg, tc.arr)
|
|
|
|
have := ArrayReverse(arg)
|
|
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)
|
|
}
|
|
}
|