Skip to content

Commit

Permalink
Reto mouredev#26 - python
Browse files Browse the repository at this point in the history
  • Loading branch information
nlarrea committed Jun 30, 2023
1 parent a47f3ac commit 43eaf63
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions Retos/Reto #26 - TESTING [Media]/python/nlarrea.py
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()

0 comments on commit 43eaf63

Please sign in to comment.