-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathcomponents_test.go
More file actions
60 lines (57 loc) · 850 Bytes
/
components_test.go
File metadata and controls
60 lines (57 loc) · 850 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
53
54
55
56
57
58
59
60
package permutation
import (
"log"
"testing"
)
func TestFactorial0(t *testing.T) {
reference := [][]int{
{0, 0},
{1, 1},
{2, 2},
{3, 6},
{4, 24},
}
for _, v := range reference {
if factorial(v[0]) != v[1] {
log.Fatal("Factorial problem", v[0], v[1])
}
}
}
func TestFactorial1(t *testing.T) {
var tests = []struct {
Name string
In, Result int
}{
{
Name: "0",
In: 0,
Result: 0,
},
{
Name: "1",
In: 1,
Result: 1,
},
{
Name: "2",
In: 2,
Result: 2,
},
{
Name: "3",
In: 3,
Result: 6,
},
{
Name: "4",
In: 4,
Result: 24,
},
}
for _, test := range tests {
if result := factorial(test.In); result != test.Result {
t.Errorf("%s: result %d doesn't match expected result %d\n",
test.Name, result, test.Result)
}
}
}