-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
56 lines (50 loc) · 1.02 KB
/
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
package main
import (
"slices"
"testing"
)
func TestClean(t *testing.T) {
cases := []struct {
name string
input string
expected []string
}{
{
name: "remove leading trailing and in-between whitespace",
input: " hello world ",
expected: []string{"hello", "world"},
},
{
name: "lowercase all words",
input: " Charmander Bulbasaur PIKACHU ",
expected: []string{"charmander", "bulbasaur", "pikachu"},
},
{
name: "empty input returns nil",
input: "",
expected: nil,
},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
actual := clean(c.input)
if !slices.Equal(c.expected, actual) {
t.Errorf("\ninput: %q\nexpected: %+v\nactual: %+v",
c.input, c.expected, actual)
}
},
)
}
}
func BenchmarkClean(b *testing.B) {
b.Run("empty input", func(b *testing.B) {
for range b.N {
clean("")
}
})
b.Run("whitespace and lowercase", func(b *testing.B) {
for range b.N {
clean(" Charmander Bulbasaur PIKACHU ")
}
})
}