forked from codeship/go-best-practices
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfib_test.go
More file actions
38 lines (32 loc) · 702 Bytes
/
fib_test.go
File metadata and controls
38 lines (32 loc) · 702 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
package fib
import (
"fmt"
"testing"
)
type testCase struct {
in int // input
expected int // expected result
}
func newCase(in, expected int) testCase { return testCase{in, expected} }
func (c testCase) Name() string {
return fmt.Sprintf("Fib(%d) should equal %d", c.in, c.expected)
}
func (c testCase) Run(t *testing.T) {
actual := Fib(c.in)
if actual != c.expected {
t.Errorf("Fib(%d): expected %d, actual %d", c.in, c.expected, actual)
}
}
func TestFib(t *testing.T) {
for _, testCase := range []testCase{
newCase(1, 1),
newCase(2, 1),
newCase(3, 2),
newCase(4, 3),
newCase(5, 5),
newCase(6, 8),
newCase(7, 13),
} {
t.Run(testCase.Name(), testCase.Run)
}
}