-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstrings_test.go
66 lines (59 loc) · 1.33 KB
/
strings_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//go:build unit || ci
package common
import (
"fmt"
"github.com/stretchr/testify/assert"
"testing"
)
type testStringSet struct {
input []string
expected []string
}
type testMultiInputSet struct {
input1 []string
input2 []string
expected []string
}
func TestIntersection(t *testing.T) {
testData := []testMultiInputSet{
{
input1: []string{"foo", "bar", "north"},
input2: []string{"foo", "say"},
expected: []string{"foo"},
},
{
input1: []string{"foo", "bar", "north"},
input2: []string{"what", "say"},
expected: []string{},
},
{
input1: []string{"foo", "bar", "north", "what"},
input2: []string{"bar", "what", "say"},
expected: []string{"bar", "what"},
},
}
for _, td := range testData {
result := Intersection(td.input1, td.input2)
assert.Equal(t, fmt.Sprintf("%s", td.expected), fmt.Sprintf("%s", result))
}
}
func TestRemoveDuplicates(t *testing.T) {
testData := []testStringSet{
{
input: []string{"foo", "foo"},
expected: []string{"foo"},
},
{
input: []string{"foo", "bar"},
expected: []string{"foo", "bar"},
},
{
input: []string{"foo", "bar", "bar"},
expected: []string{"foo", "bar"},
},
}
for _, td := range testData {
result := RemoveDuplicates(td.input)
assert.Equal(t, fmt.Sprintf("%s", td.expected), fmt.Sprintf("%s", result))
}
}