mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-07 01:35:16 +08:00
style: handle empty input array in FindMin.findMin
(#4205)
* tests: add test case with mininum not being at the beginning * style: throw IllegalArgumentException when input is empty * style: use enhanced for loop * docs: update doc-str
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
package com.thealgorithms.maths;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@ -23,4 +24,17 @@ public class FindMinTest {
|
||||
public void test2() {
|
||||
assertEquals(0, FindMin.findMin(new int[] { 0, 192, 384, 576 }));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test3() {
|
||||
assertEquals(0, FindMin.findMin(new int[] { 10, 10, 0, 10 }));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindMinThrowsExceptionForEmptyInput() {
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> FindMin.findMin(new int[]{})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user