-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathproblem4_test.go
More file actions
58 lines (50 loc) · 1.02 KB
/
problem4_test.go
File metadata and controls
58 lines (50 loc) · 1.02 KB
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
// Copyright 2014 Peter Mrekaj. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE.txt file.
package euler
import "testing"
func TestProblem4(t *testing.T) {
const want = 906609
got := Problem4()
if got != want {
t.Errorf("Problem4() = %d; want %d", got, want)
}
}
var reverseTests = []struct {
in int
want int
}{
{1111, 1111},
{1010, 101},
{1234, 4321},
}
func TestReverse(t *testing.T) {
for _, tt := range reverseTests {
got := reverse(tt.in)
if got != tt.want {
t.Errorf("reverse(%d) = %d; want %d", tt.in, got, tt.want)
}
}
}
var isPalindromeTests = []struct {
in int
want bool
}{
{101, true},
{1010, false},
{12321, true},
{123456, false},
}
func TestIsPalindrome(t *testing.T) {
for _, tt := range isPalindromeTests {
got := isPalindrome(tt.in)
if got != tt.want {
t.Errorf("isPalindrome(%d) = %t; want %t", tt.in, got, tt.want)
}
}
}
func BenchmarkProblem4(b *testing.B) {
for i := 0; i < b.N; i++ {
Problem4()
}
}