Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Step4 carracing #5541

Merged
merged 21 commits into from
Apr 18, 2024
Merged
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
42287c7
step1 squash
rkaehdaos Apr 17, 2024
3351eca
step2 squash
rkaehdaos Apr 17, 2024
d059c8e
step3 squash
rkaehdaos Apr 17, 2024
51b02c6
docs(README): STEP4 README.md 작성
rkaehdaos Apr 17, 2024
5ca13e3
feat(car): Move, getDistance 구현
rkaehdaos Apr 17, 2024
37c02f1
feat(car): name 필드
rkaehdaos Apr 17, 2024
9dd8bb2
feat(car): Car 구현 완료 및 정리
rkaehdaos Apr 17, 2024
64c8765
feat(Race): Race 생성자 및 getter 처리
rkaehdaos Apr 17, 2024
ed667b4
feat(Race): Race runRound
rkaehdaos Apr 17, 2024
cac66cb
feat(Input): Input 구현
rkaehdaos Apr 17, 2024
cc64200
feat(result): 자동차 이름과 함께 움직임 출력
rkaehdaos Apr 17, 2024
fb6ca7d
feat(result): 최종 우승자 출력: 1명 이상 일 수 있음
rkaehdaos Apr 17, 2024
01771dc
feat(result): result 구현 완료
rkaehdaos Apr 17, 2024
3641b3f
check: UI를 InputView, ResultView로 분리
rkaehdaos Apr 17, 2024
82312d2
메서드가 15라인을 넘어가지 않도록 구현
rkaehdaos Apr 17, 2024
96082e8
Step4 - 단일 책임원칙 확인
rkaehdaos Apr 17, 2024
04ab98c
Merge remote-tracking branch 'origin/step4_carracing' into step4_carr…
rkaehdaos Apr 17, 2024
d655ebe
Merge branch 'rkaehdaos' into step4_carracing
rkaehdaos Apr 17, 2024
8f9e43a
Merge branch 'rkaehdaos' into step4_carracing
rkaehdaos Apr 17, 2024
6ab6e1b
Merge remote-tracking branch 'origin/step4_carracing' into step4_carr…
rkaehdaos Apr 17, 2024
3a88c8d
conflict 해결 및 전략 패턴 적용 (#4)
rkaehdaos Apr 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat(Race): Race runRound
- 이전 study test depreacated 주석처리
rkaehdaos committed Apr 17, 2024
commit ed667b4862c62926355073082f52dd8ba92909f4
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@
- [] Race 구현
- [x] Race 생성자 : 자동차들 list 준비,
- [x] 자동차 리스트 가져오기: `@getter` 처리
- [ ] Race runRound
- [x] Race runRound

- [ ] Input 구현
- [ ] 자동차 이름 입력
10 changes: 6 additions & 4 deletions src/main/java/step4_winner/Race.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
package step4_winner;

import lombok.Getter;

import java.util.List;
import java.util.Random;

public class Race {
private final Random random= new Random();
@Getter private final List<Car> cars;
private final Random random = new Random();
private final List<Car> cars;

public Race(List<Car> cars) {
if (cars.isEmpty())
throw new IllegalArgumentException("0이상이어야 함");
this.cars=cars;
this.cars = cars;
}

public void runRound() {
cars.forEach(car -> car.move(random.nextInt(10)));
}
}
22 changes: 21 additions & 1 deletion src/test/java/step4_winner/RaceTest.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package step4_winner;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.RepeatedTest;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import static org.assertj.core.api.Assertions.*;

@@ -13,7 +16,7 @@ class RaceTest {

@Test
@DisplayName("레이스에는 1대 이상의 차가 필요하다.")
void raceMustPositiveCars(){
void raceMustPositiveCars() {
// GIVEN empty list
List<Car> cars = new ArrayList<>();
// WHEN create
@@ -31,4 +34,21 @@ void raceMustPositiveCars(){
assertThat(legalRace).isNotNull();
}

@RepeatedTest(1000)
@DisplayName("100개의 차가 참가한 race가 일단 열리면, 100대중 1개는 전진 한다")
public void RaceRoundTest() {
// GIVEN
List<Car> cars = IntStream.range(0, 100)
.mapToObj(i -> new Car("c_" + (++i)))
.collect(Collectors.toList());
Race race = new Race(cars);

// WHEN
race.runRound();

// then
boolean anyCarMoved = cars.stream().anyMatch(car -> car.getDistance() > 1);
assertThat(anyCarMoved).isTrue();
}

}
2 changes: 1 addition & 1 deletion src/test/java/study/AssertJTest.java
Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@ protected Dog(String name, Float weight) {

// 재귀적 필드 비교 -> 성공
// deprecated
assertThat(fido).isEqualToComparingFieldByFieldRecursively(fidosClone);
// assertThat(fido).isEqualToComparingFieldByFieldRecursively(fidosClone);

// 위를 대체할 수 있는 새로운 메서드
// 더 많은 유연성과 더 나은 REPORT, 더 쉬운 사용법