Skip to content

Commit

Permalink
refactor(Car): Car 에서 직접 우승 여부를 처리하도록 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
hw0603 committed Feb 17, 2024
1 parent 1c30133 commit 6481876
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/main/java/racingcar/model/Car.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,12 @@ public void move(int randomNumber) {
position++;
}
}

public boolean isMoved() {
return position > 0;
}

public boolean isSamePosition(int position) {
return this.position == position;
}
}
2 changes: 1 addition & 1 deletion src/main/java/racingcar/model/CarGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void race() {
public List<Car> findWinners() {
int maxPosition = findMaxPosition();
return cars.stream()
.filter((car -> car.getPosition() > 0 && car.getPosition() == maxPosition))
.filter((car -> car.isMoved() && car.isSamePosition(maxPosition)))
.toList();
}

Expand Down

0 comments on commit 6481876

Please sign in to comment.