forked from sw0x2A/project-euler-golang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0004_test.go
50 lines (43 loc) · 954 Bytes
/
0004_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
package main
import "testing"
func TestReverse(t *testing.T) {
pairs := [...][2]int{{111, 111}, {7337, 7337}, {906609, 906609}}
for _, pair := range pairs {
in, out := pair[0], int(pair[1])
if x := reverse(in); x != out {
t.Errorf("reverse(%d) = %d, should be %d", in, x, out)
}
}
}
func BenchmarkReverse(b *testing.B) {
in := 906609
for i := 0; i < b.N; i++ {
reverse(in)
}
}
func TestIsPalindrome(t *testing.T) {
pairs := map[int]bool{1234: false, 906609: true}
for k, _ := range pairs {
in, out := k, pairs[k]
if x := isPalindrome(in); x != out {
t.Errorf("isPalindrome(%d) = %t, should be %t", in, x, out)
}
}
}
func BenchmarkIsPalindrome(b *testing.B) {
in := 906609
for i := 0; i < b.N; i++ {
isPalindrome(in)
}
}
func TestP4(t *testing.T) {
out := 906609
if x := p4(); x != out {
t.Errorf("p4() = %d, should be %d", x, out)
}
}
func BenchmarkP4(b *testing.B) {
for i := 0; i < b.N; i++ {
p4()
}
}