From e3c19cfeb7aee82faa1200773843360ddcfc1ec4 Mon Sep 17 00:00:00 2001 From: Stuart Kent Date: Wed, 5 Apr 2017 19:57:07 -0400 Subject: [PATCH] prime-factors: convert to use instance methods --- ...eFactors.java => PrimeFactorsCalculator.java} | 4 ++-- ...Test.java => PrimeFactorsCalculatorTest.java} | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) rename exercises/prime-factors/src/example/java/{PrimeFactors.java => PrimeFactorsCalculator.java} (78%) rename exercises/prime-factors/src/test/java/{PrimeFactorsTest.java => PrimeFactorsCalculatorTest.java} (72%) diff --git a/exercises/prime-factors/src/example/java/PrimeFactors.java b/exercises/prime-factors/src/example/java/PrimeFactorsCalculator.java similarity index 78% rename from exercises/prime-factors/src/example/java/PrimeFactors.java rename to exercises/prime-factors/src/example/java/PrimeFactorsCalculator.java index b90c5b487..8a2d22d26 100644 --- a/exercises/prime-factors/src/example/java/PrimeFactors.java +++ b/exercises/prime-factors/src/example/java/PrimeFactorsCalculator.java @@ -1,9 +1,9 @@ import java.util.ArrayList; import java.util.List; -public class PrimeFactors { +public class PrimeFactorsCalculator { - public static List getForNumber(long number) { + public List calculatePrimeFactorsOf(long number) { List primes = new ArrayList<>(); long divisor = 2; diff --git a/exercises/prime-factors/src/test/java/PrimeFactorsTest.java b/exercises/prime-factors/src/test/java/PrimeFactorsCalculatorTest.java similarity index 72% rename from exercises/prime-factors/src/test/java/PrimeFactorsTest.java rename to exercises/prime-factors/src/test/java/PrimeFactorsCalculatorTest.java index 22a5786b4..2151ca550 100644 --- a/exercises/prime-factors/src/test/java/PrimeFactorsTest.java +++ b/exercises/prime-factors/src/test/java/PrimeFactorsCalculatorTest.java @@ -1,17 +1,17 @@ import org.junit.Test; -import org.junit.Ignore; 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 PrimeFactorsTest { +public class PrimeFactorsCalculatorTest { private long input; private List expectedOutput; @@ -19,9 +19,9 @@ public class PrimeFactorsTest { @Parameters(name="Prime factors of {0} = {1}") public static Collection data() { return Arrays.asList(new Object[][]{ - {1L, Arrays.asList()}, - {2L, Arrays.asList(2L)}, - {3L, Arrays.asList(3L)}, + {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)}, @@ -33,14 +33,14 @@ public static Collection data() { }); } - public PrimeFactorsTest(long input, List expectedOutput) { + public PrimeFactorsCalculatorTest(long input, List expectedOutput) { this.input = input; this.expectedOutput = expectedOutput; } - @Test public void test() { - assertEquals(expectedOutput, PrimeFactors.getForNumber(input)); + assertEquals(expectedOutput, new PrimeFactorsCalculator().calculatePrimeFactorsOf(input)); } + }