mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-27 22:43:30 +08:00
Add prime factorization algorithm (#3278)
This commit is contained in:
@ -0,0 +1,36 @@
|
||||
package com.thealgorithms.maths;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class PrimeFactorizationTest {
|
||||
|
||||
@Test
|
||||
void testpFactorsMustReturnEmptyList() {
|
||||
//given
|
||||
int n = 0;
|
||||
|
||||
//then
|
||||
assertTrue(PrimeFactorization.pfactors(n).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testpFactorsMustReturnNonEmptyList() {
|
||||
//given
|
||||
int n = 198;
|
||||
int expectedListSize = 4;
|
||||
|
||||
//when
|
||||
List<Integer> actualResultList = PrimeFactorization.pfactors(n);
|
||||
|
||||
//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));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user