瀏覽代碼

prime-factors: convert to use instance methods

Stuart Kent 9 年之前
父節點
當前提交
e3c19cfeb7

exercises/prime-factors/src/example/java/PrimeFactors.java → exercises/prime-factors/src/example/java/PrimeFactorsCalculator.java 查看文件

@@ -1,9 +1,9 @@
1 1
 import java.util.ArrayList;
2 2
 import java.util.List;
3 3
 
4
-public class PrimeFactors {
4
+public class PrimeFactorsCalculator {
5 5
 
6
-    public static List<Long> getForNumber(long number) {
6
+    public List<Long> calculatePrimeFactorsOf(long number) {
7 7
         List<Long> primes = new ArrayList<>();
8 8
         long divisor = 2;
9 9
 

exercises/prime-factors/src/test/java/PrimeFactorsTest.java → exercises/prime-factors/src/test/java/PrimeFactorsCalculatorTest.java 查看文件

@@ -1,17 +1,17 @@
1 1
 import org.junit.Test;
2
-import org.junit.Ignore;
3 2
 import org.junit.runner.RunWith;
4 3
 import org.junit.runners.Parameterized;
5 4
 import org.junit.runners.Parameterized.Parameters;
6 5
 
7 6
 import java.util.Arrays;
8 7
 import java.util.Collection;
8
+import java.util.Collections;
9 9
 import java.util.List;
10 10
 
11 11
 import static org.junit.Assert.assertEquals;
12 12
 
13 13
 @RunWith(Parameterized.class)
14
-public class PrimeFactorsTest {
14
+public class PrimeFactorsCalculatorTest {
15 15
 
16 16
     private long input;
17 17
     private List<Long> expectedOutput;
@@ -19,9 +19,9 @@ public class PrimeFactorsTest {
19 19
     @Parameters(name="Prime factors of {0} = {1}")
20 20
     public static Collection<Object[]> data() {
21 21
         return Arrays.asList(new Object[][]{
22
-                {1L, Arrays.asList()},
23
-                {2L, Arrays.asList(2L)},
24
-                {3L, Arrays.asList(3L)},
22
+                {1L, Collections.emptyList()},
23
+                {2L, Collections.singletonList(2L)},
24
+                {3L, Collections.singletonList(3L)},
25 25
                 {4L, Arrays.asList(2L, 2L)},
26 26
                 {6L, Arrays.asList(2L, 3L)},
27 27
                 {8L, Arrays.asList(2L, 2L, 2L)},
@@ -33,14 +33,14 @@ public class PrimeFactorsTest {
33 33
         });
34 34
     }
35 35
 
36
-    public PrimeFactorsTest(long input, List<Long> expectedOutput) {
36
+    public PrimeFactorsCalculatorTest(long input, List<Long> expectedOutput) {
37 37
         this.input = input;
38 38
         this.expectedOutput = expectedOutput;
39 39
     }
40 40
 
41
-
42 41
     @Test
43 42
     public void test() {
44
-        assertEquals(expectedOutput, PrimeFactors.getForNumber(input));
43
+        assertEquals(expectedOutput, new PrimeFactorsCalculator().calculatePrimeFactorsOf(input));
45 44
     }
45
+
46 46
 }