|
|
|
|
@ -461,3 +461,42 @@ func find(item string, items []string) bool {
|
|
|
|
|
} |
|
|
|
|
return false |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestMergeSlice(t *testing.T) { |
|
|
|
|
tests := map[string]struct { |
|
|
|
|
s1 []string |
|
|
|
|
s2 []string |
|
|
|
|
want []string |
|
|
|
|
}{ |
|
|
|
|
"merge slice": { |
|
|
|
|
s1: []string{"t1", "t2"}, |
|
|
|
|
s2: []string{"t3"}, |
|
|
|
|
want: []string{"t1", "t2", "t3"}, |
|
|
|
|
}, |
|
|
|
|
"merge slice with duplicates": { |
|
|
|
|
s1: []string{"t1", "t2"}, |
|
|
|
|
s2: []string{"t3", "t2"}, |
|
|
|
|
want: []string{"t1", "t2", "t3"}, |
|
|
|
|
}, |
|
|
|
|
"merge slice with empty slice": { |
|
|
|
|
s1: []string{"t1", "t2"}, |
|
|
|
|
s2: []string{}, |
|
|
|
|
want: []string{"t1", "t2"}, |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for name, tc := range tests { |
|
|
|
|
t.Run(name, func(t *testing.T) { |
|
|
|
|
got := mergeSlice(tc.s1, tc.s2) |
|
|
|
|
if len(got) != len(tc.want) { |
|
|
|
|
t.Errorf("expected equal slice") |
|
|
|
|
} |
|
|
|
|
for _, want := range tc.want { |
|
|
|
|
found := find(want, got) |
|
|
|
|
if !found { |
|
|
|
|
t.Errorf("missing element: %s", want) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|