This repository has been archived by the owner on Mar 3, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 224
/
Copy pathtests.py
151 lines (128 loc) · 3.92 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# Data
from football_dictionaries.squads_data import SQUADS_DATA
# Assignment 1
from football_dictionaries.assignment_1 import players_as_dictionaries
# Assignment 2
from football_dictionaries.assignment_2 import players_by_position
# Assignment 3
from football_dictionaries.assignment_3 import players_by_country_and_position
# Assignment 1
def test_assignment_1():
result = players_as_dictionaries(SQUADS_DATA)
assert len(result) == 14
assert result[0] == {
'caps': '',
'club': 'Quilmes',
'club_country': 'Argentina',
'country': 'Argentina',
'date_of_birth': '(1908-10-23)23 October 1908 (aged 21)',
'name': 'Juan Botasso',
'number': '1',
'position': 'GK',
'year': '1930'
}
assert result[1] == {
'caps': '',
'club': 'Boca Juniors',
'club_country': 'Argentina',
'country': 'Argentina',
'date_of_birth': '(1907-02-23)23 February 1907 (aged 23)',
'name': 'Roberto Cherro',
'number': '9',
'position': 'FW',
'year': '1930'
}
assert result[-1] == {
'caps': '26',
'club': 'Ulsan Hyundai',
'club_country': 'South Korea',
'country': 'South Korea',
'date_of_birth': '(1988-04-14)14 April 1988 (aged 26)',
'name': 'Kim Shin-Wook',
'number': '-',
'position': 'FW',
'year': '2014'
}
# Assignment 2
def test_assignment_2():
result = players_by_position(SQUADS_DATA)
assert len(result) == 3 # 3 positions
goalkeepers = result['GK']
assert len(goalkeepers) == 2
assert goalkeepers[0] == {
'caps': '',
'club': 'Quilmes',
'club_country': 'Argentina',
'country': 'Argentina',
'date_of_birth': '(1908-10-23)23 October 1908 (aged 21)',
'name': 'Juan Botasso',
'number': '1',
'position': 'GK',
'year': '1930'
}
midfielders = result['MF']
assert len(midfielders) == 8
assert midfielders[0] == {
'caps': '42',
'club': 'Royal Beerschot AC',
'club_country': 'Belgium',
'country': 'Belgium',
'date_of_birth': '(1900-10-26)26 October 1900 (aged 29)',
'name': 'Pierre Braine',
'number': '-',
'position': 'MF',
'year': '1930'
}
forwards = result['FW']
assert len(forwards) == 4
assert forwards[0] == {
'caps': '',
'club': 'Boca Juniors',
'club_country': 'Argentina',
'country': 'Argentina',
'date_of_birth': '(1907-02-23)23 February 1907 (aged 23)',
'name': 'Roberto Cherro',
'number': '9',
'position': 'FW',
'year': '1930'
}
# Assignment 3
def test_assignment_3():
result = players_by_country_and_position(SQUADS_DATA)
assert len(result) == 4
expected_countries = ['Argentina', 'Belgium', 'Brazil', 'South Korea']
assert list(result.keys()) == expected_countries
# Argentina
argentina = result['Argentina']
assert len(argentina) == 2
ar_goalkeepers = argentina['GK']
ar_forwards = argentina['FW']
assert len(ar_goalkeepers) == 1
assert len(ar_forwards) == 1
# Brazil
brazil = result['Brazil']
assert len(brazil) == 1 # Only midfielders
br_midfielders = brazil['MF']
assert len(br_midfielders) == 6
assert br_midfielders[0] == {
'caps': '29',
'club': 'Chelsea',
'club_country': 'England',
'country': 'Brazil',
'date_of_birth': '(1991-09-09)9 September 1991 (aged 22)',
'name': 'Oscar',
'number': '-',
'position': 'MF',
'year': '2010'
}
assert br_midfielders[-1] == {
'caps': '5',
'club': 'Chelsea',
'club_country': 'England',
'country': 'Brazil',
'date_of_birth': '(1988-08-09)9 August 1988 (aged 25)',
'name': 'Willian',
'number': '-',
'position': 'MF',
'year': '2014'
}