class Problem47: def __init__(self): self.primeChecker = PrimeChecker() self.primeChecker.initPrimeFactoring() def findConsecutivePrime(self, n): i = 1 while True: for j in range(0, n): if not len(self.primeChecker.getUniquePrimeFactors(i, True)) == n: break i += 1 if j == n - 1: return i-n i += 1 def answer(self): return self.findConsecutivePrime(4)
class TestProblem47(unittest.TestCase): def setUp(self): self.primeChecker = PrimeChecker() self.primeChecker.initPrimeFactoring() pass def tearDown(self): pass def test_47ShouldBeAPrime(self): self.assertTrue(PrimeChecker.isPrime(47)) def test_27ShouldNotBeAPrime(self): self.assertFalse(PrimeChecker.isPrime(27)) def test_primesBelow20ShouldBe235711131719(self): self.assertEquals([2,3,5,7,11,13,17,19], PrimeChecker.primesBelow(20)) def test_primeFactorsFor644ShouldBe22723(self): self.assertEquals([2,2,7,23], self.primeChecker.getPrimeFactors(644, True)) def test_uniquePrimeFactorsFor644ShouldBe2723(self): self.assertEquals([2,7,23], self.primeChecker.getUniquePrimeFactors(644, True))