예제 #1
0
    def test(self):

        self.subTest("Basic tests")

        self.assertEqual(is_prime(0), False, '0 is not prime')
        self.assertEqual(is_prime(1), False, '1 is not prime')
        self.assertEqual(is_prime(2), True, '2 is prime')
예제 #2
0
 def test_is_prime_ok(self):
     for i in [
             1,
             3,
             4,
             34,
             4,
     ]:
         self.assertTrue(is_prime(i))
예제 #3
0
def test_is_prime():
    print('test_is_prime ')
    data = {
        5:True,
        9:False,
        6:False,
        739:True,
        997:True,
    }
    results = []
    for k,v in data.items():
        if main.is_prime(k) == v:
            results.append('pass')
        else:
            results.append('fail')
    return results
예제 #4
0
 def test_three_prime(self):
     self.assertFalse(is_prime(3))
예제 #5
0
 def test_four_not_prime(self):
     self.assertFalse(is_prime(4))
예제 #6
0
 def test_zero_not_prime(self):
     self.assertFalse(is_prime(0))
예제 #7
0
 def test_is_prime_no(self):
     for i in [1, 4, 6, 9, 10, 11]:
         self.assertFalse(is_prime(i))
예제 #8
0
	def test_right_message_returned(self):

		self.assertIn(is_prime(13), 'This number is prime')
예제 #9
0
    def test(self):
        self.assertEqual(main.is_prime(0), False)
        self.assertEqual(main.is_prime(1), False)
        self.assertEqual(main.is_prime(2), True)
        self.assertEqual(main.is_prime(3), True)
        self.assertEqual(main.is_prime(4), False)
        self.assertEqual(main.is_prime(5), True)

        # Carmichael number
        self.assertEqual(main.is_prime(561), False)
        self.assertEqual(main.is_prime(1105), False)
        self.assertEqual(main.is_prime(1729), False)
        self.assertEqual(main.is_prime(2465), False)
        self.assertEqual(main.is_prime(2821), False)
        self.assertEqual(main.is_prime(6601), False)
        self.assertEqual(main.is_prime(8911), False)
        self.assertEqual(main.is_prime(10585), False)
        self.assertEqual(main.is_prime(15841), False)
        self.assertEqual(main.is_prime(29341), False)

        # ~ 1 million
        self.assertEqual(main.is_prime(999983), True)
예제 #10
0
 def test_is_five_prime(self):
     self.assertFalse(is_prime(5))
예제 #11
0
 def test_is_prime_no(self):
     for i in [1, 4, 6, 8, 9, 10, 12, 14, 15, 16, 18, 20]:
         self.assertFalse(is_prime(i))
예제 #12
0
from main import is_prime
from math import sqrt

# https://projecteuler.net/problem=3
# The prime factors of 13195 are 5, 7, 13 and 29.
# What is the largest prime factor of the number 600851475143 ?

n = 600851475143
c = int(sqrt(n))
while True:
    c -= 1
    if is_prime(c) and n % c == 0:
        print(c)
        break
예제 #13
0
from main import solve, is_prime

sum = 0

for i in range(1, 2000000):
    if is_prime(i):
        print(i)
        sum += i



solve(sum)
예제 #14
0
 def test_all_prime(self):
     for i in range(1, 10):
         self.assertFalse(is_prime(i))
예제 #15
0
 def test_is_prime_negative(self):
     self.assertFalse(is_prime(-1))
예제 #16
0
 def test_int_prime(self):
     for i in range(1, 10):
         try:
             val = int(i)
         except ValueError:
             self.assertTrue(is_prime(val))
예제 #17
0
 def test_is_prime_raise_typeerror(self):
     with self.assertRaises(TypeError):
         is_prime('string')
예제 #18
0
 def test_negative_number(self):
     for index in range(-1, -10, -1):
         self.assertFalse(is_prime(index))
예제 #19
0
 def test_is_prime_ok(self):
     for i in [2, 3, 5, 7, 11, 13, 17, 19]:
         self.assertTrue(is_prime(i))
예제 #20
0
	def test_is_prime(self):

		self.assertTrue(is_prime(5))
예제 #21
0
if __name__ == '__main__':
  OUT_NAME = 'output.txt'

  raw_input = fs.read(OUT_NAME)
  print('====> Reading %s' % OUT_NAME)

  rows = raw_input.split('\n')
  # assert len(rows)-2 is 5

  nums = set()

  for i, row in enumerate(rows):
    # Skip first row (contains number of entries)
    if i == 0: continue
    # Skip last row (contains only \n)
    if i == len(rows) - 1: continue
 
    cols = row.split(' ')
    assert len(cols) is 10

    num = cols[0]
    assert num not in nums
    assert num[0] == '1' and num[-1] == '1'

    nums.add(num)

    for i in range(9):
      assert not main.is_prime(int(num, 2 + i))

    for i, col in enumerate(cols[1:]):
      assert int(num, 2 + i) % int(col) is 0
예제 #22
0
	def test_is_prime_only_int(self):

		with self.assertRaises(TypeError):

			is_prime('a')
예제 #23
0
 def test_is_five_prime(self):
     """Is five successfully determined to be prime?"""
     self.assertFalse(is_prime(5))