forked from mouredev/retos-programacion-2023
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
1 changed file
with
50 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
""" | ||
* Crea tres test sobre el reto 12: "Viernes 13". | ||
* - Puedes copiar una solución ya creada por otro usuario en | ||
* el lenguaje que estés utilizando. | ||
* - Debes emplear un mecanismo de ejecución de test que posea | ||
* el lenguaje de programación que hayas seleccionado. | ||
* - Los tres test deben de funcionar y comprobar | ||
* diferentes situaciones (a tu elección). | ||
""" | ||
|
||
import unittest | ||
from datetime import datetime | ||
|
||
|
||
def is_friday_thirteen(month, year): | ||
if not isinstance(month, int) or not isinstance(year, int): | ||
assert TypeError("Invalid month or year. Use integer numbers.") | ||
|
||
if month < 1 or month > 12: | ||
return "Month is out of range." | ||
|
||
date = datetime(year, month, 13) | ||
return date.weekday() == 4 | ||
|
||
|
||
class TestReto12(unittest.TestCase): | ||
def test_number_month(self): | ||
is_friday_13th = is_friday_thirteen(1, 2023) | ||
self.assertTrue(is_friday_13th) | ||
|
||
is_friday_13th = is_friday_thirteen(3, 2022) | ||
self.assertFalse(is_friday_13th) | ||
|
||
def test_month_out_of_range(self): | ||
is_friday_13th = is_friday_thirteen(14, 2023) | ||
self.assertEqual(is_friday_13th, "Month is out of range.") | ||
|
||
is_friday_13th = is_friday_thirteen(-1, 2023) | ||
self.assertEqual(is_friday_13th, "Month is out of range.") | ||
|
||
def test_not_numeric_values(self): | ||
with self.assertRaises(TypeError): | ||
is_friday_thirteen("6", 1998) | ||
|
||
with self.assertRaises(TypeError): | ||
is_friday_thirteen(6, "1998") | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |