Example #1
0
 def test_nextPrime(self):
     primes=[2,3,5,7,11,13,17,19]
     for c,n in zip(primes[:-1],primes[1:]):
         self.assert_(HappyPrime.nextPrime(c)==n, 'nextPrime() thinks that next prime after %d is not %d' % (c,n))
Example #2
0
 def test_isHappy(self):
     self.assert_(HappyPrime.isHappy(HappyPrime.sumSquareDigits(313)), 'isHappy() thinks %d is not happy' % HappyPrime.sumSquareDigits(313))
     self.assert_(HappyPrime.isHappy(313), 'isHappy() thinks that 313 is not happy')
Example #3
0
 def test_isPrime(self):
     self.assert_(HappyPrime.isPrime(313), 'isPrime() thinks 313 is not prime')
     # Some known primes (primes smaller than 20)
     for prime in [2,3,5,7,11,13,17,19]:
         self.assert_(HappyPrime.isPrime(prime), 'isPrime() thinks %d is not prime' % prime)
Example #4
0
 def test_getNextHappyPrime(self):
     happyprimes=[313,331,367,379]
     for c,n in zip(happyprimes[:-1],happyprimes[1:]):
         self.assert_(HappyPrime.getNextHappyPrime(c)==n,
     'getNextHappyPrime() thinks that next happy prime after %d is %d, not %d' % (c,HappyPrime.getNextHappyPrime(c),n))