-
Notifications
You must be signed in to change notification settings - Fork 14
/
CountNegativesInSortedMatrixTest.java
52 lines (43 loc) · 1.55 KB
/
CountNegativesInSortedMatrixTest.java
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
package by.andd3dfx.search;
import lombok.AllArgsConstructor;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import java.util.Arrays;
import java.util.Collection;
import static by.andd3dfx.search.CountNegativesInSortedMatrix.count_MN;
import static by.andd3dfx.search.CountNegativesInSortedMatrix.count_NPlusM;
import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @see <a href="https://youtu.be/QIwQCzDU3XM">Video solution</a>
*/
@AllArgsConstructor
@RunWith(Parameterized.class)
public class CountNegativesInSortedMatrixTest {
private final Grid grid;
private final int expectedResult;
private record Grid(int[][] value) {
@Override
public String toString() {
return Arrays.deepToString(value);
}
}
@Parameters(name = "{0} -> {1}")
public static Collection<Object[]> data() {
return asList(
new Object[]{new Grid(new int[][]{{4, 3, 2, -1}, {3, 2, 1, -1}, {1, 1, -1, -2}, {-1, -1, -2, -3}}), 8},
new Object[]{new Grid(new int[][]{{3, 2}, {1, 0}}), 0},
new Object[]{new Grid(new int[][]{}), 0}
);
}
@Test
public void testCount_MN() {
assertThat(count_MN(grid.value)).isEqualTo(expectedResult);
}
@Test
public void testCount_NPlusM() {
assertThat(count_NPlusM(grid.value)).isEqualTo(expectedResult);
}
}