diff --git a/.vscode/settings.json b/.vscode/settings.json index 252022b48..49df4cc6f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -122,5 +122,8 @@ "source.fixAll.ruff": "explicit", "source.organizeImports.ruff": "explicit" } - } + }, + "python.analysis.extraPaths": [ + "./solutions/tests/test_" + ] } diff --git a/solutions/__init__.py b/solutions/check_odd_even_17/__init__.py similarity index 100% rename from solutions/__init__.py rename to solutions/check_odd_even_17/__init__.py diff --git a/solutions/check_odd_even_17/check_odd_even.py b/solutions/check_odd_even_17/check_odd_even.py new file mode 100644 index 000000000..b8059492f --- /dev/null +++ b/solutions/check_odd_even_17/check_odd_even.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +"""This module contains a function to identify if a number is even or odd.""" + + +def check_odd_even(number): + """Check if the number is odd or even.""" + if number % 2 == 0: + return "even_number" + + return "odd_number" + + +if __name__ == "__main__": + try: + num = int(input("Enter an integer: ")) + RESULT = check_odd_even(num) + print(f"The number {num} is {RESULT}.") + except ValueError: + print("Invalid input. Please enter an integer.") diff --git a/solutions/tests/test_check_odd_even.py b/solutions/tests/test_check_odd_even.py new file mode 100644 index 000000000..be01fde7b --- /dev/null +++ b/solutions/tests/test_check_odd_even.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +"""This module contains the tests for the check_odd_even function.""" + +import unittest +from solutions.check_odd_even_17.check_odd_even import check_odd_even + + +class TestOddOrEven(unittest.TestCase): + """Test cases for the check_odd_or_even function.""" + + def test_even_numbers(self): + """the test for even numbers""" + self.assertEqual(check_odd_even(2), "even_number") + self.assertEqual(check_odd_even(1000000), "even_number") + self.assertEqual(check_odd_even(0), "even_number") + + def test_odd_numbers(self): + """the test for odd numbers""" + self.assertEqual(check_odd_even(5), "odd_number") + self.assertEqual(check_odd_even(500001), "odd_number") + self.assertEqual(check_odd_even(-1), "odd_number") + + def test_edge_cases(self): + """with edge cases""" + self.assertEqual(check_odd_even(0), "even_number") + self.assertEqual(check_odd_even(1), "odd_number") + self.assertEqual(check_odd_even(-1), "odd_number") + + def test_large_integers(self): + """the test for large integers""" + self.assertEqual(check_odd_even(200000), "even_number") + self.assertEqual(check_odd_even(500000), "even_number") + self.assertEqual(check_odd_even(1000000), "even_number")