155 lines
2.8 KiB
Go
155 lines
2.8 KiB
Go
package cc
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
var lastUniqueElementsTestCases = []struct {
|
|
in []string
|
|
out []string
|
|
}{
|
|
{
|
|
in: []string{"a"},
|
|
out: []string{"a"},
|
|
},
|
|
{
|
|
in: []string{"a", "b"},
|
|
out: []string{"a", "b"},
|
|
},
|
|
{
|
|
in: []string{"a", "a"},
|
|
out: []string{"a"},
|
|
},
|
|
{
|
|
in: []string{"a", "b", "a"},
|
|
out: []string{"b", "a"},
|
|
},
|
|
{
|
|
in: []string{"b", "a", "a"},
|
|
out: []string{"b", "a"},
|
|
},
|
|
{
|
|
in: []string{"a", "a", "b"},
|
|
out: []string{"a", "b"},
|
|
},
|
|
{
|
|
in: []string{"a", "b", "a", "b"},
|
|
out: []string{"a", "b"},
|
|
},
|
|
{
|
|
in: []string{"liblog", "libdl", "libc++", "libdl", "libc", "libm"},
|
|
out: []string{"liblog", "libc++", "libdl", "libc", "libm"},
|
|
},
|
|
}
|
|
|
|
func TestLastUniqueElements(t *testing.T) {
|
|
for _, testCase := range lastUniqueElementsTestCases {
|
|
out := lastUniqueElements(testCase.in)
|
|
if !reflect.DeepEqual(out, testCase.out) {
|
|
t.Errorf("incorrect output:")
|
|
t.Errorf(" input: %#v", testCase.in)
|
|
t.Errorf(" expected: %#v", testCase.out)
|
|
t.Errorf(" got: %#v", out)
|
|
}
|
|
}
|
|
}
|
|
|
|
var (
|
|
str11 = "01234567891"
|
|
str10 = str11[:10]
|
|
str9 = str11[:9]
|
|
str5 = str11[:5]
|
|
str4 = str11[:4]
|
|
)
|
|
|
|
var splitListForSizeTestCases = []struct {
|
|
in []string
|
|
out [][]string
|
|
size int
|
|
}{
|
|
{
|
|
in: []string{str10},
|
|
out: [][]string{{str10}},
|
|
size: 10,
|
|
},
|
|
{
|
|
in: []string{str9},
|
|
out: [][]string{{str9}},
|
|
size: 10,
|
|
},
|
|
{
|
|
in: []string{str5},
|
|
out: [][]string{{str5}},
|
|
size: 10,
|
|
},
|
|
{
|
|
in: []string{str11},
|
|
out: nil,
|
|
size: 10,
|
|
},
|
|
{
|
|
in: []string{str10, str10},
|
|
out: [][]string{{str10}, {str10}},
|
|
size: 10,
|
|
},
|
|
{
|
|
in: []string{str9, str10},
|
|
out: [][]string{{str9}, {str10}},
|
|
size: 10,
|
|
},
|
|
{
|
|
in: []string{str10, str9},
|
|
out: [][]string{{str10}, {str9}},
|
|
size: 10,
|
|
},
|
|
{
|
|
in: []string{str5, str4},
|
|
out: [][]string{{str5, str4}},
|
|
size: 10,
|
|
},
|
|
{
|
|
in: []string{str5, str4, str5},
|
|
out: [][]string{{str5, str4}, {str5}},
|
|
size: 10,
|
|
},
|
|
{
|
|
in: []string{str5, str4, str5, str4},
|
|
out: [][]string{{str5, str4}, {str5, str4}},
|
|
size: 10,
|
|
},
|
|
{
|
|
in: []string{str5, str4, str5, str5},
|
|
out: [][]string{{str5, str4}, {str5}, {str5}},
|
|
size: 10,
|
|
},
|
|
{
|
|
in: []string{str5, str5, str5, str4},
|
|
out: [][]string{{str5}, {str5}, {str5, str4}},
|
|
size: 10,
|
|
},
|
|
{
|
|
in: []string{str9, str11},
|
|
out: nil,
|
|
size: 10,
|
|
},
|
|
{
|
|
in: []string{str11, str9},
|
|
out: nil,
|
|
size: 10,
|
|
},
|
|
}
|
|
|
|
func TestSplitListForSize(t *testing.T) {
|
|
for _, testCase := range splitListForSizeTestCases {
|
|
out, _ := splitListForSize(testCase.in, testCase.size)
|
|
if !reflect.DeepEqual(out, testCase.out) {
|
|
t.Errorf("incorrect output:")
|
|
t.Errorf(" input: %#v", testCase.in)
|
|
t.Errorf(" size: %d", testCase.size)
|
|
t.Errorf(" expected: %#v", testCase.out)
|
|
t.Errorf(" got: %#v", out)
|
|
}
|
|
}
|
|
}
|