示例#1
0
class PrimesTestCase(unittest.TestCase):
    def setUp(self):
        self.spec_primes = SpecPrimes(1000000)

    def test_sieve(self):
        self.spec_primes.size = 20
        self.assertEqual(self.spec_primes.make_sieve(), [2,3,5,7,11,13,17,19], 'wrong sieve')

    def test_right_truncation(self):
        right_truncation = list(self.spec_primes.right_truncation(3797))
        self.assertEqual(sorted(right_truncation), sorted([379, 37, 3]))
    
    def test_left_truncation(self):
        left_truncation = list(self.spec_primes.left_truncation(3797))
        self.assertEqual(sorted(left_truncation), sorted([797, 97, 7]))

    def test_all_trunc_primes(self):
        nums = list(self.spec_primes.all_truncable_primes())
        self.assertEqual(len(nums), 11, 'Wrong size of truncable list')
        self.assertTrue(23 in nums)
        self.assertFalse(32 in nums)
        self.assertFalse(7 in nums)
        self.assertFalse(11 in nums)
示例#2
0
 def setUp(self):
     self.spec_primes = SpecPrimes(1000000)