-
-
Notifications
You must be signed in to change notification settings - Fork 137
Expand file tree
/
Copy pathFibonacci_test.go
More file actions
59 lines (48 loc) · 1.08 KB
/
Copy pathFibonacci_test.go
File metadata and controls
59 lines (48 loc) · 1.08 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
59
package Fibonacci
import (
"reflect"
"testing"
)
func TestRecusiveFibonacci(t *testing.T) {
t.Run("Fibonacci of 0", func(t *testing.T) {
got := FibonacciRecursive(0)
want := 0
if got != want {
t.Errorf("got %q want %q", got, want)
}
})
t.Run("Fibonacci of 5", func(t *testing.T) {
got := FibonacciRecursive(5)
want := 5
if got != want {
t.Errorf("got %q want %q", got, want)
}
})
t.Run("Factorial of 8", func(t *testing.T) {
got := FibonacciRecursive(8)
want := 21
if got != want {
t.Errorf("got %q want %q", got, want)
}
})
t.Run("Factorial of 10", func(t *testing.T) {
got := FibonacciRecursive(10)
want := 55
if got != want {
t.Errorf("got %q want %q", got, want)
}
})
}
func TestFibonacciSequence(t *testing.T) {
data := []struct {
n int
want []int
}{
{0, []int{0}}, {1, []int{0, 1}}, {2, []int{0, 1, 1}}, {3, []int{0, 1, 1, 2}},
}
for _, d := range data {
if got := fibonacciSequence(d.n); !reflect.DeepEqual(got, d.want) {
t.Errorf("Invalid Fibonacci value for N: %d, got: %d, want: %d", d.n, got, d.want)
}
}
}