Преглед изворни кода

Update PrimeFactorsCalculatorTest (#1308)

* Update PrimeFactorsCalculatorTest

* Separate tests individually

* update tests
Lu Lechuan пре 8 година
родитељ
комит
c5f7350951
1 измењених фајлова са 42 додато и 24 уклоњено
  1. 42
    24
      exercises/prime-factors/src/test/java/PrimeFactorsCalculatorTest.java

+ 42
- 24
exercises/prime-factors/src/test/java/PrimeFactorsCalculatorTest.java Прегледај датотеку

@@ -1,42 +1,60 @@
1
+import org.junit.Before;
2
+import org.junit.Ignore;
1 3
 import org.junit.Test;
2
-import org.junit.runner.RunWith;
3
-import org.junit.runners.Parameterized;
4
-import org.junit.runners.Parameterized.Parameters;
5 4
 
6 5
 import java.util.Arrays;
7
-import java.util.Collection;
8 6
 import java.util.Collections;
9
-import java.util.List;
10 7
 
11 8
 import static org.junit.Assert.assertEquals;
12 9
 
13
-@RunWith(Parameterized.class)
14 10
 public class PrimeFactorsCalculatorTest {
15 11
 
16
-    private long input;
17
-    private List<Long> expectedOutput;
12
+    private PrimeFactorsCalculator primeFactorsCalculator;
18 13
 
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();
30 17
     }
31 18
 
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));
35 52
     }
36 53
 
54
+    @Ignore("Remove to run test")
37 55
     @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));
40 58
     }
41 59
 
42 60
 }