Files
go-nkode/util/util_test.go

55 lines
1.2 KiB
Go

package util
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestGenerateRandomNonRepeatingUint64(t *testing.T) {
arrLen := 100000
randNumbs, err := GenerateRandomNonRepeatingUint64(arrLen)
assert.NoError(t, err)
assert.Equal(t, len(randNumbs), arrLen)
}
func TestEncodeDecode(t *testing.T) {
testArr := []uint64{1, 2, 3, 4, 5, 6}
testEncode := EncodeBase64Str(testArr)
testDecode, err := DecodeBase64Str(testEncode)
assert.NoError(t, err)
assert.Equal(t, len(testArr), len(testDecode))
for idx, val := range testArr {
assert.Equal(t, val, testDecode[idx])
}
}
func TestMatrixTranspose(t *testing.T) {
matrix := [][]int{
{0, 1, 2},
{3, 4, 5},
}
expectedMatrixT := [][]int{
{0, 3},
{1, 4},
{2, 5},
}
expectedFlatMat := MatrixToList(expectedMatrixT)
matrixT, err := MatrixTranspose(matrix)
assert.NoError(t, err)
flatMat := MatrixToList(matrixT)
assert.Equal(t, len(flatMat), len(expectedFlatMat))
for idx := range flatMat {
assert.Equal(t, expectedFlatMat[idx], flatMat[idx])
}
}
func TestIntToByteAndBack(t *testing.T) {
origIntArr := []int{1, 2, 3, 4, 5}
byteArr := IntArrToByteArr(origIntArr)
intArr := ByteArrToIntArr(byteArr)
assert.ElementsMatch(t, origIntArr, intArr)
}