Skip to content

Commit 784b37f

Browse files
committed
#26 - Python
1 parent f4543de commit 784b37f

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
"""
2+
Crea tres test sobre el reto 12: "Viernes 13".
3+
- Puedes copiar una solución ya creada por otro usuario en
4+
el lenguaje que estés utilizando.
5+
- Debes emplear un mecanismo de ejecución de test que posea
6+
el lenguaje de programación que hayas seleccionado.
7+
- Los tres test deben de funcionar y comprobar
8+
diferentes situaciones (a tu elección).
9+
"""
10+
11+
from datetime import date
12+
import unittest
13+
14+
def have_friday_13(year: int, month: int) -> bool:
15+
"""Check if the 13th of a given month/year falls on a Friday.
16+
17+
Args:
18+
year (int): Year to check.
19+
month (int): Month to check (1-12).
20+
21+
Returns:
22+
bool: True if the 13th is Friday, False otherwise.
23+
24+
Raises:
25+
TypeError: If arguments are not integers.
26+
ValueError: If month is not in 1-12.
27+
"""
28+
if not isinstance(year, int) or not isinstance(month, int):
29+
raise TypeError("El año y el mes deben ser enteros.")
30+
if not 1 <= month <= 12:
31+
raise ValueError("El mes debe estar entre 1 y 12.")
32+
33+
return date(year, month, 13).weekday() == 4
34+
35+
class TestHaveFriday13(unittest.TestCase):
36+
"""Unit test suite for the have_friday_13 function.
37+
38+
Tests include:
39+
- Cases where Friday the 13th exists
40+
- Cases where it does not
41+
- Type validation errors
42+
- Month range validation
43+
"""
44+
45+
def test_1(self):
46+
"""Check a month in 2023 that does have a Friday 13th."""
47+
result = have_friday_13(2023, 1)
48+
self.assertTrue(result)
49+
50+
def test_2(self):
51+
"""Check a month in 2023 that does not have a Friday 13th."""
52+
result = have_friday_13(2023, 3)
53+
self.assertFalse(result)
54+
55+
def test_3(self):
56+
"""Ensure TypeError is raised when passing non-integer values."""
57+
with self.assertRaises(TypeError):
58+
have_friday_13("s", "s")
59+
60+
def test_4(self):
61+
"""Ensure ValueError is raised when passing an out-of-range month."""
62+
with self.assertRaises(ValueError):
63+
have_friday_13(2024, 14)
64+
65+
66+
if __name__ == "__main__":
67+
unittest.main()

0 commit comments

Comments
 (0)