diff --git a/maths/primelib.py b/maths/primelib.py index cf01750cf912..92ebb5006627 100644 --- a/maths/primelib.py +++ b/maths/primelib.py @@ -38,7 +38,7 @@ """ from math import sqrt - +import doctest from maths.greatest_common_divisor import gcd_by_iterative @@ -46,6 +46,15 @@ def is_prime(number: int) -> bool: """ input: positive integer 'number' returns true if 'number' is prime otherwise false. + + >>> is_prime(97) + True + >>> is_prime(9991) + False + >>> is_prime(-3) + Traceback (most recent call last): + ... + AssertionError: 'number' must been an int and positive """ # precondition @@ -589,3 +598,7 @@ def fib(n): fib1 = tmp return ans + + +if __name__ == "__main__": + doctest.testmod()