platform_build_soong/android/util_test.go
Colin Cross b671544973 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
2017-10-24 12:12:32 -07:00

120 lines
2.6 KiB
Go

// 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)
}
}
}