-
Notifications
You must be signed in to change notification settings - Fork 0
/
240. 搜索二维矩阵 II_test.go
71 lines (68 loc) · 1.08 KB
/
240. 搜索二维矩阵 II_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
package main
import "testing"
func Test_match(t *testing.T) {
type args struct {
matrix [][]int
target int
x int
y int
}
matrix := [][]int{
{1, 4, 7, 11, 15, 16},
{2, 5, 8, 12, 19, 20},
{3, 6, 9, 16, 22, 25},
{10, 13, 14, 17, 24, 27},
{18, 21, 23, 26, 30, 35},
}
tests := []struct {
name string
args args
want bool
}{
{
name: "t1",
args: args{
matrix: matrix,
target: 16,
},
want: true,
},
{
name: "t2",
args: args{
matrix: matrix,
target: 100,
},
want: false,
},
{
name: "t3",
args: args{
matrix: matrix,
target: 35,
},
want: true,
},
{
name: "t4",
args: args{
matrix: [][]int{
{1, 3, 5, 7, 9},
{2, 4, 6, 8, 10},
{11, 13, 15, 17, 19},
{12, 14, 16, 18, 20},
{21, 22, 23, 24, 25},
},
target: 13,
},
want: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := match(tt.args.matrix, tt.args.target, tt.args.x, tt.args.y); got != tt.want {
t.Errorf("match() = %v, want %v", got, tt.want)
}
})
}
}