util: move ArrayReverse into package of its own

Leave just uint160 and uint256 types in util.
This commit is contained in:
Roman Khimov 2021-07-18 15:55:37 +03:00
parent 588f3fbbd3
commit 100e97d772
8 changed files with 28 additions and 21 deletions

View file

@ -0,0 +1,45 @@
package slice
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 TestCopyReverse(t *testing.T) {
for _, tc := range testCases {
arg := make([]byte, len(tc.arr))
copy(arg, tc.arr)
have := CopyReverse(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)
}
}