lots of exercises in java... from https://github.com/exercism/java

PrimeFactorsCalculatorTest.java 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import org.junit.Before;
  2. import org.junit.Ignore;
  3. import org.junit.Test;
  4. import java.util.Arrays;
  5. import java.util.Collections;
  6. import static org.junit.Assert.assertEquals;
  7. public class PrimeFactorsCalculatorTest {
  8. private PrimeFactorsCalculator primeFactorsCalculator;
  9. @Before
  10. public void setUp() {
  11. primeFactorsCalculator = new PrimeFactorsCalculator();
  12. }
  13. @Test
  14. public void testNoFactors() {
  15. assertEquals(Collections.emptyList(), primeFactorsCalculator.calculatePrimeFactorsOf(1L));
  16. }
  17. @Ignore("Remove to run test")
  18. @Test
  19. public void testPrimeNumber() {
  20. assertEquals(Collections.singletonList(2L), primeFactorsCalculator.calculatePrimeFactorsOf(2L));
  21. }
  22. @Ignore("Remove to run test")
  23. @Test
  24. public void testSquareOfAPrime() {
  25. assertEquals(Arrays.asList(3L, 3L), primeFactorsCalculator.calculatePrimeFactorsOf(9L));
  26. }
  27. @Ignore("Remove to run test")
  28. @Test
  29. public void testCubeOfAPrime() {
  30. assertEquals(Arrays.asList(2L, 2L, 2L), primeFactorsCalculator.calculatePrimeFactorsOf(8L));
  31. }
  32. @Ignore("Remove to run test")
  33. @Test
  34. public void testProductOfPrimesAndNonPrimes() {
  35. assertEquals(Arrays.asList(2L, 2L, 3L), primeFactorsCalculator.calculatePrimeFactorsOf(12L));
  36. }
  37. @Ignore("Remove to run test")
  38. @Test
  39. public void testProductOfPrimes() {
  40. assertEquals(Arrays.asList(5L, 17L, 23L, 461L), primeFactorsCalculator.calculatePrimeFactorsOf(901255L));
  41. }
  42. @Ignore("Remove to run test")
  43. @Test
  44. public void testFactorsIncludingALargePrime() {
  45. assertEquals(Arrays.asList(11L, 9539L, 894119L), primeFactorsCalculator.calculatePrimeFactorsOf(93819012551L));
  46. }
  47. }