blob: 32f92b46c9990e8b71d136cf7b86fea75f254804 [file] [log] [blame]
Colin Crossb6715442017-10-24 11:13:31 -07001// Copyright 2017 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package android
16
17import (
18 "reflect"
19 "testing"
20)
21
22var firstUniqueStringsTestCases = []struct {
23 in []string
24 out []string
25}{
26 {
27 in: []string{"a"},
28 out: []string{"a"},
29 },
30 {
31 in: []string{"a", "b"},
32 out: []string{"a", "b"},
33 },
34 {
35 in: []string{"a", "a"},
36 out: []string{"a"},
37 },
38 {
39 in: []string{"a", "b", "a"},
40 out: []string{"a", "b"},
41 },
42 {
43 in: []string{"b", "a", "a"},
44 out: []string{"b", "a"},
45 },
46 {
47 in: []string{"a", "a", "b"},
48 out: []string{"a", "b"},
49 },
50 {
51 in: []string{"a", "b", "a", "b"},
52 out: []string{"a", "b"},
53 },
54 {
55 in: []string{"liblog", "libdl", "libc++", "libdl", "libc", "libm"},
56 out: []string{"liblog", "libdl", "libc++", "libc", "libm"},
57 },
58}
59
60func TestFirstUniqueStrings(t *testing.T) {
61 for _, testCase := range firstUniqueStringsTestCases {
62 out := FirstUniqueStrings(testCase.in)
63 if !reflect.DeepEqual(out, testCase.out) {
64 t.Errorf("incorrect output:")
65 t.Errorf(" input: %#v", testCase.in)
66 t.Errorf(" expected: %#v", testCase.out)
67 t.Errorf(" got: %#v", out)
68 }
69 }
70}
71
72var lastUniqueStringsTestCases = []struct {
73 in []string
74 out []string
75}{
76 {
77 in: []string{"a"},
78 out: []string{"a"},
79 },
80 {
81 in: []string{"a", "b"},
82 out: []string{"a", "b"},
83 },
84 {
85 in: []string{"a", "a"},
86 out: []string{"a"},
87 },
88 {
89 in: []string{"a", "b", "a"},
90 out: []string{"b", "a"},
91 },
92 {
93 in: []string{"b", "a", "a"},
94 out: []string{"b", "a"},
95 },
96 {
97 in: []string{"a", "a", "b"},
98 out: []string{"a", "b"},
99 },
100 {
101 in: []string{"a", "b", "a", "b"},
102 out: []string{"a", "b"},
103 },
104 {
105 in: []string{"liblog", "libdl", "libc++", "libdl", "libc", "libm"},
106 out: []string{"liblog", "libc++", "libdl", "libc", "libm"},
107 },
108}
109
110func TestLastUniqueStrings(t *testing.T) {
111 for _, testCase := range lastUniqueStringsTestCases {
112 out := LastUniqueStrings(testCase.in)
113 if !reflect.DeepEqual(out, testCase.out) {
114 t.Errorf("incorrect output:")
115 t.Errorf(" input: %#v", testCase.in)
116 t.Errorf(" expected: %#v", testCase.out)
117 t.Errorf(" got: %#v", out)
118 }
119 }
120}