2015-04-28 22:30:13 +02:00
|
|
|
package cc
|
|
|
|
|
|
|
|
import (
|
2017-05-09 22:34:34 +02:00
|
|
|
"android/soong/android"
|
2015-04-28 22:30:13 +02:00
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2017-05-17 22:44:16 +02:00
|
|
|
var firstUniqueElementsTestCases = []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{"a", "b"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
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", "libdl", "libc++", "libc", "libm"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestFirstUniqueElements(t *testing.T) {
|
|
|
|
for _, testCase := range firstUniqueElementsTestCases {
|
|
|
|
out := firstUniqueElements(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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-28 22:30:13 +02:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-05-01 01:36:18 +02:00
|
|
|
|
|
|
|
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 {
|
2017-05-09 22:34:34 +02:00
|
|
|
out, _ := splitListForSize(android.PathsForTesting(testCase.in), testCase.size)
|
|
|
|
|
|
|
|
var outStrings [][]string
|
|
|
|
|
|
|
|
if len(out) > 0 {
|
|
|
|
outStrings = make([][]string, len(out))
|
|
|
|
for i, o := range out {
|
|
|
|
outStrings[i] = o.Strings()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(outStrings, testCase.out) {
|
2015-05-01 01:36:18 +02:00
|
|
|
t.Errorf("incorrect output:")
|
|
|
|
t.Errorf(" input: %#v", testCase.in)
|
|
|
|
t.Errorf(" size: %d", testCase.size)
|
|
|
|
t.Errorf(" expected: %#v", testCase.out)
|
2017-05-09 22:34:34 +02:00
|
|
|
t.Errorf(" got: %#v", outStrings)
|
2015-05-01 01:36:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|