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

[자동차 경주 step1] 양두영 미션 제출합니다. #19

Open
wants to merge 32 commits into
base: FhRh
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
643b604
feat : readme 작성
Due-IT Aug 6, 2024
1c60e62
feat : 게임 흐름 코드 추가
Due-IT Aug 6, 2024
76ee82c
feat : 게임 준비 컨트롤러 코드 작성
Due-IT Aug 6, 2024
1332d36
feat : 게임 준비 안내문구 출력 코드 작성
Due-IT Aug 6, 2024
480295e
feat : 게임 준비 입력기 코드 작성
Due-IT Aug 6, 2024
c6b78b0
feat : Cars객체 생성
Due-IT Aug 6, 2024
ed68363
test : 자동차 이름을 입력받아 쉼표 기준으로 구분한다
Due-IT Aug 6, 2024
540ba0c
fix : 한글 메서드 역따옴표 사용 및 출력테스트는 삭제
Due-IT Aug 6, 2024
4a8fa93
test : 라운드 입력과 예외처리에 대한 테스트 코드 작성
Due-IT Aug 6, 2024
0aae47d
docs : readme에 수행한 작업을 체크
Due-IT Aug 6, 2024
7322a9a
test : 자동차 객체 집합 생성 테스트 코드 작성
Due-IT Aug 6, 2024
469efd7
feat : 자동차 집합 생성 코드 작성
Due-IT Aug 6, 2024
e76d519
test : 자동차의 위치를 출력한다.
Due-IT Aug 6, 2024
128c5b2
feat : 이동 및 위치 출력 코드 작성
Due-IT Aug 6, 2024
1886873
test : 주사위를 굴려 한자리 정수를 반환한다
Due-IT Aug 6, 2024
c39982d
feat : 주사위를 굴려 1~9사이의 정수를 반환한다
Due-IT Aug 6, 2024
fbe849d
test : 특정 위치의 자동차를 한 칸 움직인다
Due-IT Aug 6, 2024
6da8a3d
feat : 테스트 코드 통과 완료
Due-IT Aug 6, 2024
21b64a2
feat : cars에 속한 car들의 위치 출력
Due-IT Aug 6, 2024
a8747eb
fix : Cars를 일급 컬렉션 정의 규칙에 맞게 수정
Due-IT Aug 6, 2024
b3dcfca
feat&test : 우승한 차들의 이름을 출력한다.
Due-IT Aug 6, 2024
73495d0
fix : 오로지 생성자만을 사용한 Cars객체 생성 및 전체적인 기능 작성 완료
Due-IT Aug 6, 2024
ca514d0
docs : 작업한 내용 readme 적용
Due-IT Aug 6, 2024
30bb064
refactor : mvc패턴을 고려하여 리팩토링
Due-IT Aug 9, 2024
0bdeb43
refactor : GameInputer 위치 변경
Due-IT Aug 9, 2024
a0631cf
feat : 입력값 검증 기능 추가
Due-IT Aug 9, 2024
77fff6b
docs : README 수정
Due-IT Aug 9, 2024
7c200d5
refactor : cars는 우승에 대한 개념과 출력에 대해 모른다.
Due-IT Aug 15, 2024
075ae77
refactor : 우승자는 컨트롤러가 결정한다.
Due-IT Aug 15, 2024
ea21bb6
fix : position은 외부에서 변경할 수 없다.
Due-IT Aug 15, 2024
5157d6a
refactor : require를 통해 입력값을 검사한다.
Due-IT Aug 15, 2024
be3bcb1
refactor : 중복검사 최적화
Due-IT Aug 15, 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
12 changes: 10 additions & 2 deletions src/main/kotlin/racingcar/controller/GameController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class GameController {
for (i in 1..rounds) {
Copy link
Contributor

Choose a reason for hiding this comment

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

repeat 을 활용해 볼 수 있겠네요:)

Copy link
Author

Choose a reason for hiding this comment

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

유용한 키워드네요 :)

processRound(cars)
}

GameAnnouncer.printWinners(cars)
val winners = resolveWinners(cars)
GameAnnouncer.printWinners(winners)
}

private fun processRound(cars: Cars) {
Expand All @@ -33,4 +33,12 @@ class GameController {
}
GameAnnouncer.printCarPositions(cars)
}

private fun resolveWinners(cars : Cars) : Cars{
val carList = cars.getCarList()
val maxPosition = carList.maxOf { it.position }
val winners = carList.filter { it.position == maxPosition }
.map { it }
return Cars(winners)
}
Comment on lines +38 to +44
Copy link
Contributor

Choose a reason for hiding this comment

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

private 함수는 테스트하기 힘들죠.
이 부분도 심판 도메인 모델로 분리하면 관심사도 분리되고 및 테스트 용이성도 증가할 것 같아요.!

Copy link
Contributor

Choose a reason for hiding this comment

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

Cars 를 받아 Winners 를 구하는 책임을 누군가 가지는게 어떤가요!

Copy link
Author

Choose a reason for hiding this comment

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

아하 심판 도메인을 구현하는 부분 참 좋은 생각인것 같습니다!

}
10 changes: 3 additions & 7 deletions src/main/kotlin/racingcar/view/GameAnnouncer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,9 @@ object GameAnnouncer {
cars.getCarList().forEach{printCarPosition(it)}
println()
}
fun printWinners(cars: Cars) {
val carList = cars.getCarList()
val maxPosition = carList.maxOf { it.position }
val winners = carList.filter { it.position == maxPosition }
.map { it.name }

val winnerNames = winners.joinToString(", ") { it }
fun printWinners(winners : Cars) {
val winnerList = winners.getCarList()
val winnerNames = winnerList.joinToString(", ") { it.name }
println("최종 우승자 : $winnerNames")
}
fun printProcess() {
Expand Down
16 changes: 0 additions & 16 deletions src/test/kotlin/study/model/CarsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,4 @@ class CarsTest {
val carList = cars.getCarList()
assertEquals(carList[0].position, 1)
}

@Test
fun `우승한 차들의 이름을 출력한다`(){
//given
val expected = listOf("apple", "banana")
val car1 = Car("apple", 2)
val car2 = Car("banana", 2)
val car3 = Car("cherry", 1)
val cars = Cars(listOf(car1,car2,car3))

//when
val result = cars.getWinnerNames()

//then
assertEquals(expected,result)
}
}