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

Step5 #5836

Open
wants to merge 20 commits into
base: sweet-info
Choose a base branch
from
Open

Step5 #5836

Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 9 additions & 0 deletions src/main/java/racing/RacingApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package racing;

import racing.controller.CarRacingController;

public class RacingApplication {
public static void main(String[] args) {
CarRacingController.main(args);
}
}
1 change: 1 addition & 0 deletions src/main/java/racing/controller/CarRacingController.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ public static void main(String[] args) {
}
resultView.findWinners(cars.findWinners());
}

}
5 changes: 4 additions & 1 deletion src/main/java/racing/entity/CarName.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ public class CarName {

public CarName(String value) {
if (value == null || value.isEmpty()) {
throw new IllegalArgumentException("Car name cannot be null or empty.");
throw new IllegalArgumentException("cannot be null or empty.");
}
if (value.length() > 5) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5와 같은 숫자 리터럴은 상수로 선언하여 의미를 부여해보면 어떨까요?

throw new IllegalArgumentException("cannot be longer than 5 characters.");
}
this.value = value;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/racing/entity/Position.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ public int getValue() {
public Position movePosition() {
return new Position(value + 1);
}
}
}
1 change: 0 additions & 1 deletion src/main/java/racing/service/Cars.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,3 @@ public List<Car> findWinners() {
.filter(car -> car.isPosition(maxPosition))
.collect(Collectors.toList());
}
}
1 change: 1 addition & 0 deletions src/main/java/racing/view/InputView.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public List<Car> inputCar() {
return cars;
}


public int inputNumber() {
System.out.println("시도할 횟수를 입력하세요 : ");
return scanner.nextInt();
Expand Down
Empty file removed src/test/java/.gitkeep
Empty file.
26 changes: 26 additions & 0 deletions src/test/java/racing/CarNameTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package racing;

import org.junit.jupiter.api.Test;
import racing.entity.CarName;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

public class CarNameTest {

@Test
void carNameIsSetCorrectly() {
CarName carName = new CarName("Car");
assertEquals("Car", carName.getValue());
}

@Test
void carNameCannotBeNull() {
Comment on lines +17 to +18
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NullAndEmptySource를 활용하여 코드 중복을 줄여보면 어떨까요?

assertThrows(IllegalArgumentException.class, () -> new CarName(null));
}

@Test
void carNameCannotBeEmpty() {
assertThrows(IllegalArgumentException.class, () -> new CarName(""));
}
}
4 changes: 3 additions & 1 deletion src/test/java/racing/CarTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ void carDoesNotMove() {
Car car = new Car("Car") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Car에 전략 패턴을 적용하여 자동차의 움직임을 유연하게 만들어보면 어떨까요?
https://park-algorithm.tistory.com/entry/%EC%A0%84%EB%9E%B5-%ED%8C%A8%ED%84%B4-%EC%82%AC%EC%9A%A9-%ED%9B%84%EA%B8%B0

@Override
public void move() {
if (canMove(5)) { // 임의의 값 5를 전달하여 항상 true를 반환하도록 함

if (canMove(5)) {

Position position = new Position(1);
}
}
Expand Down
29 changes: 29 additions & 0 deletions src/test/java/racing/PositionTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package racing;

import org.junit.jupiter.api.Test;
import racing.entity.Position;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

public class PositionTest {

@Test
void positionCorrectly() {
Position position = new Position(5);
assertEquals(5, position.getValue());
}

@Test
void positionCannotBeNegative() {
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> new Position(-1));
assertEquals("cannot be negative.", exception.getMessage());
}

@Test
void movePositionCorrectly() {
Position position = new Position(5);
Position movedPosition = position.movePosition();
assertEquals(6, movedPosition.getValue());
}
}