Update SinglePeakFinderUnitTest.java

This commit is contained in:
Imran Alam 2024-03-01 13:20:31 +05:30 committed by GitHub
parent 1155a6d8e8
commit 16b8708d25
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 12 additions and 1 deletions

View File

@ -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());
} }
} }