-
Notifications
You must be signed in to change notification settings - Fork 0
/
fib_test.go
57 lines (48 loc) · 1.08 KB
/
fib_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
package main
import "testing"
func BenchmarkFibonacci_10(b *testing.B) {
for i := 0; i < b.N; i++ {
Fibonacci(10)
}
}
func BenchmarkFibonacci_20(b *testing.B) {
for i := 0; i < b.N; i++ {
Fibonacci(20)
}
}
func BenchmarkFibonacciBig_10(b *testing.B) {
for i := 0; i < b.N; i++ {
FibonacciBig(10)
}
}
func BenchmarkFibonacciBig_20(b *testing.B) {
for i := 0; i < b.N; i++ {
FibonacciBig(20)
}
}
func TestFibonacci(t *testing.T) {
data := []struct {
n uint
want uint64
}{
{0, 0}, {1, 1}, {2, 1}, {3, 2}, {4, 3}, {5, 5}, {6, 8}, {10, 55}, {42, 267914296},
}
for _, d := range data {
if got := Fibonacci(d.n); got != d.want {
t.Errorf("Invalid Fibonacci value for N: %d, got: %d, want: %d", d.n, got, d.want)
}
}
}
func TestFibonacciBig(t *testing.T) {
data := []struct {
n uint
want int64
}{
{0, 0}, {1, 1}, {2, 1}, {3, 2}, {4, 3}, {5, 5}, {6, 8}, {10, 55}, {42, 267914296},
}
for _, d := range data {
if got := FibonacciBig(d.n); got.Int64() != d.want {
t.Errorf("Invalid Fibonacci value for N: %d, got: %d, want: %d", d.n, got, d.want)
}
}
}