1
exercism fetch java prime-factors

src/test/java/PrimeFactorsCalculatorTest.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

import static org.junit.Assert.assertEquals;

@RunWith(Parameterized.class)
public class PrimeFactorsCalculatorTest {

    private long input;
    private List<Long> expectedOutput;

    @Parameters(name="Prime factors of {0} = {1}")
    public static Collection<Object[]> data() {
        return Arrays.asList(new Object[][]{
                {1L, Collections.emptyList()},
                {2L, Collections.singletonList(2L)},
                {3L, Collections.singletonList(3L)},
                {4L, Arrays.asList(2L, 2L)},
                {6L, Arrays.asList(2L, 3L)},
                {8L, Arrays.asList(2L, 2L, 2L)},
                {9L, Arrays.asList(3L, 3L)},
                {27L, Arrays.asList(3L, 3L, 3L)},
                {625L, Arrays.asList(5L, 5L, 5L, 5L)},
                {901255L, Arrays.asList(5L, 17L, 23L, 461L)},
                {93819012551L, Arrays.asList(11L, 9539L, 894119L)}
        });
    }

    public PrimeFactorsCalculatorTest(long input, List<Long> expectedOutput) {
        this.input = input;
        this.expectedOutput = expectedOutput;
    }

    @Test
    public void test() {
        assertEquals(expectedOutput, new PrimeFactorsCalculator().calculatePrimeFactorsOf(input));
    }

}