-
Notifications
You must be signed in to change notification settings - Fork 3
/
problem20_test.go
45 lines (39 loc) · 821 Bytes
/
problem20_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
// Copyright 2015 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 (
"math/big"
"testing"
)
func TestProblem20(t *testing.T) {
const want = 648
got := Problem20()
if got != want {
t.Errorf("Problem20() = %d; want %d", got, want)
}
}
var bigIntFactorialTests = []struct {
in int64
want int64
}{
{0, 1},
{1, 1},
{2, 2},
{3, 6},
{4, 24},
{5, 120},
}
func TestBigIntFactorial(t *testing.T) {
for _, tt := range bigIntFactorialTests {
got := bigIntFactorial(big.NewInt(tt.in))
if got.Cmp(big.NewInt(tt.want)) != 0 {
t.Errorf("bigIntFactorial(%d) = %v; want %d", tt.in, got, tt.want)
}
}
}
func BenchmarkProblem20(b *testing.B) {
for i := 0; i < b.N; i++ {
Problem20()
}
}