refactor: improving MedianOfMatrix (#6376)

refactor: improving MedianOfMatrix
This commit is contained in:
Oleksandr Klymenko
2025-07-15 08:23:49 +03:00
committed by GitHub
parent 25aaa6e064
commit 95116dbee4
2 changed files with 26 additions and 10 deletions

View File

@@ -1,9 +1,11 @@
package com.thealgorithms.matrix;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.junit.jupiter.api.Test;
@@ -31,4 +33,18 @@ public class MedianOfMatrixTest {
assertEquals(2, result);
}
@Test
public void testMedianSingleElement() {
List<List<Integer>> matrix = new ArrayList<>();
matrix.add(List.of(1));
assertEquals(1, MedianOfMatrix.median(matrix));
}
@Test
void testEmptyMatrixThrowsException() {
Iterable<List<Integer>> emptyMatrix = Collections.emptyList();
assertThrows(IllegalArgumentException.class, () -> MedianOfMatrix.median(emptyMatrix), "Expected median() to throw, but it didn't");
}
}