File tree Expand file tree Collapse file tree
programmers/python/해시/완주하지_못한_선수 Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ from collections import Counter
2+ from typing import List
3+
4+
5+ def solution (participant : List [str ], completion : List [str ]) -> str :
6+ counter = Counter (participant )
7+
8+ for name in completion :
9+ counter [name ] -= 1
10+
11+ return counter .most_common ()[0 ][0 ]
Original file line number Diff line number Diff line change 1+ [
2+ {
3+ "params" : [
4+ [
5+ " leo" ,
6+ " kiki" ,
7+ " eden"
8+ ],
9+ [
10+ " eden" ,
11+ " kiki"
12+ ]
13+ ],
14+ "expected" : " leo"
15+ },
16+ {
17+ "params" : [
18+ [
19+ " marina" ,
20+ " josipa" ,
21+ " nikola" ,
22+ " vinko" ,
23+ " filipa"
24+ ],
25+ [
26+ " josipa" ,
27+ " filipa" ,
28+ " marina" ,
29+ " nikola"
30+ ]
31+ ],
32+ "expected" : " vinko"
33+ },
34+ {
35+ "params" : [
36+ [
37+ " mislav" ,
38+ " stanko" ,
39+ " mislav" ,
40+ " ana"
41+ ],
42+ [
43+ " stanko" ,
44+ " ana" ,
45+ " mislav"
46+ ]
47+ ],
48+ "expected" : " mislav"
49+ }
50+ ]
Original file line number Diff line number Diff line change 1+ import json
2+ import os
3+ import unittest
4+
5+ from parameterized import parameterized
6+
7+ from .main import solution
8+
9+
10+ def load_sample (filename : str ):
11+ path = os .path .join (os .path .dirname (os .path .abspath (__file__ )), filename )
12+
13+ with open (path , "r" ) as file :
14+ return [(case ["params" ], case ["expected" ]) for case in json .load (file )]
15+
16+
17+ class TestCase (unittest .TestCase ):
18+ @parameterized .expand (load_sample ("sample.json" ))
19+ def test_case (self , params : list , expected : any ):
20+ # When
21+ result = solution (* params )
22+
23+ # Then
24+ self .assertEqual (expected , result )
25+
26+
27+ if __name__ == "__main__" :
28+ unittest .main ()
You can’t perform that action at this time.
0 commit comments