1package cc
2
3import (
4	"reflect"
5	"testing"
6)
7
8var lastUniqueElementsTestCases = []struct {
9	in  []string
10	out []string
11}{
12	{
13		in:  []string{"a"},
14		out: []string{"a"},
15	},
16	{
17		in:  []string{"a", "b"},
18		out: []string{"a", "b"},
19	},
20	{
21		in:  []string{"a", "a"},
22		out: []string{"a"},
23	},
24	{
25		in:  []string{"a", "b", "a"},
26		out: []string{"b", "a"},
27	},
28	{
29		in:  []string{"b", "a", "a"},
30		out: []string{"b", "a"},
31	},
32	{
33		in:  []string{"a", "a", "b"},
34		out: []string{"a", "b"},
35	},
36	{
37		in:  []string{"a", "b", "a", "b"},
38		out: []string{"a", "b"},
39	},
40	{
41		in:  []string{"liblog", "libdl", "libc++", "libdl", "libc", "libm"},
42		out: []string{"liblog", "libc++", "libdl", "libc", "libm"},
43	},
44}
45
46func TestLastUniqueElements(t *testing.T) {
47	for _, testCase := range lastUniqueElementsTestCases {
48		out := lastUniqueElements(testCase.in)
49		if !reflect.DeepEqual(out, testCase.out) {
50			t.Errorf("incorrect output:")
51			t.Errorf("     input: %#v", testCase.in)
52			t.Errorf("  expected: %#v", testCase.out)
53			t.Errorf("       got: %#v", out)
54		}
55	}
56}
57
58var (
59	str11 = "01234567891"
60	str10 = str11[:10]
61	str9  = str11[:9]
62	str5  = str11[:5]
63	str4  = str11[:4]
64)
65
66var splitListForSizeTestCases = []struct {
67	in   []string
68	out  [][]string
69	size int
70}{
71	{
72		in:   []string{str10},
73		out:  [][]string{{str10}},
74		size: 10,
75	},
76	{
77		in:   []string{str9},
78		out:  [][]string{{str9}},
79		size: 10,
80	},
81	{
82		in:   []string{str5},
83		out:  [][]string{{str5}},
84		size: 10,
85	},
86	{
87		in:   []string{str11},
88		out:  nil,
89		size: 10,
90	},
91	{
92		in:   []string{str10, str10},
93		out:  [][]string{{str10}, {str10}},
94		size: 10,
95	},
96	{
97		in:   []string{str9, str10},
98		out:  [][]string{{str9}, {str10}},
99		size: 10,
100	},
101	{
102		in:   []string{str10, str9},
103		out:  [][]string{{str10}, {str9}},
104		size: 10,
105	},
106	{
107		in:   []string{str5, str4},
108		out:  [][]string{{str5, str4}},
109		size: 10,
110	},
111	{
112		in:   []string{str5, str4, str5},
113		out:  [][]string{{str5, str4}, {str5}},
114		size: 10,
115	},
116	{
117		in:   []string{str5, str4, str5, str4},
118		out:  [][]string{{str5, str4}, {str5, str4}},
119		size: 10,
120	},
121	{
122		in:   []string{str5, str4, str5, str5},
123		out:  [][]string{{str5, str4}, {str5}, {str5}},
124		size: 10,
125	},
126	{
127		in:   []string{str5, str5, str5, str4},
128		out:  [][]string{{str5}, {str5}, {str5, str4}},
129		size: 10,
130	},
131	{
132		in:   []string{str9, str11},
133		out:  nil,
134		size: 10,
135	},
136	{
137		in:   []string{str11, str9},
138		out:  nil,
139		size: 10,
140	},
141}
142
143func TestSplitListForSize(t *testing.T) {
144	for _, testCase := range splitListForSizeTestCases {
145		out, _ := splitListForSize(testCase.in, testCase.size)
146		if !reflect.DeepEqual(out, testCase.out) {
147			t.Errorf("incorrect output:")
148			t.Errorf("     input: %#v", testCase.in)
149			t.Errorf("      size: %d", testCase.size)
150			t.Errorf("  expected: %#v", testCase.out)
151			t.Errorf("       got: %#v", out)
152		}
153	}
154}
155