-
-
Notifications
You must be signed in to change notification settings - Fork 130
/
Copy pathpascal_test.go
80 lines (64 loc) · 1.18 KB
/
pascal_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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package PascalTriangle
import (
"testing"
)
func TestIsPascalTriangle(t *testing.T) {
t.Run("PascalTraingle of 1", func(t *testing.T) {
got := pascalTriangle(1)
want := [][]int{
{1},
}
if len(got) != len(want) {
t.Errorf("Different array size then expected")
}
for i := 0; i < len(got); i++ {
if !Equal(got[i], want[i]) {
t.Errorf("Error")
}
}
})
t.Run("PascalTraingle of 2", func(t *testing.T) {
got := pascalTriangle(2)
want := [][]int{
{1},
{1, 1},
}
if len(got) != len(want) {
t.Errorf("Different array size then expected")
}
for i := 0; i < len(got); i++ {
if !Equal(got[i], want[i]) {
t.Errorf("Error")
}
}
})
t.Run("PascalTraingle of 5", func(t *testing.T) {
got := pascalTriangle(5)
want := [][]int{
{1},
{1, 1},
{1, 2, 1},
{1, 3, 3, 1},
{1, 4, 6, 4, 1},
}
if len(got) != len(want) {
t.Errorf("Different array size then expected")
}
for i := 0; i < len(got); i++ {
if !Equal(got[i], want[i]) {
t.Errorf("Error")
}
}
})
}
func Equal(a, b []int) bool {
if len(a) != len(b) {
return false
}
for i, v := range a {
if v != b[i] {
return false
}
}
return true
}