Skip to content

Commit f0f6f75

Browse files
authored
Merge pull request #1 from annaviper/13-pruebas-unitarias
#13 - Python, Kotlin
2 parents 6303063 + 2f45ae4 commit f0f6f75

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package main
2+
3+
import org.testng.AssertJUnit.assertEquals
4+
import org.testng.annotations.Test
5+
6+
/*
7+
* SUM
8+
*/
9+
10+
fun sum(num1: Int, num2: Int): Int {
11+
return num1 + num2
12+
}
13+
14+
class SumTest {
15+
@Test
16+
fun testSum() {
17+
assertEquals(42, sum(40, 2))
18+
}
19+
}
20+
21+
22+
/*
23+
* DICTIONARY
24+
* */
25+
26+
val data = mapOf(
27+
"name" to "Anna",
28+
"age" to "36",
29+
"birth_date" to "13 de octubre",
30+
"programming_languages" to listOf("Python", "Kotlin")
31+
)
32+
33+
class DictionaryTest {
34+
@Test
35+
fun testAllKeysExist() {
36+
val correctKeys = setOf("name", "age", "birth_date", "programming_languages")
37+
assertEquals(data.keys, correctKeys)
38+
}
39+
}
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)