Bladeren bron

Use longs for all values. (closes #48)(closes #49)

John S. Ryan 11 jaren geleden
bovenliggende
commit
3cf5bb27b3

+ 3
- 3
prime-factors/src/example/java/PrimeFactors.java Bestand weergeven

3
 
3
 
4
 public class PrimeFactors {
4
 public class PrimeFactors {
5
 
5
 
6
-    public static List<Integer> getForNumber(double number) {
7
-        List<Integer> primes = new ArrayList<>();
8
-        int divisor = 2;
6
+    public static List<Long> getForNumber(long number) {
7
+        List<Long> primes = new ArrayList<>();
8
+        long divisor = 2;
9
 
9
 
10
         while (number > 1) {
10
         while (number > 1) {
11
             while (number % divisor == 0) {
11
             while (number % divisor == 0) {

+ 14
- 14
prime-factors/src/test/java/PrimeFactorsTest.java Bestand weergeven

12
 @RunWith(Parameterized.class)
12
 @RunWith(Parameterized.class)
13
 public class PrimeFactorsTest {
13
 public class PrimeFactorsTest {
14
 
14
 
15
-    private double input;
16
-    private List<Integer> expectedOutput;
15
+    private long input;
16
+    private List<Long> expectedOutput;
17
 
17
 
18
     @Parameters(name="Prime factors of {0} = {1}")
18
     @Parameters(name="Prime factors of {0} = {1}")
19
     public static Collection<Object[]> data() {
19
     public static Collection<Object[]> data() {
20
         return Arrays.asList(new Object[][]{
20
         return Arrays.asList(new Object[][]{
21
-                {1, Arrays.asList(new Integer[0])},
22
-                {2, Arrays.asList(new Integer[]{2})},
23
-                {3, Arrays.asList(new Integer[]{3})},
24
-                {4, Arrays.asList(new Integer[]{2, 2})},
25
-                {6, Arrays.asList(new Integer[]{2, 3})},
26
-                {8, Arrays.asList(new Integer[]{2, 2, 2})},
27
-                {9, Arrays.asList(new Integer[]{3, 3})},
28
-                {27, Arrays.asList(new Integer[]{3, 3, 3})},
29
-                {625, Arrays.asList(new Integer[]{5, 5, 5, 5})},
30
-                {901255, Arrays.asList(new Integer[]{5, 17, 23, 461})},
31
-                {93819012551L, Arrays.asList(new Integer[]{11, 9539, 894119})}
21
+                {1L, Arrays.asList()},
22
+                {2L, Arrays.asList(2L)},
23
+                {3L, Arrays.asList(3L)},
24
+                {4L, Arrays.asList(2L, 2L)},
25
+                {6L, Arrays.asList(2L, 3L)},
26
+                {8L, Arrays.asList(2L, 2L, 2L)},
27
+                {9L, Arrays.asList(3L, 3L)},
28
+                {27L, Arrays.asList(3L, 3L, 3L)},
29
+                {625L, Arrays.asList(5L, 5L, 5L, 5L)},
30
+                {901255L, Arrays.asList(5L, 17L, 23L, 461L)},
31
+                {93819012551L, Arrays.asList(11L, 9539L, 894119L)}
32
         });
32
         });
33
     }
33
     }
34
 
34
 
35
-    public PrimeFactorsTest(double input, List<Integer> expectedOutput) {
35
+    public PrimeFactorsTest(long input, List<Long> expectedOutput) {
36
         this.input = input;
36
         this.input = input;
37
         this.expectedOutput = expectedOutput;
37
         this.expectedOutput = expectedOutput;
38
     }
38
     }