prime check import math import unittest import pytest def isprimenumber int bool precondition if not isinstancenumber int or not number 0 raise valueerrorisprime only accepts positive integers if 1 number 4 2 and 3 are primes return true elif number 2 or number 2 0 or number 3 0 negatives 0 1 all even numbers all multiples of 3 are not primes return false all primes number are in format of 6k 1 for i in range5 intmath sqrtnumber 1 6 if number i 0 or number i 2 0 return false return true class testunittest testcase def testprimesself assert isprime2 assert isprime3 assert isprime5 assert isprime7 assert isprime11 assert isprime13 assert isprime17 assert isprime19 assert isprime23 assert isprime29 def testnotprimesself with pytest raisesvalueerror isprime19 assert not isprime 0 zero doesn t have any positive factors primes must have exactly two assert not isprime 1 one only has 1 positive factor primes must have exactly two assert not isprime2 2 assert not isprime2 3 assert not isprime3 3 assert not isprime3 5 assert not isprime3 5 7 if name main unittest main checks to see if a number is a prime in o sqrt n a number is prime if it has exactly two factors 1 and itself is_prime 0 false is_prime 1 false is_prime 2 true is_prime 3 true is_prime 27 false is_prime 87 false is_prime 563 true is_prime 2999 true is_prime 67483 false is_prime 16 1 traceback most recent call last valueerror is_prime only accepts positive integers is_prime 4 traceback most recent call last valueerror is_prime only accepts positive integers precondition 2 and 3 are primes negatives 0 1 all even numbers all multiples of 3 are not primes all primes number are in format of 6k 1
import math
import unittest

import pytest


def is_prime(number: int) -> bool:
    

    
    if not isinstance(number, int) or not number >= 0:
        raise ValueError("is_prime() only accepts positive integers")

    if 1 < number < 4:
        
        return True
    elif number < 2 or number % 2 == 0 or number % 3 == 0:
        
        return False

    
    for i in range(5, int(math.sqrt(number) + 1), 6):
        if number % i == 0 or number % (i + 2) == 0:
            return False
    return True


class Test(unittest.TestCase):
    def test_primes(self):
        assert is_prime(2)
        assert is_prime(3)
        assert is_prime(5)
        assert is_prime(7)
        assert is_prime(11)
        assert is_prime(13)
        assert is_prime(17)
        assert is_prime(19)
        assert is_prime(23)
        assert is_prime(29)

    def test_not_primes(self):
        with pytest.raises(ValueError):
            is_prime(-19)
        assert not is_prime(
            0
        ), "Zero doesn't have any positive factors, primes must have exactly two."
        assert not is_prime(
            1
        ), "One only has 1 positive factor, primes must have exactly two."
        assert not is_prime(2 * 2)
        assert not is_prime(2 * 3)
        assert not is_prime(3 * 3)
        assert not is_prime(3 * 5)
        assert not is_prime(3 * 5 * 7)


if __name__ == "__main__":
    unittest.main()