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." )
def test_two(self): results = prime.prime_number(2) self.assertEqual([2], results)
def test_eight(self): results = prime.prime_number(8) self.assertEqual([2, 3, 5, 7], results)
def test_data_type(self): results = prime.prime_number("hello") self.assertEqual("invalid data", results)
def test_zero(self): results = prime.prime_number(0) self.assertEqual([], results)
def test_negative(self): results = prime.prime_number(-5) self.assertEqual([], results)
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
def test_prime_even(): assert prime_number(2) == True for i in range(4, 100, 2): assert prime_number(i) == False