-
Notifications
You must be signed in to change notification settings - Fork 0
/
solution_test.go
55 lines (49 loc) · 1.08 KB
/
solution_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
package valid_palindrome
import (
"fmt"
"testing"
)
var testCases = []struct {
input string
want bool
}{
{input: "A man, a plan, a canal: Panama", want: true},
{input: "race a car", want: false},
{input: "0P", want: false},
{input: ".a", want: true},
{input: " ", want: true},
}
func Benchmark_isPalindrome(b *testing.B) {
for i, tc := range testCases {
b.Run(fmt.Sprintf("Case_%d", i), func(b *testing.B) {
for i := 0; i < b.N; i++ {
isPalindrome(tc.input)
}
})
}
}
func Benchmark_isPalindromeV2(b *testing.B) {
for i, tc := range testCases {
b.Run(fmt.Sprintf("Case_%d", i), func(b *testing.B) {
for i := 0; i < b.N; i++ {
isPalindromeV2(tc.input)
}
})
}
}
func Test_isPalindrome(t *testing.T) {
for i, tc := range testCases {
got := isPalindrome(tc.input)
if tc.want != got {
t.Fatalf("Case #%d: expected: %v, got: %v", i+1, tc.want, got)
}
}
}
func Test_isPalindromeV2(t *testing.T) {
for i, tc := range testCases {
got := isPalindromeV2(tc.input)
if tc.want != got {
t.Fatalf("Case #%d: expected: %v, got: %v", i+1, tc.want, got)
}
}
}