|
4 | 4 | def test(): |
5 | 5 | directors = get_movies_by_director() |
6 | 6 |
|
7 | | - assert 'Sergio Leone' in directors |
8 | | - assert 'Andrew Stanton' in directors # has 3 movies, but not yet filtered |
9 | | - assert len(directors['Sergio Leone']) == 4 |
10 | | - assert len(directors['Peter Jackson']) == 12 |
| 7 | + assert "Sergio Leone" in directors |
| 8 | + assert "Andrew Stanton" in directors # has 3 movies, but not yet filtered |
| 9 | + assert len(directors["Sergio Leone"]) == 4 |
| 10 | + assert len(directors["Peter Jackson"]) == 12 |
11 | 11 |
|
12 | | - movies_sergio = directors['Sergio Leone'] |
13 | | - movies_nolan = directors['Christopher Nolan'] |
| 12 | + movies_sergio = directors["Sergio Leone"] |
| 13 | + movies_nolan = directors["Christopher Nolan"] |
14 | 14 | assert _calc_mean(movies_sergio) == 8.5 |
15 | 15 | assert _calc_mean(movies_nolan) == 8.4 |
16 | 16 |
|
17 | 17 | directors = get_average_scores(directors) |
18 | | - assert 'Andrew Stanton' not in directors # director 3 movies now filtered out |
19 | | - |
20 | | - expected_directors = ['Sergio Leone', 'Christopher Nolan', 'Quentin Tarantino', |
21 | | - 'Hayao Miyazaki', 'Frank Darabont', 'Stanley Kubrick'] |
| 18 | + assert "Andrew Stanton" not in directors # director 3 movies now filtered out |
| 19 | + |
| 20 | + expected_directors = [ |
| 21 | + "Sergio Leone", |
| 22 | + "Christopher Nolan", |
| 23 | + "Quentin Tarantino", |
| 24 | + "Hayao Miyazaki", |
| 25 | + "Frank Darabont", |
| 26 | + "Stanley Kubrick", |
| 27 | + ] |
22 | 28 | expected_avg_scores = [8.5, 8.4, 8.2, 8.2, 8.0, 8.0] |
23 | 29 | expected_num_movies = [4, 8, 8, 4, 4, 7] |
24 | | - report = sorted(directors.items(), key=lambda x: float(x[0][1]), reverse=True) |
| 30 | + report = sorted(directors.items(), key=lambda x: float(x[1][0]), reverse=True) |
25 | 31 | for counter, (i, j, k) in enumerate( |
26 | | - zip(expected_directors, |
27 | | - expected_avg_scores, expected_num_movies)): |
28 | | - assert report[counter][0] == (i, j) |
29 | | - assert len(report[counter][1]) == k |
30 | | - assert _calc_mean(report[counter][1]) == j |
| 32 | + zip(expected_directors, expected_avg_scores, expected_num_movies) |
| 33 | + ): |
| 34 | + assert report[counter][0], [counter][1][0] == (i, j) |
| 35 | + assert len(report[counter][1][1]) == k |
| 36 | + assert _calc_mean(report[counter][1][1]) == j |
31 | 37 |
|
32 | 38 | return "tests pass" |
33 | 39 |
|
34 | 40 |
|
35 | | -if __name__ == '__main__': |
| 41 | +if __name__ == "__main__": |
36 | 42 | print(test()) |
0 commit comments