From 44dc7506272e3502ca6c0dacd2cb8c170e07fe91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn?= Date: Sat, 29 Aug 2020 15:42:44 +0200 Subject: [PATCH 1/2] Added type hints and doctest for maths/prime_check. --- maths/prime_check.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/maths/prime_check.py b/maths/prime_check.py index e60281228fda..91b0e95961e8 100644 --- a/maths/prime_check.py +++ b/maths/prime_check.py @@ -4,11 +4,17 @@ import unittest -def prime_check(number): +def prime_check(number: int) -> bool: """ Check to See if a Number is Prime. A number is prime if it has exactly two dividers: 1 and itself. + >>> prime_check(3) + True + >>> prime_check(-1) + False + >>> prime_check(2*21) + False """ if number < 2: # Negatives, 0 and 1 are not primes @@ -42,7 +48,7 @@ def test_primes(self): def test_not_primes(self): self.assertFalse(prime_check(-19), "Negative numbers are not prime.") self.assertFalse( - prime_check(0), "Zero doesn't have any divider, primes must have two" + prime_check(0), "Zero doesn't have any divider, primes must have two." ) self.assertFalse( prime_check(1), "One just have 1 divider, primes must have two." @@ -56,3 +62,6 @@ def test_not_primes(self): if __name__ == "__main__": unittest.main() + + import doctest + doctest.testmod() From 057aedafe404d944fc41aab88aa584e5650e807a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn?= Date: Sat, 29 Aug 2020 16:58:52 +0200 Subject: [PATCH 2/2] Removed doctests. --- maths/prime_check.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/maths/prime_check.py b/maths/prime_check.py index 91b0e95961e8..ed8fbbae809a 100644 --- a/maths/prime_check.py +++ b/maths/prime_check.py @@ -9,12 +9,6 @@ def prime_check(number: int) -> bool: Check to See if a Number is Prime. A number is prime if it has exactly two dividers: 1 and itself. - >>> prime_check(3) - True - >>> prime_check(-1) - False - >>> prime_check(2*21) - False """ if number < 2: # Negatives, 0 and 1 are not primes @@ -62,6 +56,3 @@ def test_not_primes(self): if __name__ == "__main__": unittest.main() - - import doctest - doctest.testmod()