10
10
11
11
public class PracticeTest {
12
12
13
- /** Test method for {@link _074_SearchA2DMatrix.Solution } */
14
- Solution solution ;
13
+ /** Test method for {@link _074_SearchA2DMatrix.Practice } */
14
+ Practice solution ;
15
15
16
16
@ Rule
17
17
public Timeout globalTimeout = new Timeout (200 );
18
18
19
19
@ Before
20
20
public void setUp () throws Exception {
21
- solution = new Solution ();
21
+ solution = new Practice ();
22
22
}
23
23
24
24
@ After
@@ -28,8 +28,11 @@ public void tearDown() throws Exception {
28
28
29
29
@ Test
30
30
public void Test1 () {
31
- int [][] matrix = { { 1 , 3 , 5 , 7 }, { 10 , 11 , 16 , 20 },
32
- { 23 , 30 , 34 , 50 } };
31
+ int [][] matrix = {
32
+ { 1 , 3 , 5 , 7 },
33
+ { 10 , 11 , 16 , 20 },
34
+ { 23 , 30 , 34 , 50 }
35
+ };
33
36
int target = 3 ;
34
37
boolean actual = solution .searchMatrix (matrix , target );
35
38
boolean expected = true ;
@@ -38,8 +41,11 @@ public void Test1() {
38
41
39
42
@ Test
40
43
public void Test2 () {
41
- int [][] matrix = { { 1 , 3 , 5 , 7 }, { 10 , 11 , 16 , 20 },
42
- { 23 , 30 , 34 , 50 } };
44
+ int [][] matrix = {
45
+ { 1 , 3 , 5 , 7 },
46
+ { 10 , 11 , 16 , 20 },
47
+ { 23 , 30 , 34 , 50 }
48
+ };
43
49
int target = 100 ;
44
50
boolean actual = solution .searchMatrix (matrix , target );
45
51
boolean expected = false ;
@@ -48,8 +54,11 @@ public void Test2() {
48
54
49
55
@ Test
50
56
public void Test3 () {
51
- int [][] matrix = { { 1 , 3 , 5 , 7 }, { 10 , 11 , 16 , 20 },
52
- { 23 , 30 , 34 , 50 } };
57
+ int [][] matrix = {
58
+ { 1 , 3 , 5 , 7 },
59
+ { 10 , 11 , 16 , 20 },
60
+ { 23 , 30 , 34 , 50 }
61
+ };
53
62
int target = 15 ;
54
63
boolean actual = solution .searchMatrix (matrix , target );
55
64
boolean expected = false ;
@@ -58,8 +67,11 @@ public void Test3() {
58
67
59
68
@ Test
60
69
public void Test4 () {
61
- int [][] matrix = { { 1 , 3 , 5 , 7 }, { 10 , 11 , 16 , 20 },
62
- { 23 , 30 , 34 , 50 } };
70
+ int [][] matrix = {
71
+ { 1 , 3 , 5 , 7 },
72
+ { 10 , 11 , 16 , 20 },
73
+ { 23 , 30 , 34 , 50 }
74
+ };
63
75
int target = 30 ;
64
76
boolean actual = solution .searchMatrix (matrix , target );
65
77
boolean expected = true ;
@@ -68,8 +80,11 @@ public void Test4() {
68
80
69
81
@ Test
70
82
public void Test5 () {
71
- int [][] matrix = { { 1 , 3 , 5 , 7 }, { 10 , 11 , 16 , 20 },
72
- { 23 , 30 , 34 , 50 } };
83
+ int [][] matrix = {
84
+ { 1 , 3 , 5 , 7 },
85
+ { 10 , 11 , 16 , 20 },
86
+ { 23 , 30 , 34 , 50 }
87
+ };
73
88
int target = 0 ;
74
89
boolean actual = solution .searchMatrix (matrix , target );
75
90
boolean expected = false ;
@@ -78,12 +93,127 @@ public void Test5() {
78
93
79
94
@ Test
80
95
public void Test6 () {
81
- int [][] matrix = { { 1 , 3 , 5 , 7 }, { 10 , 11 , 16 , 20 },
82
- { 23 , 30 , 34 , 50 } };
96
+ int [][] matrix = {
97
+ { 1 , 3 , 5 , 7 },
98
+ { 10 , 11 , 16 , 20 },
99
+ { 23 , 30 , 34 , 50 }
100
+ };
83
101
int target = 10 ;
84
102
boolean actual = solution .searchMatrix (matrix , target );
85
103
boolean expected = true ;
86
104
assertEquals (expected , actual );
87
105
}
88
106
107
+ @ Test
108
+ public void Test7 () {
109
+ int [][] matrix = { { 1 , 3 , 5 , 7 } };
110
+ int target = 10 ;
111
+ assertFalse (solution .searchMatrix (matrix , target ));
112
+ }
113
+
114
+ @ Test
115
+ public void Test8 () {
116
+ int [][] matrix = { { 1 , 3 , 5 , 7 } };
117
+ int target = 7 ;
118
+ assertTrue (solution .searchMatrix (matrix , target ));
119
+ }
120
+
121
+ @ Test
122
+ public void Test9 () {
123
+ int [][] matrix = { { 1 , 3 , 5 , 7 } };
124
+ int target = 1 ;
125
+ assertTrue (solution .searchMatrix (matrix , target ));
126
+ }
127
+
128
+ @ Test
129
+ public void Test10 () {
130
+ int [][] matrix = { { 1 , 3 , 5 , 7 } };
131
+ int target = 4 ;
132
+ assertFalse (solution .searchMatrix (matrix , target ));
133
+ }
134
+
135
+ @ Test
136
+ public void Test11 () {
137
+ int [][] matrix = { { 1 , 3 , 5 , 7 } };
138
+ int target = 5 ;
139
+ assertTrue (solution .searchMatrix (matrix , target ));
140
+ }
141
+
142
+ @ Test
143
+ public void Test12 () {
144
+ int [][] matrix = {
145
+ { 1 },
146
+ { 5 },
147
+ { 9 },
148
+ };
149
+ int target = 9 ;
150
+ assertTrue (solution .searchMatrix (matrix , target ));
151
+ }
152
+
153
+ @ Test
154
+ public void Test13 () {
155
+ int [][] matrix = {
156
+ { 1 },
157
+ { 5 },
158
+ { 9 },
159
+ };
160
+ int target = 1 ;
161
+ assertTrue (solution .searchMatrix (matrix , target ));
162
+ }
163
+
164
+ @ Test
165
+ public void Test14 () {
166
+ int [][] matrix = {
167
+ { 1 },
168
+ { 5 },
169
+ { 9 },
170
+ };
171
+ int target = 5 ;
172
+ assertTrue (solution .searchMatrix (matrix , target ));
173
+ }
174
+
175
+ @ Test
176
+ public void Test15 () {
177
+ int [][] matrix = {
178
+ { 1 },
179
+ { 5 },
180
+ { 9 },
181
+ };
182
+ int target = 18 ;
183
+ assertFalse (solution .searchMatrix (matrix , target ));
184
+ }
185
+
186
+ @ Test
187
+ public void Test16 () {
188
+ int [][] matrix = {
189
+ { 1 },
190
+ { 5 },
191
+ { 9 },
192
+ };
193
+ int target = 0 ;
194
+ assertFalse (solution .searchMatrix (matrix , target ));
195
+ }
196
+
197
+ @ Test
198
+ public void Test17 () {
199
+ int [][] matrix = {
200
+ { 1 },
201
+ { 5 },
202
+ { 9 },
203
+ };
204
+ int target = 3 ;
205
+ assertFalse (solution .searchMatrix (matrix , target ));
206
+ }
207
+
208
+ @ Test
209
+ public void Test18 () {
210
+ int [][] matrix = {
211
+ { 1 },
212
+ { 5 },
213
+ { 9 },
214
+ };
215
+ int target = 7 ;
216
+ assertFalse (solution .searchMatrix (matrix , target ));
217
+ }
218
+
89
219
}
0 commit comments