-
Notifications
You must be signed in to change notification settings - Fork 2
/
main_test.go
74 lines (70 loc) · 968 Bytes
/
main_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
67
68
69
70
71
72
73
74
package main
import (
"testing"
"github.com/kylelemons/godebug/pretty"
)
func TestSplit(t *testing.T) {
cases := []struct {
name string
s string
n int
want []string
}{
{
"negative_parts",
"foo",
-1,
[]string{},
},
{
"empty_0",
"",
0,
[]string{},
},
{
"nonempty_0",
"foo",
0,
[]string{},
},
{
"one_part",
"foo",
1,
[]string{"foo"},
},
{
"len_equal_to_parts",
"foo",
3,
[]string{"f", "o", "o"},
},
{
"len_greater_than_parts",
"foo",
5,
[]string{"f", "o", "o"},
},
{
"equal_parts",
"foobarbaz",
3,
[]string{"foo", "bar", "baz"},
},
{
"remainder",
"foobarbazz",
3,
[]string{"foob", "arba", "zz"},
},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
got := split(c.s, c.n)
if diff := pretty.Compare(got, c.want); diff != "" {
t.Errorf("Unexpected result (-got +want):\n%s", diff)
}
})
}
}