diff --git a/core-java-modules/core-java-lang-math-4/src/test/java/com/baeldung/percentile/CalculatePercentileUnitTest.java b/core-java-modules/core-java-lang-math-4/src/test/java/com/baeldung/percentile/CalculatePercentileUnitTest.java index 84aac76b7e..7b46b37e38 100644 --- a/core-java-modules/core-java-lang-math-4/src/test/java/com/baeldung/percentile/CalculatePercentileUnitTest.java +++ b/core-java-modules/core-java-lang-math-4/src/test/java/com/baeldung/percentile/CalculatePercentileUnitTest.java @@ -9,7 +9,6 @@ import java.util.Collections; import java.util.List; import java.util.stream.Collectors; import java.util.stream.IntStream; -import java.util.stream.LongStream; import org.junit.jupiter.api.Test; @@ -40,36 +39,40 @@ public class CalculatePercentileUnitTest { .collect(Collectors.toList()); Collections.shuffle(list100); + assertEquals(1, getPercentile(list100, 0)); assertEquals(10, getPercentile(list100, 10)); assertEquals(25, getPercentile(list100, 25)); assertEquals(50, getPercentile(list100, 50)); assertEquals(76, getPercentile(list100, 75.3)); + assertEquals(100, getPercentile(list100, 100)); List list8 = IntStream.of(-1, 200, 30, 42, -5, 7, 8, 92) .boxed() .collect(Collectors.toList()); + assertEquals(-5, getPercentile(list8, 0)); assertEquals(-5, getPercentile(list8, 10)); assertEquals(-1, getPercentile(list8, 25)); assertEquals(8, getPercentile(list8, 50)); assertEquals(92, getPercentile(list8, 75.3)); + assertEquals(200, getPercentile(list8, 100)); } @Test void whenCallingGetPercentileWithAnArray_thenGetExpectedResult() { - //prepare the input array - long[] theArray = LongStream.of(-1, 200, 30, 42, -5, 7, 8, 92) - .toArray(); + long[] theArray = new long[] { -1, 200, 30, 42, -5, 7, 8, 92 }; //convert the long[] array to a List List list8 = Arrays.stream(theArray) .boxed() .toList(); + assertEquals(-5, getPercentile(list8, 0)); assertEquals(-5, getPercentile(list8, 10)); assertEquals(-1, getPercentile(list8, 25)); assertEquals(8, getPercentile(list8, 50)); assertEquals(92, getPercentile(list8, 75.3)); + assertEquals(200, getPercentile(list8, 100)); } } \ No newline at end of file