Update SinglePeakFinderUnitTest.java
This commit is contained in:
parent
1155a6d8e8
commit
16b8708d25
|
@ -2,12 +2,23 @@ package com.baeldung.peakelements;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
import java.util.OptionalInt;
|
||||||
|
|
||||||
public class SinglePeakFinderUnitTest {
|
public class SinglePeakFinderUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void findSinglePeak_givenArrayOfIntegers_whenValidInput_thenReturnsCorrectPeak() {
|
void findSinglePeak_givenArrayOfIntegers_whenValidInput_thenReturnsCorrectPeak() {
|
||||||
int[] arr = {0, 10, 2, 4, 5, 1};
|
int[] arr = {0, 10, 2, 4, 5, 1};
|
||||||
assertEquals(10, SinglePeakFinder.findSinglePeak(arr));
|
OptionalInt peak = SinglePeakFinder.findSinglePeak(arr);
|
||||||
|
assertTrue(peak.isPresent());
|
||||||
|
assertEquals(10, peak.getAsInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void findSinglePeak_givenEmptyArray_thenReturnsEmptyOptional() {
|
||||||
|
int[] arr = {};
|
||||||
|
OptionalInt peak = SinglePeakFinder.findSinglePeak(arr);
|
||||||
|
assertTrue(peak.isEmpty());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue