File tree Expand file tree Collapse file tree 3 files changed +44
-3
lines changed Expand file tree Collapse file tree 3 files changed +44
-3
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,4 @@ public int getPosition() {
2020 return position ;
2121 }
2222
23- public String getPositionAsString (){
24- return "-" .repeat (position );
25- }
2623}
Original file line number Diff line number Diff line change 1+ import java .util .ArrayList ;
2+ import java .util .List ;
3+
4+ public class Winners {
5+ public static List <String > findWinnersNames (List <Car > cars ){
6+ List <String > winners = new ArrayList <>();
7+ for (int i = 0 ; i < cars .size (); i ++){
8+ if (cars .get (i ).getPosition () >= 5 ){
9+ winners .add (cars .get (i ).getCarName ());
10+ }
11+ }
12+ return winners ;
13+ }
14+ }
Original file line number Diff line number Diff line change 1+ import org .junit .jupiter .api .DisplayName ;
2+ import org .junit .jupiter .api .Test ;
3+
4+ import java .util .List ;
5+
6+ import static org .assertj .core .api .Assertions .assertThat ;
7+
8+ public class WinnersTest {
9+ @ Test
10+ @ DisplayName ("우승자(들) 이름을 반환한다" )
11+ void returnWinnerNames (){
12+ Car carA = new Car ("Car A" );
13+ Car carB = new Car ("Car B" );
14+ Car carC = new Car ("Car C" );
15+
16+ for (int i = 0 ; i < 5 ; i ++){
17+ carA .move (()->true );
18+ }
19+
20+ for (int i = 0 ; i < 4 ; i ++){
21+ carB .move (()->true );
22+ }
23+ for (int i = 0 ; i < 5 ; i ++){
24+ carC .move (()->true );
25+ }
26+
27+ List <Car > cars = List .of (carA , carB , carC );
28+ assertThat (Winners .findWinnersNames (cars )).containsExactlyInAnyOrder ("Car A" ,"Car C" );
29+ }
30+ }
You can’t perform that action at this time.
0 commit comments