-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfibonacci_test.go
More file actions
52 lines (46 loc) · 927 Bytes
/
fibonacci_test.go
File metadata and controls
52 lines (46 loc) · 927 Bytes
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
package algorithms
import "testing"
var (
tests = []struct {
name string
n int
want int
}{
{"zero", 0, 0},
{"one", 1, 1},
{"two", 2, 1},
{"nine", 9, 34},
{"twelve", 12, 144},
{"forteen", 14, 377},
}
)
func TestMemoization(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := memoization(tt.n); got != tt.want {
t.Errorf("memoization() = %v, want %v", got, tt.want)
}
})
}
}
func BenchmarkMemoization(b *testing.B) {
// run the Fib function b.N times
for n := 0; n < b.N; n++ {
memoization(10)
}
}
func TestRecursion(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := recursion(tt.n); got != tt.want {
t.Errorf("recursion() = %v, want %v", got, tt.want)
}
})
}
}
func BenchmarkRecursion(b *testing.B) {
// run the Fib function b.N times
for n := 0; n < b.N; n++ {
recursion(10)
}
}