Skip to content

Commit 46ed4ed

Browse files
committed
#13 - python
1 parent 697e569 commit 46ed4ed

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import unittest
2+
from datetime import datetime, date
3+
4+
"""
5+
Ejercicio
6+
"""
7+
8+
9+
def sum(a, b):
10+
if not isinstance(a, (int, float)) or not isinstance(b, (int, float)):
11+
return ValueError("Los argumentos deben de ser enteros o decimales.")
12+
return a + b
13+
14+
15+
class TestSum(unittest.TestCase):
16+
17+
def test_sum(self):
18+
self.assertEqual(sum(5, 7), 12)
19+
self.assertEqual(sum(5, -7), -2)
20+
self.assertEqual(sum(0, 0), 0)
21+
self.assertEqual(sum(5.1, 7.1), 12.2)
22+
23+
def test_sum_type(self):
24+
with self.assertRaises(ValueError):
25+
sum("5", 7)
26+
with self.assertRaises(ValueError):
27+
sum(5, "7")
28+
with self.assertRaises(ValueError):
29+
sum("5", "7")
30+
31+
32+
#EJERCIICO EXTRA
33+
dicc = {
34+
"name": "Victor",
35+
"age": 21,
36+
"birth_date": "06-09-2003",
37+
"programming_languages": ["Python", "Java", "C"]
38+
}
39+
40+
class TestSum(unittest.TestCase):
41+
42+
def test_all_param(self):
43+
self.assertIn("name", dicc)
44+
self.assertIn("age", dicc)
45+
self.assertIn("birth_date", dicc)
46+
self.assertIn("programming_languages", dicc)
47+
48+
def test_correct_data(self):
49+
self.assertIsInstance(dicc["name"], str)
50+
self.assertIsInstance(dicc["age"], int)
51+
self.assertIsInstance(dicc["birth_date"], str)
52+
self.assertIsInstance(dicc["programming_languages"], list)
53+
54+
unittest.main()

0 commit comments

Comments
 (0)