Skip to content

Commit 3fe6986

Browse files
author
boraxpr
committed
submission Bite 180 @ codechalleng.es
1 parent e1d9847 commit 3fe6986

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed

180/names.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from collections import defaultdict
2+
3+
# fake data from https://www.mockaroo.com
4+
data = """last_name,first_name,country_code
5+
Watsham,Husain,ID
6+
Harrold,Alphonso,BR
7+
Apdell,Margo,CN
8+
Tomblings,Deerdre,RU
9+
Wasielewski,Sula,ID
10+
Jeffry,Rudolph,TD
11+
Brenston,Luke,SE
12+
Parrett,Ines,CN
13+
Braunle,Kermit,PL
14+
Halbard,Davie,CN"""
15+
16+
17+
def group_names_by_country(data: str = data) -> defaultdict:
18+
countries = defaultdict(list)
19+
# you code
20+
sorted(countries.items())
21+
return countries
22+
23+
24+
# x = group_names_by_country(data)
25+
# print(x)

180/test_names.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
from collections import defaultdict
2+
3+
import pytest
4+
5+
from names import group_names_by_country, data
6+
7+
# another output to test with
8+
data2 = """last_name,first_name,country_code
9+
Poxton,Sydney,CZ
10+
Kynman,Bryant,NL
11+
Mockler,Leese,AF
12+
Gillicuddy,Raffaello,IR
13+
Renyard,Carlo,CO
14+
Beadham,Evonne,CZ
15+
Tunstall,Allissa,IR
16+
Kamenar,Augy,IR
17+
Insko,Ave,NL
18+
Pigney,Gavrielle,ID"""
19+
20+
21+
@pytest.fixture
22+
def grouping1():
23+
return group_names_by_country(data)
24+
25+
26+
@pytest.fixture
27+
def grouping2():
28+
return group_names_by_country(data2)
29+
30+
31+
def test_return_type(grouping1, grouping2):
32+
assert type(grouping1) == defaultdict
33+
assert type(grouping2) == defaultdict
34+
35+
36+
def test_return_dict_len(grouping1, grouping2):
37+
assert len(grouping1) == 7
38+
assert len(grouping2) == 6
39+
40+
41+
@pytest.mark.parametrize('key, expected', [
42+
('BR', ['Alphonso Harrold']),
43+
('CN', ['Davie Halbard', 'Ines Parrett', 'Margo Apdell']),
44+
('ID', ['Husain Watsham', 'Sula Wasielewski']),
45+
('PL', ['Kermit Braunle']),
46+
('RU', ['Deerdre Tomblings']),
47+
('SE', ['Luke Brenston']),
48+
('TD', ['Rudolph Jeffry']),
49+
])
50+
def test_grouping1_return(grouping1, key, expected):
51+
assert sorted(grouping1[key]) == expected
52+
53+
54+
@pytest.mark.parametrize('key, expected', [
55+
('AF', ['Leese Mockler']),
56+
('CO', ['Carlo Renyard']),
57+
('CZ', ['Evonne Beadham', 'Sydney Poxton']),
58+
('ID', ['Gavrielle Pigney']),
59+
('IR', ['Allissa Tunstall', 'Augy Kamenar', 'Raffaello Gillicuddy']),
60+
('NL', ['Ave Insko', 'Bryant Kynman']),
61+
])
62+
def test_grouping2_return(grouping2, key, expected):
63+
assert sorted(grouping2[key]) == expected
64+
65+
test_grouping1_return
66+
test_grouping2_return

0 commit comments

Comments
 (0)