diff options
author | 2017-10-24 11:13:31 -0700 | |
---|---|---|
committer | 2017-10-24 12:12:32 -0700 | |
commit | b6715449737261c64d3408418754185da8624204 (patch) | |
tree | 737974202fe72cabcc566e7c6b8c1ca3637b028e /android/util_test.go | |
parent | ae88703df55dcd721ccd5c3cca4c02c7b541ca9d (diff) |
Move first/last unique elements utility functions to android package
Move firstUniqueElements to android.FirstUniqueStrings,
lastUniqueElements to android.LastUniqueStrings, and lastUniquePaths
to android.LastUniquePaths.
Test: m checkbuild
Change-Id: Ieac840405126c7f8f98afb4a4ef35c01a18fe7fb
Diffstat (limited to 'android/util_test.go')
-rw-r--r-- | android/util_test.go | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/android/util_test.go b/android/util_test.go new file mode 100644 index 000000000..32f92b46c --- /dev/null +++ b/android/util_test.go @@ -0,0 +1,120 @@ +// Copyright 2017 Google Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package android + +import ( + "reflect" + "testing" +) + +var firstUniqueStringsTestCases = []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 TestFirstUniqueStrings(t *testing.T) { + for _, testCase := range firstUniqueStringsTestCases { + out := FirstUniqueStrings(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 lastUniqueStringsTestCases = []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 TestLastUniqueStrings(t *testing.T) { + for _, testCase := range lastUniqueStringsTestCases { + out := LastUniqueStrings(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) + } + } +} |