diff --git a/src/test/java/com/thealgorithms/maths/PrimeFactorizationTest.java b/src/test/java/com/thealgorithms/maths/PrimeFactorizationTest.java index abe6068c2..6994379d7 100644 --- a/src/test/java/com/thealgorithms/maths/PrimeFactorizationTest.java +++ b/src/test/java/com/thealgorithms/maths/PrimeFactorizationTest.java @@ -1,36 +1,32 @@ package com.thealgorithms.maths; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.List; -import org.junit.jupiter.api.Test; +import java.util.stream.Stream; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; class PrimeFactorizationTest { - @Test - void testpFactorsMustReturnEmptyList() { - // given - int n = 0; - - // then - assertTrue(PrimeFactorization.pfactors(n).isEmpty()); + @ParameterizedTest + @MethodSource("provideNumbersAndFactors") + void testPrimeFactorization(int number, List expectedFactors) { + assertEquals(expectedFactors, PrimeFactorization.pfactors(number), "Prime factors for number: " + number); } - @Test - void testpFactorsMustReturnNonEmptyList() { - // given - int n = 198; - int expectedListSize = 4; + @ParameterizedTest + @MethodSource("provideNumbersAndSizes") + void testPrimeFactorsSize(int number, int expectedSize) { + assertEquals(expectedSize, PrimeFactorization.pfactors(number).size(), "Size of prime factors list for number: " + number); + } - // when - List actualResultList = PrimeFactorization.pfactors(n); + private static Stream provideNumbersAndFactors() { + return Stream.of(Arguments.of(0, List.of()), Arguments.of(1, List.of()), Arguments.of(2, List.of(2)), Arguments.of(3, List.of(3)), Arguments.of(4, List.of(2, 2)), Arguments.of(18, List.of(2, 3, 3)), Arguments.of(100, List.of(2, 2, 5, 5)), Arguments.of(198, List.of(2, 3, 3, 11))); + } - // then - assertEquals(expectedListSize, actualResultList.size()); - assertEquals(2, actualResultList.get(0)); - assertEquals(3, actualResultList.get(1)); - assertEquals(3, actualResultList.get(2)); - assertEquals(11, actualResultList.get(3)); + private static Stream provideNumbersAndSizes() { + return Stream.of(Arguments.of(2, 1), Arguments.of(3, 1), Arguments.of(4, 2), Arguments.of(18, 3), Arguments.of(100, 4), Arguments.of(198, 4)); } }