Esempio n. 1
0
 def check(self, number: int, isPrime: bool):
     """Checks if the user's program correctly determines primality and provides a helpful message if not."""
     self.assertEqual(
         prime_number(number), isPrime,
         f"Error: {number} was found {'not ' if isPrime else ''}to be prime."
     )
Esempio n. 2
0
 def test_two(self):
     results = prime.prime_number(2)
     self.assertEqual([2], results)
Esempio n. 3
0
 def test_eight(self):
     results = prime.prime_number(8)
     self.assertEqual([2, 3, 5, 7], results)
Esempio n. 4
0
 def test_data_type(self):
     results = prime.prime_number("hello")
     self.assertEqual("invalid data", results)
Esempio n. 5
0
 def test_zero(self):
     results = prime.prime_number(0)
     self.assertEqual([], results)
Esempio n. 6
0
 def test_negative(self):
     results = prime.prime_number(-5)
     self.assertEqual([], results)
Esempio n. 7
0
def test_prime_odd():
    for i in [3, 5, 7, 11, 13]:
        assert prime_number(i) == True
    for i in [9, 15, 35, 121]:
        assert prime_number(i) == False
Esempio n. 8
0
def test_prime_even():
    assert prime_number(2) == True
    for i in range(4, 100, 2):
        assert prime_number(i) == False