Skip to content

Commit 6006b69

Browse files
committed
#13 - PYTHON
1 parent 6303063 commit 6006b69

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import pytest
2+
3+
"""EJERCICIO"""
4+
5+
6+
def sum_two_numbers(num1: int, num2: int) -> int:
7+
if isinstance(num1, int) & isinstance(num2, int):
8+
return num1 + num2
9+
raise ValueError("Numbers have to be integers.")
10+
11+
12+
class TestSum:
13+
@pytest.mark.parametrize("num1,num2,expected", [
14+
(0, 1, 1),
15+
(5, 5, 10),
16+
(3, -1, 2)
17+
])
18+
def test_sum_two_numbers(self, num1, num2, expected):
19+
assert sum_two_numbers(num1, num2) == expected
20+
21+
def test_raises_value_error(self):
22+
with pytest.raises(ValueError):
23+
sum_two_numbers("", 3)
24+
25+
26+
"""DIFICULTAD EXTRA"""
27+
28+
data = {
29+
'name': 'anna',
30+
'age': 36,
31+
'birth_date': "13 de octubre",
32+
'programming_languages': ['Python', 'Kotlin']
33+
}
34+
35+
36+
class TestDictionary:
37+
def test_all_keys_exist(self):
38+
# using set instead of list so the order doesn't matter
39+
keys = {'name', 'age', 'birth_date', 'programming_languages'}
40+
assert set(data.keys()) == keys
41+
42+
def test_values_are_correct(self):
43+
values = ['anna', 36, '13 de octubre', ['Python', 'Kotlin']]
44+
assert list(data.values()) == values

0 commit comments

Comments
 (0)