Skip to content

Commit c5f7350

Browse files
LuLechuanFridaTveit
authored andcommitted
Update PrimeFactorsCalculatorTest (exercism#1308)
* Update PrimeFactorsCalculatorTest * Separate tests individually * update tests
1 parent a8a720d commit c5f7350

1 file changed

Lines changed: 42 additions & 24 deletions

File tree

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,60 @@
1+
import org.junit.Before;
2+
import org.junit.Ignore;
13
import org.junit.Test;
2-
import org.junit.runner.RunWith;
3-
import org.junit.runners.Parameterized;
4-
import org.junit.runners.Parameterized.Parameters;
54

65
import java.util.Arrays;
7-
import java.util.Collection;
86
import java.util.Collections;
9-
import java.util.List;
107

118
import static org.junit.Assert.assertEquals;
129

13-
@RunWith(Parameterized.class)
1410
public class PrimeFactorsCalculatorTest {
1511

16-
private long input;
17-
private List<Long> expectedOutput;
12+
private PrimeFactorsCalculator primeFactorsCalculator;
1813

19-
@Parameters(name="Prime factors of {0} = {1}")
20-
public static Collection<Object[]> data() {
21-
return Arrays.asList(new Object[][]{
22-
{1L, Collections.emptyList()},
23-
{2L, Collections.singletonList(2L)},
24-
{9L, Arrays.asList(3L, 3L)},
25-
{8L, Arrays.asList(2L, 2L, 2L)},
26-
{12L, Arrays.asList(2L, 2L, 3L)},
27-
{901255L, Arrays.asList(5L, 17L, 23L, 461L)},
28-
{93819012551L, Arrays.asList(11L, 9539L, 894119L)}
29-
});
14+
@Before
15+
public void setUp() {
16+
primeFactorsCalculator = new PrimeFactorsCalculator();
3017
}
3118

32-
public PrimeFactorsCalculatorTest(long input, List<Long> expectedOutput) {
33-
this.input = input;
34-
this.expectedOutput = expectedOutput;
19+
@Test
20+
public void testNoFactors() {
21+
assertEquals(Collections.emptyList(), primeFactorsCalculator.calculatePrimeFactorsOf(1L));
22+
}
23+
24+
@Ignore("Remove to run test")
25+
@Test
26+
public void testPrimeNumber() {
27+
assertEquals(Collections.singletonList(2L), primeFactorsCalculator.calculatePrimeFactorsOf(2L));
28+
}
29+
30+
@Ignore("Remove to run test")
31+
@Test
32+
public void testSquareOfAPrime() {
33+
assertEquals(Arrays.asList(3L, 3L), primeFactorsCalculator.calculatePrimeFactorsOf(9L));
34+
}
35+
36+
@Ignore("Remove to run test")
37+
@Test
38+
public void testCubeOfAPrime() {
39+
assertEquals(Arrays.asList(2L, 2L, 2L), primeFactorsCalculator.calculatePrimeFactorsOf(8L));
40+
}
41+
42+
@Ignore("Remove to run test")
43+
@Test
44+
public void testProductOfPrimesAndNonPrimes() {
45+
assertEquals(Arrays.asList(2L, 2L, 3L), primeFactorsCalculator.calculatePrimeFactorsOf(12L));
46+
}
47+
48+
@Ignore("Remove to run test")
49+
@Test
50+
public void testProductOfPrimes() {
51+
assertEquals(Arrays.asList(5L, 17L, 23L, 461L), primeFactorsCalculator.calculatePrimeFactorsOf(901255L));
3552
}
3653

54+
@Ignore("Remove to run test")
3755
@Test
38-
public void test() {
39-
assertEquals(expectedOutput, new PrimeFactorsCalculator().calculatePrimeFactorsOf(input));
56+
public void testFactorsIncludingALargePrime() {
57+
assertEquals(Arrays.asList(11L, 9539L, 894119L), primeFactorsCalculator.calculatePrimeFactorsOf(93819012551L));
4058
}
4159

4260
}

0 commit comments

Comments
 (0)