[๐ ์ฌ์ดํด2 - ๋ฏธ์ (๋ธ๋์ญ ๋ฒ ํ )] ๋งฅ์ค ๋ฏธ์ ์ ์ถํฉ๋๋ค. #1130
[๐ ์ฌ์ดํด2 - ๋ฏธ์
(๋ธ๋์ญ ๋ฒ ํ
)] ๋งฅ์ค ๋ฏธ์
์ ์ถํฉ๋๋ค. #1130simhokyung wants to merge 87 commits intowoowacourse:simhokyungfrom
Conversation
- ๋๋ฌ ์นด๋ 16์ดํ ์ฌ๋ถ ํ์ธ ํ ์คํธ ๊ตฌํ - ์นด๋ ์ถ๊ฐ ํ์ธ ํ ์คํธ ๊ตฌํ
- ํ๋ ์ด์ด์ ์นด๋ ์ถ๊ฐ ์ฌ๋ถ ํ์ธ ํ ์คํธ - ํ๋ ์ด์ด์ ๋ฒ์คํธ ์ฌ๋ถ ํ์ธ ํ ์คํธ
- ๋ชจ๋ ํ๋ ์ด์ด๋ค์ ๋ฒ์คํธ ์ฌ๋ถ ํ์ธ ํ ์คํธ ์์ฑ
- ํ๋ ์ด์ด ์ด๋ฆ ๊ธธ์ด๊ฐ 20์๋ฅผ ์ด๊ณผํ ๊ฒฝ์ฐ ์์ธ ๋ฐ์ ํ ์คํธ ์์ฑ - Null ํน์ ๋น ๊ฐ ์ ๋ ฅ ์ ์์ธ ๋ฐ์ ํ ์คํธ
- drawํ๋ ๊ฒฝ์ฐ ํ ์คํธ ์ถ๊ฐ
- DTO ์์ฑ ๋จ๊ณ์์ ๊ณต๊ฐํ ์นด๋ ๋ฒ์๋ฅผ ๊ฒฐ์ ํ๊ณ , ๋ทฐ๋ ์ ๋ฌ๋ฐ์ ๊ฐ๋ง ์ถ๋ ฅํ๋๋ก ํ๋๋ก ์์
- Hand์ hasScoreLessThanOrEqual ๋ฉ์๋๋ฅผ ์ถ๊ฐํ์ฌ Dealer์ checkThreshold ๋ฉ์๋์ ๋ฐํ๊ฐ์์์ ์ง์ ๊ฐ์๋ฅผ ์ค์
- ๋ธ๋์ญ ํ๋จ ํ ์คํธ
- PlayerCreationInfo ํด๋์ค๋ฅผ ํ์ฉํ๋ ๊ตฌ์กฐ๋ก ๋ณ๊ฒฝ
- PlayerCreationInfo ํด๋์ค๋ฅผ ํ์ฉํ๋ ๊ตฌ์กฐ๋ก ๋ณ๊ฒฝ
- Player: ์์ฑ์๋ถ๋ถ์ BettingMoney ์ถ๊ฐ - Participant: getHand()๋ฉ์๋ ์ ๊ทผ์ ์ด์ ๋ณ๊ฒฝ(public -> protected๋ก ๋ณ๊ฒฝ)
- BlackjackGame.start()์ ์ธ์๋ฅผ ํ๋ ์ด์ด ์ด๋ฆ๊ณผ ๋ฐฐํ ๊ธ์ก์ ํฌํจํ๊ณ ์๋ PlayerCreationInfo๋ฅผ ํ์ฉํ๋ ๊ตฌ์กฐ๋ก ๋ณ๊ฒฝ
jamie9504
left a comment
There was a problem hiding this comment.
์๋ ํ์ธ์, ๋งฅ์ค. ๋ฆฌ๋ทฐ์ด ์ ์ด๋ฏธ์ ๋๋ค.
์ฝ๋ฉํธ ๋จ๊ฒจ๋์์ต๋๋ค.
| @@ -1,34 +1,69 @@ | |||
| package controller; | |||
There was a problem hiding this comment.
-
๊ธฐ์กด BlackjackGame.start() ๊ตฌ์กฐ๋ฅผ ์ ์งํ๊ธฐ ์ํด ์์ฑ ์ ๋ณด ๊ฐ์ฒด๋ฅผ ์ถ๊ฐํ ์ ํ์ด ์ ์ ํ๊ฐ?
์ปจํธ๋กค๋ฌ๊ฐ PlayerCreationInfo๋ฅผ ์ง์ ๋ง๋๋ ๊ฒ ์์ฒด๋ ์์ฑ์ ๊ด์ฌํ๋ ํ์ ์๋๊น์?
์๋ ** ์ฝ๋ฉํธ๋ ํจ๊ป ํ์ธํด๋ณด์ธ์. -
Hand์ ์ฑ ์ ๋ถ๋ฆฌ
์ ๋ต์ด ์๋ค๊ธฐ๋ณด๋ค๋ ํธ๋ ์ด๋์คํ์ ๋ฌธ์ ์์.
์ฌ์ฉํ๋ ์ชฝ์์ Hand.getScore()๋ก ์ฐ๋ ๊ฑด ๋์ผํ์ง๋ง,
Score๊ฐ isBust() ๊ฐ์ ํ์๋ฅผ ๊ฐ์ง๋ค๋ฉด ๋๊ฐ ์์ฑ ์ฑ ์์ ๊ฐ๋์ง๊ฐ ์๋ฏธ ์์ด์ ธ์.
ํ์ฌ ๊ตฌ์กฐ์์ Hand๊ฐ new Score(...)๋ฅผ ์ง์ ํธ์ถํ๊ณ ์์ผ๋,
ScoreCalculator์ ์์ํ๋ค๊ณ ํด๋ ์์ฑ ์ฑ ์์ Hand์ ๋จ์์๋ ์ ์ด์์.๊ฒฐ๊ตญ ๋๊ฐ ์์ฑ ์ฑ ์์ ๊ฐ๋์ง์ ์ฐจ์ด์์.
| List<String> playerProfitResults = players.getPlayers().stream() | ||
| .map(player -> String.format("%s: %s%n", | ||
| player.getNameValue(), | ||
| ProfitCalculator.formatProfit( | ||
| ProfitCalculator.calculatePlayerProfit(player, dealer) | ||
| ))) | ||
| .toList(); |
There was a problem hiding this comment.
์ปจํธ๋กค๋ฌ์์ String.format์ผ๋ก ์ง์ ํฌ๋งทํ
ํ๊ณ ์์ด์.
์ถ๋ ฅ ํ์์ ๋ํ ์ฑ
์์ OutputView๊ฐ ๊ฐ์ง๋ ๊ฒ์ด ์์ฐ์ค๋ฝ์ง ์์๊น์?
| List<PlayerCreationInfo> playerCreationInfos = new ArrayList<>(); | ||
| for (String name : names) { | ||
| Integer money = InputView.readBettingMoney(name); | ||
| System.out.println(); |
There was a problem hiding this comment.
System.out.println()์ด ์ปจํธ๋กค๋ฌ์ ์ง์ ์๋ค์.
์ถ๋ ฅ์ OutputView์ ์์ํ๋ ๊ฒ์ด ์ด๋จ๊น์?
| System.out.printf("%s์ ๋ฐฐํ ๊ธ์ก์?%n",name); | ||
| return Integer.parseInt(scanner.nextLine()); |
There was a problem hiding this comment.
์ซ์๊ฐ ์๋ ๊ฐ์ด ์ ๋ ฅ๋๋ฉด ์ด๋ป๊ฒ ๋๋์?
| public class ProfitCalculator { | ||
| private static final double BLACKJACK_PROFIT_RATE = 1.5; | ||
|
|
||
| public static double calculatePlayerProfit(Player player, Dealer dealer) { |
There was a problem hiding this comment.
ํจ์(๋๋ ๋ฉ์๋)์ ๊ธธ์ด๊ฐ 10๋ผ์ธ์ ๋์ด๊ฐ์ง ์๋๋ก ๊ตฌํํ๋ค.
| public class BettingMoneyTest { | ||
|
|
||
| @Test | ||
| void ๋ฒ ํ ๊ธ์ก์_์์ฑํ _์_์๋ค(){ | ||
| BettingMoney bettingMoney = BettingMoney.of(1000); | ||
| assertThat(bettingMoney.getMoney()).isEqualTo(1000); | ||
| } | ||
|
|
||
| @Test | ||
| void ๋ฒ ํ ๊ธ์ก์ด_0์ดํ๋ฉด_์์ธ๊ฐ_๋ฐ์ํ๋ค(){ | ||
| assertThatThrownBy(() -> BettingMoney.of(0)) | ||
| .isInstanceOf(IllegalArgumentException.class); | ||
| assertThatThrownBy(() -> BettingMoney.of(-1000)) | ||
| .isInstanceOf(IllegalArgumentException.class); | ||
| } | ||
| } |
There was a problem hiding this comment.
๋ง์ฝ product code์์ ํด๋น ๊ธฐ์ค์ด 100 ์ดํ๋ฉด ์์ธ๊ฐ ๋ฐ์ํ๋ค๋ก ๋ณ๊ฒฝ๋๋ค๋ฉด,
์ด ํ
์คํธ๋ค๋ก ๋ฌด์์ ์ ๊ฒํ ์ ์๋์?
| System.out.println("\n\n## ์ต์ข ์์ต"); | ||
| System.out.printf("๋๋ฌ: %s%n", dealerProfit); |
There was a problem hiding this comment.
๊ฐํ๋ฌธ์๊ฐ ํผ์ฉ๋๊ณ ์๋ค์.
๊ฐ ๊ฐํ๋ฌธ์๋ณ ํน์ง์ ์ ์ด์ฃผ์ธ์.
| Player bustPlayer = Player.of(Name.from("pobi"), new Hand(new ArrayList<>(List.of( | ||
| Card.of(CardNumber.J, CardShape.CLOVER), | ||
| Card.of(CardNumber.K, CardShape.HEART), | ||
| Card.of(CardNumber.Q, CardShape.DIAMOND))))); | ||
| Card.of(CardNumber.J, CardShape.CLOVER), | ||
| Card.of(CardNumber.K, CardShape.HEART), | ||
| Card.of(CardNumber.Q, CardShape.DIAMOND)))) | ||
| , BettingMoney.of(1000) | ||
| ); | ||
|
|
||
| Player normalPlayer = Player.of(Name.from("jason"), new Hand(new ArrayList<>(List.of( | ||
| Card.of(CardNumber.J, CardShape.CLOVER), | ||
| Card.of(CardNumber.Q, CardShape.DIAMOND))))); | ||
| Card.of(CardNumber.Q, CardShape.DIAMOND)))), | ||
| BettingMoney.of(2000)); | ||
|
|
||
| Players allBustPlayers = Players.from(List.of(bustPlayer, bustPlayer, bustPlayer)); | ||
| Players containBustPlayers = Players.from(List.of(bustPlayer, normalPlayer, normalPlayer)); | ||
| Players allNormalPlayers = Players.from(List.of(normalPlayer, normalPlayer, normalPlayer)); |
There was a problem hiding this comment.
bustPlayer, normalPlayer ๋ฑ์ด ํด๋์ค ํ๋๋ก ์ ์ธ๋์ด ์๋ค์.
@BeforeEach ๋ฑ์์ ์ ์ธํ๋ ๊ฒ๊ณผ ์ด๋ ํ ์ฐจ์ด๊ฐ ์์๊น์?
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| public class ProfitCalculatorTest { |
There was a problem hiding this comment.
๋๋ฌ์ ํ๋ ์ด์ด๊ฐ ๋ชจ๋ ๋ฒ์คํธ์ธ ๊ฒฝ์ฐ๋ ์์ด๋ ๋ ๊น์?
| package domain.card; | ||
|
|
||
| public enum CardNumber { | ||
| ACE("A", 1), |
There was a problem hiding this comment.
๊ทธ๋ฌ๊ณ ๋ณด๋ ACE๋ ํ๋ค์์ผ๋ก, J, Q, K๋ ์ฝ์ด๋ก ์ ์ธํ ์ด์ ๊ฐ ๋ฌด์์ธ๊ฐ์?
์ผ๊ด์ฑ ์๊ฒ ํต์ผํ๋ค๋ฉด ์ด๋ค ๊ธฐ์ค์ผ๋ก ๋ง์ถ๋ ๊ฒ ์ข์๊น์?
PR์ main์ผ๋ก ์๋ชป ๋ ๋ ค์, ๊ธฐ์กด PR์ ๋ซ๊ณ ๋ค์ ์์ฑํฉ๋๋ค! ๐ญ
์ฒดํฌ ๋ฆฌ์คํธ
test๋ฅผ ์คํํ์ ๋, ๋ชจ๋ ํ ์คํธ๊ฐ ์ ์์ ์ผ๋ก ํต๊ณผํ๋์?์ด๋ค ๋ถ๋ถ์ ์ง์คํ์ฌ ๋ฆฌ๋ทฐํด์ผ ํ ๊น์?
1. ๊ธฐ์กด
BlackjackGame.start()๊ตฌ์กฐ๋ฅผ ์ ์งํ๊ธฐ ์ํด ์์ฑ ์ ๋ณด ๊ฐ์ฒด๋ฅผ ์ถ๊ฐํ ์ ํ์ด ์ ์ ํ๊ฐ?๊ธฐ์กด ๊ตฌ์กฐ์์๋
BlackjackGame.start()์ ํ๋ ์ด์ด ์ด๋ฆ ๋ชฉ๋ก(List<String>)์ ์ ๋ฌํ๊ณ ,BlackjackGame๋ด๋ถ์์ ์ด๋ฅผ ๋ฐํ์ผ๋กPlayer๋ฅผ ์์ฑํ๋ ๋ฐฉ์์ผ๋ก ๊ตฌํ๋์ด ์์์ต๋๋ค.์ด๋ฒ ์ฌ์ดํด์์ ๋ฒ ํ ๊ธฐ๋ฅ์ด ์ถ๊ฐ๋๋ฉด์, ๋ ์ด์ ์ด๋ฆ๋ง์ผ๋ก๋
Player๋ฅผ ์์ฑํ ์ ์๊ฒ ๋์๊ณ ,์ด๋ฆ๊ณผ ํจ๊ป
BettingMoney๋ ์ด๊ธฐํํด์ผ ํ๋ ์ํฉ์ด ์๊ฒผ์ต๋๋ค.์ด๋ ๊ฐ์ฅ ๋จผ์ ๊ณ ๋ฏผํ๋ ๋ถ๋ถ์, ๊ธฐ์กด์ ๊ตฌ์กฐ๋ฅผ ์ต๋ํ ์ ์งํ๋ฉด์ ํ์ฅํ์๋ ๊ฒ์ด์์ต๋๋ค.
๊ธฐ์กด์ฒ๋ผ
BlackjackGame.start()๊ฐ ๊ฒ์ ์์๊ณผ ํ๋ ์ด์ด ์์ฑ์ ํจ๊ป ๋ด๋นํ๋ ๊ตฌ์กฐ๋ฅผ ์ ์งํ๋๋ก ์ค๊ณํ๊ณ ์ถ์๊ณ ,๊ทธ๋์
start()์ ์ญํ ์ ์ ์งํ๋, ๋จ์ ์ด๋ฆ ๋ชฉ๋ก ๋์ ์ด๋ฆ๊ณผ ๋ฐฐํ ๊ธ์ก์ ํจ๊ป ๋ด๋PlayerCreationInfo๊ฐ์ฒด๋ฅผ ๋ง๋ค๊ณ , ๊ทธ ๋ฆฌ์คํธ๋ฅผ ๋๊ฒจ์ฃผ๋ ๋ฐฉ์์ ์ ํํ์ต๋๋ค.์ด ๋ฐฉ์์
BlackjackGame.start()๊ฐ ์ฌ์ ํ ๊ฒ์ ์์ฑ ์ฑ ์์ ๊ฐ์ง๋๋ก ์ ์งํ ์ ์๊ณ ,GameController๊ฐ ๋๋ฉ์ธ ๊ฐ์ฒด ์์ฑ์ ๊น๊ฒ ๊ด์ฌํ์ง ์๋๋ก ํ ์ ์๋ค๋ ์ ์์ ๊ด์ฐฎ๋ค๊ณ ํ๋จํ์ต๋๋ค.๋ค๋ง
PlayerCreationInfo๋ ์ค์ ๊ฒ์ ์งํ ์ค์๋ ์ฌ์ฉ๋์ง ์๊ณ ์์ฑ ์์ ์๋ง ์ฌ์ฉ๋๊ธฐ ๋๋ฌธ์,์ด ๊ฐ์ฒด๊ฐ ๋๋ฉ์ธ์ ์ผ๋ก ์๋ฏธ๊ฐ ์๋ ๊ฐ์ฒด์ธ์ง,
์๋๋ฉด ๊ธฐ์กด ๊ตฌ์กฐ๋ฅผ ์ ์งํ๊ธฐ ์ํด ๋ง๋ ๋จ์ ํฌ์ฅ ๊ฐ์ฒด์ ๊ฐ๊น์ด์ง์ ๋ํด ๊ณ ๋ฏผ์ด ์์์ต๋๋ค.
ํ์ฌ ๋ฐฉ์์ด ์ ์ ํ ์ ํ์ธ์ง,
ํน์ ํ๋ ์ด์ด ์์ฑ ์ฑ ์์ ๋ค๋ฅธ ๊ฐ์ฒด๋ก ๋ถ๋ฆฌํ๋ ๊ฒ์ด ๋ ์์ฐ์ค๋ฌ์ด์ง
์ ์ด๋ฏธ์ ์๊ฒฌ์ ๋ฃ๊ณ ์ถ์ต๋๋ค.
2.
Hand์ ์ฑ ์ ๋ถ๋ฆฌScore๋ฅผHand์ ์ํ๋ก ๋ณด๋ ๊ฒ์ด ์์ฐ์ค๋ฝ๋ค๊ณ ์๊ฐํด์Hand.getScore()๋ฅผ ๋์๊ณ , ๋ค๋ง ์ ์ ๊ณ์ฐ ๊ท์น๊น์งHand๊ฐ ๋ชจ๋ ์ ํ์๋ ์๋ค๊ณ ํ๋จํด ๊ณ์ฐ ๊ณผ์ ์ScoreCalculator์ ์์ํ์ต๋๋ค. ๊ทธ๋์ ํ์ฌ๋Hand๊ฐ ๊ณ์ฐ ๊ฒฐ๊ณผ๋ฅผ ๋ฐ์Score๋ฅผ ์์ฑํด ๋ฐํํ๋ ๊ตฌ์กฐ๋ก ๋์์ต๋๋ค.๋ค๋ง ๋ฆฌ๋ทฐ ์ฃผ์ ๋ด์ฉ์ ๋ณด๋ฉด์, ์ด ๊ตฌ์กฐ๊ฐ ์์ ํ โ์ 3์๊ฐ
Score๋ฅผ ๋ง๋ ๋คโ๊ธฐ๋ณด๋ค๋Hand๊ฐ ์์ฑ ์ฑ ์๊น์ง ์ผ๋ถ ๊ฐ์ง๊ณ ์์ด์ 2๋ฒ๊ณผ 3๋ฒ ์ฌ์ด์ ๊ฑธ์ณ ์๋ ํํ๋ก๋ ๋ณด์ผ ์ ์๊ฒ ๋ค๊ณ ๋๊ผ์ต๋๋ค.์ฌ๊ธฐ์ ๊ถ๊ธํ ๋ถ๋ถ์ด ์๋๋ฐ์,
ScoreCalculator๊ฐ int๋ง ๊ณ์ฐํ๊ณHand๊ฐScore๋ฅผ ์์ฑํ๋ ํ์ฌ ๊ตฌ์กฐ์,ScoreCalculator๊ฐScore๊น์ง ๋ฐํํ๋ ๊ตฌ์กฐ์ ํต์ฌ ์ฐจ์ด๋ฅผ ์ด๋ป๊ฒ ๋ณด์๋์ง ๊ถ๊ธํฉ๋๋ค.Score์ ์์ฑ ์์น๊ฐ ๋ค๋ฅด๊ธด ํ์ง๋ง, ์ฌ์ฉํ๋ ์ชฝ์์๋ ๊ฒฐ๊ตญHand.getScore()๋ก ๊ฐ์ ธ๋ค ์ฐ๊ฒ ๋์ด์, ์ ๊ฐ ๋๋ผ๊ธฐ์ ๋น์ทํ ๋ฐฉ์์ด๋ผ๊ณ ์๊ฐ๋๋๋ฐ, ์ ๋ต์ด ์๋๊ฑธ๊น์? ์ ์ด๋ฏธ์ ์๊ฒฌ์ด ๊ถ๊ธํฉ๋๋ค.์ด์ธ์๋ ๋ถ์กฑํ ๋ถ๋ถ์ ์์ ๋กญ๊ฒ ํผ๋๋ฐฑ ์ฃผ์๋ฉด ๊ฐ์ฌํ๊ฒ ์ต๋๋ค!