Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1e7a148

Browse files
author
Sandy
authored
Merge pull request #185 from openset/develop
Add: Toeplitz Matrix
2 parents c78ebc0 + 5632616 commit 1e7a148

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,12 @@
11
package toeplitz_matrix
2+
3+
func isToeplitzMatrix(matrix [][]int) bool {
4+
for i, row := range matrix[1:] {
5+
for j, v := range row[1:] {
6+
if v != matrix[i][j] {
7+
return false
8+
}
9+
}
10+
}
11+
return true
12+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,34 @@
11
package toeplitz_matrix
2+
3+
import "testing"
4+
5+
type caseType struct {
6+
input [][]int
7+
expected bool
8+
}
9+
10+
func TestIsToeplitzMatrix(t *testing.T) {
11+
tests := [...]caseType{
12+
{
13+
input: [][]int{
14+
{1, 2, 3, 4},
15+
{5, 1, 2, 3},
16+
{9, 5, 1, 2},
17+
},
18+
expected: true,
19+
},
20+
{
21+
input: [][]int{
22+
{1, 2},
23+
{2, 2},
24+
},
25+
expected: false,
26+
},
27+
}
28+
for _, tc := range tests {
29+
output := isToeplitzMatrix(tc.input)
30+
if output != tc.expected {
31+
t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected)
32+
}
33+
}
34+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /