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:
Piotr Idzik
2023-05-28 13:08:44 +02:00
committed by GitHub
parent e14b30b88c
commit 4f15149804
2 changed files with 25 additions and 7 deletions

View File

@ -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[]{})
);
}
}