Update PeakElementFinderUnitTest.java

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

View File

@ -8,19 +8,11 @@ import static org.junit.jupiter.api.Assertions.*;
public class PeakElementFinderUnitTest { public class PeakElementFinderUnitTest {
@Test
void findPeakElement_givenArrayOfIntegers_whenValidInput_thenReturnsCorrectPeakIndex() {
PeakElementFinder finder = new PeakElementFinder();
int[] array = {5, 8, 7, 6, 12};
List<Integer> peaks = finder.findPeakElement(array);
assertEquals(2, peaks.size() );
}
@Test @Test
void findPeakElement_givenArrayOfIntegers_whenNoPeaks_thenReturnsMinusOne() { void findPeakElement_givenArrayOfIntegers_whenNoPeaks_thenReturnsMinusOne() {
PeakElementFinder finder = new PeakElementFinder(); PeakElementFinder finder = new PeakElementFinder();
int[] array = {5, 8, 7, 6, 12}; int[] array = {5, 8, 7, 6, 12};
List<Integer> peaks = finder.findPeakElement(array); List<Integer> peaks = finder.findPeakElements(array);
assertEquals(2, peaks.size()); assertEquals(2, peaks.size());
} }
@ -28,7 +20,7 @@ public class PeakElementFinderUnitTest {
void findPeakElement_givenArrayOfIntegers_whenPeaksAtExtremes_thenReturnsCorrectPeakIndex() { void findPeakElement_givenArrayOfIntegers_whenPeaksAtExtremes_thenReturnsCorrectPeakIndex() {
PeakElementFinder finder = new PeakElementFinder(); PeakElementFinder finder = new PeakElementFinder();
int[] array = {5, 2, 1, 3, 4}; int[] array = {5, 2, 1, 3, 4};
List<Integer> peaks = finder.findPeakElement(array); List<Integer> peaks = finder.findPeakElements(array);
assertEquals(2, peaks.size()); assertEquals(2, peaks.size());
} }
@ -36,7 +28,7 @@ public class PeakElementFinderUnitTest {
void findPeakElement_givenArrayOfIntegers_whenPlateaus_thenReturnsCorrectPeakIndex() { void findPeakElement_givenArrayOfIntegers_whenPlateaus_thenReturnsCorrectPeakIndex() {
PeakElementFinder finder = new PeakElementFinder(); PeakElementFinder finder = new PeakElementFinder();
int[] array = {1, 2, 2, 2, 3, 4, 5}; int[] array = {1, 2, 2, 2, 3, 4, 5};
List<Integer> peaks = finder.findPeakElement(array); List<Integer> peaks = finder.findPeakElements(array);
assertEquals(2, peaks.size()); assertEquals(1, peaks.size());
} }
} }