-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Javier Pinilla
authored and
Javier Pinilla
committed
Jun 28, 2023
1 parent
34b6424
commit d4c3be2
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
Retos/Reto #26 - TESTING [Media]/python/ingjavierpinilla.py
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,56 @@ | ||
import unittest | ||
from datetime import datetime | ||
|
||
|
||
def has_friday_13(year: int, month: int) -> bool: | ||
"""Esta funcion retorna verdadero si para un año y mes dado existe un viernes 13 | ||
Args: | ||
year (int): | ||
month (int): | ||
Returns: | ||
bool: | ||
""" | ||
if not isinstance(year, int): | ||
raise TypeError("Year invalid, enter a valid integer number") | ||
if not isinstance(month, int): | ||
raise TypeError("Month invalid, enter a valid integer number") | ||
|
||
return datetime(year, month, 13).weekday() == 4 | ||
|
||
|
||
class TestIsFriday13(unittest.TestCase): | ||
def setUp(self): | ||
self.is_friday_13 = {"year": 2023, "month": 10} | ||
self.not_friday_13 = {"year": 2023, "month": 7} | ||
|
||
def test_invalid_year(self): | ||
with self.assertRaises(TypeError): | ||
has_friday_13(year="1520", month=7) | ||
|
||
def test_invalid_month(self): | ||
with self.assertRaises(TypeError): | ||
has_friday_13(year=1520, month=(1520, 1)) | ||
|
||
def test_expected_return(self): | ||
self.assertIsInstance(has_friday_13(year=1520, month=7), bool) | ||
|
||
def test_valid_friday_13(self): | ||
self.assertIs( | ||
has_friday_13( | ||
year=self.is_friday_13["year"], month=self.is_friday_13["month"] | ||
), | ||
True, | ||
) | ||
|
||
def test_invalid_friday_13(self): | ||
self.assertIsNot( | ||
has_friday_13( | ||
year=self.not_friday_13["year"], month=self.not_friday_13["month"] | ||
), | ||
True, | ||
) | ||
|
||
if __name__ == "__main__": | ||
unittest.main() |