From 43eaf636795bbe6e27121c9f56250aa464ce474b Mon Sep 17 00:00:00 2001 From: nlarrea Date: Fri, 30 Jun 2023 13:30:22 +0200 Subject: [PATCH] Reto #26 - python --- .../python/nlarrea.py | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Retos/Reto #26 - TESTING [Media]/python/nlarrea.py diff --git a/Retos/Reto #26 - TESTING [Media]/python/nlarrea.py b/Retos/Reto #26 - TESTING [Media]/python/nlarrea.py new file mode 100644 index 0000000000..5e27a33005 --- /dev/null +++ b/Retos/Reto #26 - TESTING [Media]/python/nlarrea.py @@ -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() \ No newline at end of file