forked from andeya/goutil
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sets_test.go
62 lines (56 loc) · 1.18 KB
/
sets_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
package goutil
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestSetToStrings(t *testing.T) {
a := make([]string, 0, 10)
a = append(a, "1", "2", "3")
b := SetToStrings(a, "4", "2", "5")
assert.Equal(t, []string{"1", "2", "3", "4", "5"}, b)
assert.Equal(t, []string{"1", "2", "3"}, a)
}
func TestIntersectStrings(t *testing.T) {
cases := []struct {
set1, set2, intersect []string
}{
{
[]string{"a", "b", "c", "d"},
[]string{"b", "d"},
[]string{"b", "d"},
},
{
[]string{"a", "b", "c", "d", "e", "d"},
[]string{"b", "d", "d", "d"},
[]string{"b", "d"},
},
{
[]string{"a"},
nil,
[]string{},
},
{
[]string{"a"},
[]string{"b"},
[]string{},
},
}
for _, c := range cases {
assert.Equal(t, c.intersect, IntersectStrings(c.set1, c.set2))
}
}
func TestStringsToXXX(t *testing.T) {
var cases = []struct {
strs []string
expected []int
}{
{[]string{"1", "", "3"}, []int{1, 0, 3}},
}
for _, c := range cases {
r, err := StringsToInts(c.strs)
assert.EqualError(t, err, "strconv.Atoi: parsing \"\": invalid syntax")
r, err = StringsToInts(c.strs, true)
assert.Nil(t, err)
assert.Equal(t, c.expected, r)
}
}