-
Notifications
You must be signed in to change notification settings - Fork 4
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
add 4ColorsCard usecase #99
base: develop
Are you sure you want to change the base?
Conversation
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.
Review done.
src/test/java/domain/GameTest.java
Outdated
game.rollDice(playerB.getId(), 1); | ||
|
||
// then | ||
int bakerySize = handCard.getEstablishments(Bakery.class).size(); |
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.
這裡不應該計算 bakerySize
,而是手牌中 bakery 數量可獲得的金額,建議可改成 totalBakeryBonuses
src/test/java/domain/GameTest.java
Outdated
assertThat(playerB.getTotalCoins()).isEqualTo(2); | ||
assertThat(game.getBank().getTotalCoin()).isEqualTo(originalBankCoins - bakerySize); |
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.
isEqualTo(2)
改為isEqualTo(totalBakeryBonuses)
bakerySize
改為totalBakeryBonuses
src/test/java/domain/GameTest.java
Outdated
當A骰子擲出點數為5時, | ||
B可以從銀行得到2元,C可以從銀行得到1元 | ||
""") | ||
void BLUE5_當B有2張森林B得到2元_當C有1張森林C得到1元() { |
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.
function name buleCardForestTest
src/test/java/domain/GameTest.java
Outdated
int point1 = dice1.throwDice(); | ||
int point2 = dice2.throwDice(); |
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.
可以移除
…fourColorUsecases # Conflicts: # src/test/java/domain/GameTest.java
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.
Review done.
src/test/java/domain/GameTest.java
Outdated
HandCard handCard = new HandCard(); | ||
handCard.addHandCard(new Bakery()); | ||
handCard.addHandCard(new Bakery()); | ||
Player playerB = Player.builder().id("B01").name("B").coins(0).handCard(handCard).build(); |
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.
建立 PlayerA、B、C 物件可以抽成屬性,在 @beforeach 內賦值。
如果有測試案例用到 Player 就直接取用這些屬性。
整個檔案出現類似的程式碼都套用這個規則。
private Player playerA;
@BeforeEach
void setup() {
playerA = Player.builder()
.id("A01")
.name("A")
.build();
}
在各自的測試方法內呼叫 addCardToHandCard() 加入 handCard
var originalBankCoins = game.getBank().getTotalCoin(); | ||
|
||
// when | ||
Mockito.when(dice.throwDice()).thenReturn(2); |
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.
放在 mock 骰子物件下方。
這不是 when 的程式碼,而是 given 模擬的資料。
整個檔案出現類似的程式碼都套用這個規則
src/test/java/domain/GameTest.java
Outdated
|
||
// then | ||
int totalBakeryBonuses = handCard.getEstablishments(Bakery.class).size(); | ||
assertThat(playerB.getTotalCoins()).isEqualTo(2); |
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.
isEqualTo(2)
的 2 命名為具有領域意義的名稱,會更好理解
assertThat(playerB.getTotalCoins()).isEqualTo(totalBakeryBonuses);
整個檔案內的 assertion 都套用此規則
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.
調整DisplayName說明清楚
src/test/java/domain/GameTest.java
Outdated
playerC.payCoin(2); | ||
playerB.payCoin(2); | ||
playerA.gainCoin(4); |
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.
nit,
體育館的發動效果沒有在 takeAllPlayersEffect()
裡面是正常的嗎?
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.
已新增takeEffectPurple方法
src/test/java/domain/GameTest.java
Outdated
當玩家B有2張森林 | ||
當玩家C有1張森林 |
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.
nit
測試 PlayerA 體育館的效果,PlayerB、C 可以不用有手牌也可以測試體育館效果。
src/test/java/domain/GameTest.java
Outdated
|
||
@Test | ||
@DisplayName(""" | ||
當玩家A有2張麵包店跟火車站,且輪到A擲骰子 |
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.
nit,
PlayerA 可以不用有手牌,也可以測試家庭餐廳的效果
|
||
Player playerA = Player.builder().id("A01").name("A").coins(10).handCard(handCardA).build(); | ||
Landmark trainStation = playerA.getLandMark("火車站"); | ||
playerA.flipLandMark(trainStation, bank); |
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.
- 應該要在 Game new 出來之後火車站才能翻牌,並且需要使用 Game 物件裡面的 bank
src/test/java/domain/GameTest.java
Outdated
assertThat(playerA.getTotalCoins()).isEqualTo(4); | ||
assertThat(playerB.getTotalCoins()).isEqualTo(2); |
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.
PlayerA 的 4 元和 PlayerB 的 2 元如何得出的?
src/test/java/domain/GameTest.java
Outdated
HandCard handCard = new HandCard(); | ||
handCard.addHandCard(new Bakery()); | ||
handCard.addHandCard(new Bakery()); | ||
Player playerB = Player.builder().id("B01").name("B").coins(0).handCard(handCard).build(); |
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.
整個檔案中有用到的 Player 物件可以抽成屬性,並在 @Beforecach 內賦值
測試方法中有用到 Player 時可以直接調用屬性,不必重新 new 物件
private Player playerA;
@BeforeEach
void setup() {
playerA = Player.builder()
.id("A01")
.name("A")
.build();
}
var originalBankCoins = game.getBank().getTotalCoin(); | ||
|
||
// when | ||
Mockito.when(dice.throwDice()).thenReturn(2); |
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.
when
要寫的是測試的動作,
Mockito.when(dice.throwDice()).thenReturn(2);
是在 given
的時候建立模擬丟骰子的資料
我在GameTest補上4種不同顏色卡的測試案例:
1.GREEN:麵包店
2.BLUE森林
3.PURPLE體育館
4.RED家庭餐廳
問題:紅色卡牌家庭餐廳(點數9~10)的測試不知道要怎麼寫成模擬兩顆假骰子一起骰,Mockito的部分還在想要怎麼寫