-
Notifications
You must be signed in to change notification settings - Fork 21k
Expand file tree
/
Copy pathSearchMatrixTest.java
More file actions
55 lines (44 loc) · 1.3 KB
/
SearchMatrixTest.java
File metadata and controls
55 lines (44 loc) · 1.3 KB
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
package com.thealgorithms.matrix;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
class SearchMatrixTest {
@Test
void nullMatrixReturnsFalse() {
assertFalse(SearchMatrix.contains(null, 1));
}
@Test
void emptyMatrixReturnsFalse() {
assertFalse(SearchMatrix.contains(new Integer[0][], 1));
}
@Test
void findsElementInRectangularMatrix() {
final Integer[][] matrix = {
{1, 2, 3},
{4, 5, 6},
};
assertTrue(SearchMatrix.contains(matrix, 5));
assertFalse(SearchMatrix.contains(matrix, 7));
}
@Test
void supportsNullTargetAndNullElements() {
final String[][] matrix = {
{"a", null},
{"b", "c"},
};
assertTrue(SearchMatrix.contains(matrix, null));
assertTrue(SearchMatrix.contains(matrix, "c"));
assertFalse(SearchMatrix.contains(matrix, "d"));
}
@Test
void supportsJaggedMatricesAndNullRows() {
final Integer[][] matrix = {
{1, 2, 3},
null,
{},
{4},
};
assertTrue(SearchMatrix.contains(matrix, 4));
assertFalse(SearchMatrix.contains(matrix, 5));
}
}