-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
60 lines (50 loc) · 1.09 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
57
58
59
60
package main
import (
"fmt"
"testing"
)
var tests = []struct {
number int
expected bool
}{
{121, true},
{-121, false},
{10, false},
{11, true},
{101, true},
{1001, true},
{110, false},
{1011, false},
}
func TestIsPalindrome(t *testing.T) {
for _, test := range tests {
testname := fmt.Sprintf("running test with input(%d)", test.number)
t.Run(testname, func(t *testing.T) {
out := isPalindrome(test.number)
if out != test.expected {
t.Errorf("isPalindrome(%d) expected %t, but got %t", test.number, test.expected, out)
}
})
}
}
func TestIsPalindrome2(t *testing.T) {
for _, test := range tests {
testname := fmt.Sprintf("running test with input(%d)", test.number)
t.Run(testname, func(t *testing.T) {
out := isPalindrome2(test.number)
if out != test.expected {
t.Errorf("isPalindrome(%d) expected %t, but got %t", test.number, test.expected, out)
}
})
}
}
func BenchmarkIsPalindrome(b *testing.B) {
for i := 0; i < b.N; i++ {
isPalindrome(101)
}
}
func BenchmarkIsPalindrome2(b *testing.B) {
for i := 0; i < b.N; i++ {
isPalindrome2(101)
}
}