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