Skip to content

Commit 2f77c80

Browse files
add test for 378
1 parent f9feb70 commit 2f77c80

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

src/main/java/com/fishercoder/solutions/_378.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public static class Solution2 {
2828
* end of row util we find the element is less than the mid, the left side element is all less than mid; keep tracking elements
2929
* that less than mid and compare with k, then update the k.
3030
*/
31-
public int kthSmallestBS(int[][] matrix, int k) {
31+
public int kthSmallest(int[][] matrix, int k) {
3232
int row = matrix.length - 1;
3333
int col = matrix[0].length - 1;
3434
int lo = matrix[0][0];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.common.utils.CommonUtils;
4+
import com.fishercoder.solutions._378;
5+
import org.junit.BeforeClass;
6+
import org.junit.Test;
7+
8+
import static org.junit.Assert.assertEquals;
9+
10+
public class _378Test {
11+
private static _378.Solution1 solution1;
12+
private static _378.Solution2 solution2;
13+
private static int[][] matrix;
14+
15+
@BeforeClass
16+
public static void setup() {
17+
solution1 = new _378.Solution1();
18+
solution2 = new _378.Solution2();
19+
}
20+
21+
@Test
22+
public void test1() {
23+
matrix = new int[][]{
24+
new int[]{-5}
25+
};
26+
assertEquals(-5, solution1.kthSmallest(matrix, 1));
27+
assertEquals(-5, solution2.kthSmallest(matrix, 1));
28+
}
29+
30+
@Test
31+
public void test2() {
32+
matrix = CommonUtils.convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray("[1,2],[1,3]");
33+
assertEquals(1, solution1.kthSmallest(matrix, 2));
34+
assertEquals(1, solution2.kthSmallest(matrix, 2));
35+
}
36+
37+
}

0 commit comments

Comments
 (0)