Skip to content

Commit

Permalink
Merge pull request #32 from MIT-Emerging-Talent/check_odd_even
Browse files Browse the repository at this point in the history
Check odd and even
  • Loading branch information
KHserv-Creator authored Jan 12, 2025
2 parents 4fd0f43 + 8cb29d1 commit b48485c
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,8 @@
"source.fixAll.ruff": "explicit",
"source.organizeImports.ruff": "explicit"
}
}
},
"python.analysis.extraPaths": [
"./solutions/tests/test_"
]
}
File renamed without changes.
20 changes: 20 additions & 0 deletions solutions/check_odd_even_17/check_odd_even.py
Original file line number Diff line number Diff line change
@@ -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.")
34 changes: 34 additions & 0 deletions solutions/tests/test_check_odd_even.py
Original file line number Diff line number Diff line change
@@ -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")

0 comments on commit b48485c

Please sign in to comment.