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

[둘리] 1단계 블랙잭 제출합니다. #21

Merged
merged 70 commits into from
Mar 5, 2023

Conversation

hyemdooly
Copy link

안녕하세요, 리뷰어님!! 많이 배우겠습니다. 피드백 부탁드립니다! :)

Copy link

@galcyurio galcyurio left a comment

Choose a reason for hiding this comment

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

1단계 블랙잭 미션 고생하셨습니다.
클래스를 각 역할별로 잘 분리해주셨네요 :)
이번 단계에서는 UI 로직 분리와 테스트 코드에서 불필요한 정보를 없애는데에 초점을 맞춰보면 좋겠어요.

src/main/kotlin/domain/CardPackGenerator.kt Outdated Show resolved Hide resolved
src/main/kotlin/domain/CardPicker.kt Outdated Show resolved Hide resolved
src/main/kotlin/model/Card.kt Outdated Show resolved Hide resolved
src/main/kotlin/model/Cards.kt Outdated Show resolved Hide resolved
src/main/kotlin/model/Suit.kt Outdated Show resolved Hide resolved
src/main/kotlin/view/InputView.kt Outdated Show resolved Hide resolved
src/test/kotlin/blackjack/domain/CardGameTest.kt Outdated Show resolved Hide resolved
src/test/kotlin/blackjack/model/DealerTest.kt Outdated Show resolved Hide resolved
src/test/kotlin/blackjack/model/ParticipantsTest.kt Outdated Show resolved Hide resolved
src/main/kotlin/model/Players.kt Outdated Show resolved Hide resolved
Copy link

@galcyurio galcyurio left a comment

Choose a reason for hiding this comment

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

1단계 미션 고생하셨습니다 👍
몇 가지 피드백을 남겨두었는데 다음 단계에서 같이 반영해주세요!

Comment on lines 13 to 22
fun `카드의 합이 16을 초과하지 않으면 hit 한다`() {
val dealer = Dealer(
Cards(
listOf(
Card(Rank.JACK, Suit.DIAMOND),
Card(Rank.SIX, Suit.CLOVER),
),
),
)
val dealer = hitDealer()
assertThat(dealer.isHit()).isTrue
}

@Test
fun `카드의 합이 16을 초과하면 stay 한다`() {
val dealer = Dealer(
Cards(
listOf(
Card(Rank.JACK, Suit.DIAMOND),
Card(Rank.SEVEN, Suit.CLOVER),
),
),
)
val dealer = stayDealer()
assertThat(dealer.isHit()).isFalse
}

Choose a reason for hiding this comment

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

이 테스트 케이스에서 중요한 정보는 Rank입니다.
테스트 케이스를 처음 보는 사람이 테스트 본문만 보아도 합이 16이 넘거나 넘지 않았을 때, hit or stay 한다는 것을 알 수 있어야 합니다.

하지만 이미 함수 이름에서부터 hitDealer(), stayDealer()라고 확정되어있고 어떤 때에 hit 되는지는 테스트 본문을 떠나서 해당 함수를 들여다 보아야합니다.

dealer(rank1, rank2, ...) 형태로 만들어보는건 어떨까요?

Comment on lines +98 to +105
private const val DIAMOND = "다이아몬드"
private const val CLOVER = "클로버"
private const val SPADE = "스페이드"
private const val HEART = "하트"
private const val ACE = "A"
private const val KING = "K"
private const val JACK = "J"
private const val QUEEN = "Q"

Choose a reason for hiding this comment

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

View에서 UI를 그리도록 잘 변경해주셨네요 👍

Choose a reason for hiding this comment

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

조금 더 고도화해본다면 ui layer에서만 사용하는 SuitModel을 만들고 해당 클래스에서 UI를 제공하도록 만드는 방법도 있습니다.
이 방식은 이번 미션에서는 적용하지 않아도 좋지만 추후 안드로이드에서 자주 쓰이는 방식이니 미리 인지해두시면 좋겠어요.

Comment on lines +12 to +16
private lateinit var game: CardGame
@BeforeEach
fun setUp() {
game = CardGame(CardPackGenerator().createCardPack())
}

Choose a reason for hiding this comment

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

참고로 junit4, junit5에서는 각 테스트 케이스를 수행하기 전에 테스트 클래스를 새로 만드는게 기본 설정이라 실제로는 @BeforeEach도 필요없습니다.
하지만 가독성과 추후에 필요해지는 경우도 생기므로 지금처럼 초기화 코드를 분리해주시는게 좋습니다.

만약 필요하다면 @TestInstance(Lifecycle.PER_CLASS)를 통해 한 번만 인스턴스가 만들어지도록 할 수도 있습니다.

Comment on lines +10 to +12
fun pick(cardPack: Cards) {
cards.add(cardPack.pop())
}

Choose a reason for hiding this comment

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

더욱 코드가 객체지향적이 되었네요 👍

Comment on lines +25 to +30
fun pop(): Card {
require(_cards.isNotEmpty()) { OUT_OF_INDEX_CARDS_CURSOR }
val card = _cards[0]
_cards.removeAt(0)
return card
}

Choose a reason for hiding this comment

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

LinkedList와 같이 이미 잘 만들어져있는 자료구조를 활용해봐도 좋겠네요.

@galcyurio galcyurio merged commit 9d436b1 into woowacourse:hyemdooly Mar 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants