-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
π 3λ¨κ³ - μλμ°¨ κ²½μ£Ό #5920
base: jonghoonok
Are you sure you want to change the base?
Conversation
κΈ°λ₯ λͺ©λ‘ 체ν¬λ¦¬μ€νΈ μμ±
- κ°μ μ λ ₯λ°λ UserInputProcessor μμ± - κ°μ λ΄λ UserInput μμ± - νλ‘κ·Έλ¨μ μ€ννλ Main μμ± - κ²μμ μ€ννλ GameController μμ±
- μμΉλΌλ μνμ μνλ₯Ό λ³κ²½νλ λ©μλλ₯Ό κ°λ Car μμ± - Carμ λν ν μ€νΈ μμ±
- μ λ ₯λ°μ κ°λ§νΌμ Carλ₯Ό κ°κ³ μ΄λ€μ μμ§μ΄λ CarController μμ± - CarController λ΄λΆμμ randomμ μ΄μ©νμ¬ Carλ₯Ό μ΄λμν€λλ‘ ν¨
- Carμ 리μ€νΈλ₯Ό λ°μμ μ 체 μλμ°¨μ μνλ₯Ό μΆλ ₯νλ CarPrinter μμ± - CarController λ΄λΆμμ CarPrinterλ₯Ό νΈμΆνμ¬ μνλ₯Ό μΆλ ₯νκ² ν¨
- Carμ 리μ€νΈλ₯Ό κ°λ 1κΈ μ»¬λ μ Cars μμ± - domain, view ν¨ν€μ§ λΆλ¦¬
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3λ¨κ³ μ§ν κ³ μλ§μΌμ
¨μ΅λλ€~
κ°λ¨ν νΌλλ°±μ λ¨κ²ΌμΌλ νμΈν΄μ£ΌμΈμ!~
μΈμ λ μ§ κΆκΈνκ² μλ€λ©΄ μ¬λμΌλ‘ μ°λ½μ£ΌμΈμ!
ν§ν
μ
λλ€!
private final Cars cars; | ||
private final UserInput userInput; | ||
|
||
public CarController(UserInput userInput) { | ||
this.userInput = userInput; | ||
this.cars = new Cars(userInput.getNumOfCar()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MVCν¨ν΄μ κΈ°λ°νμ κ±° κ°μ΅λλ€.
Controllerλ κ³Όμ° μνλ₯Ό κ°μ§κ³ μλκ² λ§μκΉμ?
μ¦, μΈμ€ν΄μ€λ³μλ‘ Carsλ₯Ό κ°μ§κ³ μλκ² λ§μμ§... κ³ λ―Όμ ν΄λ³΄μλ©΄ μ΄λ¨κΉμ?
public class GameController { | ||
private final UserInputProcessor userInputProcessor = new UserInputProcessor(); | ||
|
||
public void run() { | ||
UserInput userInput = userInputProcessor.getUserInput(); | ||
CarController carController = new CarController(userInput); | ||
carController.race(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Controllerκ° Controllerλ₯Ό κ°μ§κ³ μλ ννκ° MVCμμ κΈ°λ°λλκ±ΈκΉμ?
private boolean isMovable() { | ||
return random.nextInt() > MOVE_THRESHOLD; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μ¬κΈ°μ λλ€μ μ μ΄νλ€λ©΄, Carsμ λν moveAllμ λν ν μ€νΈκ° νλ€κ±° κ°μ΅λλ€.
νλ² μλ κΈμ μ°Έκ³ ν΄λ³΄μλ©΄ μ΄λ¨κΉμ?
https://tecoble.techcourse.co.kr/post/2020-05-17-appropriate_method_for_test_by_interface/
@ParameterizedTest(name = "μλμ°¨λ₯Ό μμ§μ΄λ©΄ μλμ°¨κ° μμ§μΈ λ§νΌ μμΉκ° λ³νλ€. μμ§μΈ κ°: {0}") | ||
@ValueSource(ints = {1, 2, 3}) | ||
void shouldMoveCarByGivenDistance(int inputDistance) { | ||
Car car = new Car(); | ||
car.move(inputDistance); | ||
assertThat(car.getDistance()).isEqualTo(inputDistance); | ||
} | ||
|
||
@ParameterizedTest(name = "μλμ°¨λ₯Ό μμλ§νΌ μμ§μ΄λ©΄ μλ¬κ° λ°μνλ€. μμ§μΈ κ°: {0}") | ||
@ValueSource(ints = {-1, -2, -3}) | ||
void sholdThrowRuntimeExceptionWhenNegativeDistanceIsGiven(int inputDistance) { | ||
Car car = new Car(); | ||
assertThatThrownBy(() -> car.move(inputDistance)) | ||
.isInstanceOf(RuntimeException.class); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
κ²½κ³κ°μ ν
μ€νΈν΄λΌ. λΌλ λ§μ΄ μμ΅λλ€.
μμμ μμλ₯Ό κ²μ¦ν΄μΌ νλλ°μ.
κ·Έλ λ€λ©΄ μμμ μμμ κ²½κ³μ μ μ΄λμΌκΉμ?
-1κ³Ό 1μ΄λΌκ³ μκ°ν©λλ€.
κ·Έ λκ°μ§ ν
μ€νΈλ‘ μΆ©λΆν ν μ μμ§ μμκΉμ?
1μ κ²μ¦νλ€μ 2,3μ κ²μ¦νλκ²μ λν΄ ν° μλ―Έκ° μμκΉμ?
νλ² κ³ λ―Όν΄λ³΄μλ©΄ μ’μκ±° κ°μ΅λλ€!
import java.util.Random; | ||
import java.util.function.Consumer; | ||
|
||
public class Cars { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μΌκΈμ»¬λ μ π
μλ νμΈμ, μ€λλ 리뷰 μ λΆνλ립λλ€.
randomμ λν ν μ€νΈ μμ± λ±μ΄ μ’ μ 맀ν΄μ ν μ€νΈ μ½λκ° λΆμ‘±ν κ°μ΄ μλλ°μ,
οΏ½ν μ€νΈλ₯Ό μ΄λ€ μμΌλ‘ μμ±νλ©΄ μ’μμ§ μ€μ¬μΌλ‘ νΌλλ°± ν΄μ£Όμλ©΄ κ°μ¬νκ² μ΅λλ€!