MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / TestGenerateTriangle

Function TestGenerateTriangle

math/pascal/pascaltriangle_test.go:13–31  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func TestGenerateTriangle(t *testing.T) {
14 tests := []struct {
15 name string
16 n int
17 want [][]int
18 }{
19 {name: "Pascal's three-line triangle", n: 3, want: [][]int{{1}, {1, 1}, {1, 2, 1}}},
20 {name: "Pascal's 0-line triangle", n: 0, want: [][]int{}},
21 {name: "Pascal's one-line triangle", n: 1, want: [][]int{{1}}},
22 {name: "Pascal's 7-line triangle", n: 7, want: [][]int{{1}, {1, 1}, {1, 2, 1}, {1, 3, 3, 1}, {1, 4, 6, 4, 1}, {1, 5, 10, 10, 5, 1}, {1, 6, 15, 20, 15, 6, 1}}},
23 }
24 for _, test := range tests {
25 t.Run(test.name, func(t *testing.T) {
26 if got := GenerateTriangle(test.n); !reflect.DeepEqual(got, test.want) {
27 t.Errorf("GenerateTriangle() = %v, want %v", got, test.want)
28 }
29 })
30 }
31}
32
33func BenchmarkGenerateTriangle(b *testing.B) {
34 for i := 0; i < b.N; i++ {

Callers

nothing calls this directly

Calls 1

GenerateTriangleFunction · 0.85

Tested by

no test coverage detected