Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is prime #80

Merged
merged 3 commits into from
Jan 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions solutions/IsPrime.py → solutions/is_prime.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
A module for finding if an integer is prime.
Module for finding if an integer is prime.

Module contents:
- IsPrime: finds if an integer is prime.
- is_prime: finds if an integer is prime.

Created on XX XX XX
@author: Mohammed Elfadil
"""


def IsPrime(a: int) -> str:
def is_prime(a: int) -> str:
"""Checks if an integer is prime.
Parameter:
a: int
Return -> str: whether a is prime or not
Raises:
AssertionError: if the argument is not an integer
>>> IsPrime(0)
>>> is_prime(0)
not prime
>>> IsPrime(1)
>>> is_prime(1)
not prime
>>> IsPrime(2)
>>> is_prime(2)
prime
>>> IsPrime(4)
>>> is_prime(4)
not prime
>>> IsPrime(7)
>>> is_prime(7)
prime
>>> IsPrime(2.5)
>>> is_prime(2.5)
invalid input
>>> IsPrime(-1)
>>> is_prime(-1)
not prime
"""
if not isinstance(a, int):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,67 +1,67 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import unittest
from solutions.IsPrime import IsPrime
from solutions.is_prime import is_prime


class TestIsPrime(unittest.TestCase):
"""test the IsPrime function"""
"""test the is_prime function"""

def test_0(self):
"""It should evaluate not prime"""
actual = IsPrime(0)
actual = is_prime(0)
expected = "not prime"
self.assertEqual(actual, expected)

def test_1(self):
"""It should evaluate not prime"""
actual = IsPrime(1)
actual = is_prime(1)
expected = "not prime"
self.assertEqual(actual, expected)

def test_2(self):
actual = IsPrime(2)
actual = is_prime(2)
expected = "prime"
self.assertEqual(actual, expected)

def test_4(self):
"""its should evaluate not prime"""
actual = IsPrime(4)
actual = is_prime(4)
expected = "not prime"
self.assertEqual(actual, expected)

def test_7(self):
"""It should evaluate prime"""
actual = IsPrime(7)
actual = is_prime(7)
expected = "prime"
self.assertEqual(actual, expected)

def test_9(self):
"""It should evaluate not prime"""
actual = IsPrime(9)
actual = is_prime(9)
expected = "not prime"
self.assertEqual(actual, expected)

def test_11(self):
"""It should evaluate prime"""
actual = IsPrime(11)
actual = is_prime(11)
expected = "prime"
self.assertEqual(actual, expected)

def test_13(self):
"""It should evaluate prime"""
actual = IsPrime(13)
actual = is_prime(13)
expected = "prime"
self.assertEqual(actual, expected)

def test_negative(self):
"""It should evaluate not prime"""
actual = IsPrime(-1)
actual = is_prime(-1)
expected = "not prime"
self.assertEqual(actual, expected)

def test_not_integer(self):
"""It should evaluate not prime"""
actual = IsPrime(1.5)
actual = is_prime(1.5)
expected = "invalid input"
self.assertEqual(actual, expected)
Loading