forked from MIT-Emerging-Talent/ET6-practice-code-review
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from MIT-Emerging-Talent/check_odd_even
Check odd and even
- Loading branch information
Showing
4 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |