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