-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreverse_words_3_test.go
56 lines (46 loc) · 1.42 KB
/
reverse_words_3_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 problem0557
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
type Result struct {
Input string
Expected string
}
var Results = []Result{
{"Let's take LeetCode contest", "s'teL ekat edoCteeL tsetnoc"},
{"God Ding", "doG gniD"},
{`According to all known lawsof aviation,there is no way a beeshould be able to fly.Its wings are too small to getits fat little body off the ground.The bee, of course, flies anywaybecause bees don't carewhat humans think is impossible.`,
`gnidroccA ot lla nwonk foswal ereht,noitaiva si on yaw a dluohseeb eb elba ot stI.ylf sgniw era oot llams ot stiteg taf elttil ydob ffo eht ehT.dnuorg ,eeb fo ,esruoc seilf esuacebyawyna seeb t'nod tahwerac snamuh kniht si .elbissopmi`},
}
func TestReverseWords(t *testing.T) {
assert := assert.New(t)
for _, res := range Results {
want := res.Expected
got := reverseWords(res.Input)
assert.Equal(want, got, fmt.Sprintf("%+v", res))
}
}
func BenchmarkReverseWords(b *testing.B) {
for i := 0; i < b.N; i++ {
for _, res := range Results {
reverseWords(res.Input)
}
}
}
func TestReverseWordsOpt(t *testing.T) {
assert := assert.New(t)
for _, res := range Results {
want := res.Expected
got := reverseWordsOpt(res.Input)
assert.Equal(want, got, fmt.Sprintf("%+v", res))
}
}
func BenchmarkReverseWordsOpt(b *testing.B) {
for i := 0; i < b.N; i++ {
for _, res := range Results {
reverseWordsOpt(res.Input)
}
}
}