2020-03-06 01:38:02 +00:00
|
|
|
package utils
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestShouldSplitIntoEvenStringsOfFour(t *testing.T) {
|
2020-05-02 16:20:40 +00:00
|
|
|
input := testStringInput
|
2020-03-06 01:38:02 +00:00
|
|
|
arrayOfStrings := SliceString(input, 4)
|
|
|
|
assert.Equal(t, len(arrayOfStrings), 3)
|
|
|
|
assert.Equal(t, "abcd", arrayOfStrings[0])
|
|
|
|
assert.Equal(t, "efgh", arrayOfStrings[1])
|
|
|
|
assert.Equal(t, "ijkl", arrayOfStrings[2])
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestShouldSplitIntoEvenStringsOfOne(t *testing.T) {
|
2020-05-02 16:20:40 +00:00
|
|
|
input := testStringInput
|
2020-03-06 01:38:02 +00:00
|
|
|
arrayOfStrings := SliceString(input, 1)
|
|
|
|
assert.Equal(t, 12, len(arrayOfStrings))
|
|
|
|
assert.Equal(t, "a", arrayOfStrings[0])
|
|
|
|
assert.Equal(t, "b", arrayOfStrings[1])
|
|
|
|
assert.Equal(t, "c", arrayOfStrings[2])
|
|
|
|
assert.Equal(t, "d", arrayOfStrings[3])
|
|
|
|
assert.Equal(t, "l", arrayOfStrings[11])
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestShouldSplitIntoUnevenStringsOfFour(t *testing.T) {
|
2020-05-02 16:20:40 +00:00
|
|
|
input := testStringInput + "m"
|
2020-03-06 01:38:02 +00:00
|
|
|
arrayOfStrings := SliceString(input, 4)
|
|
|
|
assert.Equal(t, len(arrayOfStrings), 4)
|
|
|
|
assert.Equal(t, "abcd", arrayOfStrings[0])
|
|
|
|
assert.Equal(t, "efgh", arrayOfStrings[1])
|
|
|
|
assert.Equal(t, "ijkl", arrayOfStrings[2])
|
|
|
|
assert.Equal(t, "m", arrayOfStrings[3])
|
|
|
|
}
|