121 lines
2.6 KiB
Go
121 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)
|
|
}
|
|
}
|
|
}
|