-
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?
Changes from 6 commits
1201a5a
a7da8c4
9a936f4
951637f
3e924c2
65f1c58
16bf948
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,9 @@ | ||
package domain; | ||
|
||
import domain.card.establishment.AppleOrchard; | ||
import domain.card.establishment.Bakery; | ||
import domain.card.establishment.Cafe; | ||
import domain.card.establishment.ConvenienceStore; | ||
import domain.card.establishment.Establishment; | ||
import domain.card.establishment.WheatField; | ||
import domain.card.establishment.*; | ||
import domain.card.landmark.Landmark; | ||
import domain.card.landmark.ShoppingMall; | ||
import domain.card.landmark.TrainStation; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mockito; | ||
|
@@ -159,4 +155,169 @@ void test1() { | |
assertThat(game.getBank().getTotalCoin()).isEqualTo(originalBankCoins - effectCoins); | ||
|
||
} | ||
|
||
@Test | ||
@DisplayName(""" | ||
當玩家B有2張麵包店,且輪到B擲骰子 | ||
當骰子擲出點數為2時 | ||
B可以從銀行得到2元 | ||
""") | ||
void greenCardbackeryCardTest() { | ||
// given | ||
Dice dice = Mockito.mock(Dice.class); | ||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. 整個檔案中有用到的 Player 物件可以抽成屬性,並在 @Beforecach 內賦值 private Player playerA;
@BeforeEach
void setup() {
playerA = Player.builder()
.id("A01")
.name("A")
.build();
} |
||
|
||
Game game = Game.builder() | ||
.players(List.of(playerB)) | ||
.turnPlayer(playerB) | ||
.currentDicePoint(2) | ||
.dices(List.of(dice)) | ||
.bank(new Bank()) | ||
.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 commentThe reason will be displayed to describe this comment to others. Learn more. 放在 mock 骰子物件下方。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
game.rollDice(playerB.getId(), false); | ||
|
||
// 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 commentThe reason will be displayed to describe this comment to others. Learn more.
整個檔案內的 assertion 都套用此規則 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 調整DisplayName說明清楚 |
||
assertThat(game.getBank().getTotalCoin()).isEqualTo(originalBankCoins - totalBakeryBonuses); | ||
} | ||
|
||
@Test | ||
@DisplayName(""" | ||
當玩家A有2張麵包店,且輪到A擲骰子 | ||
當玩家B有2張森林 | ||
當玩家C有1張森林 | ||
當A骰子擲出點數為5時, | ||
B可以從銀行得到2元,C可以從銀行得到1元 | ||
""") | ||
void buleCardForestTest() { | ||
// given | ||
Dice dice = Mockito.mock(Dice.class); | ||
|
||
HandCard handCardA = new HandCard(); | ||
handCardA.addHandCard(new Bakery()); | ||
handCardA.addHandCard(new Bakery()); | ||
Player playerA = Player.builder().id("A01").name("A").coins(0).handCard(handCardA).build(); | ||
HandCard handCardB = new HandCard(); | ||
handCardB.addHandCard(new Forest()); | ||
handCardB.addHandCard(new Forest()); | ||
Player playerB = Player.builder().id("B01").name("B").coins(0).handCard(handCardB).build(); | ||
HandCard handCardC = new HandCard(); | ||
handCardC.addHandCard(new Forest()); | ||
Player playerC = Player.builder().id("C01").name("C").coins(0).handCard(handCardC).build(); | ||
|
||
Game game = Game.builder() | ||
.players(List.of(playerA, playerB, playerC)) | ||
.turnPlayer(playerA) | ||
.currentDicePoint(5) | ||
.dices(List.of(dice)) | ||
.bank(new Bank()) | ||
.build(); | ||
|
||
var originalBankCoins = game.getBank().getTotalCoin(); | ||
|
||
// when | ||
Mockito.when(dice.throwDice()).thenReturn(5); | ||
game.rollDice(playerA.getId(), false); | ||
|
||
// then | ||
assertThat(playerA.getTotalCoins()).isEqualTo(0); | ||
assertThat(playerB.getTotalCoins()).isEqualTo(2); | ||
assertThat(playerC.getTotalCoins()).isEqualTo(1); | ||
} | ||
|
||
@Test | ||
@DisplayName(""" | ||
當玩家A有1張體育館,且輪到A擲骰子 | ||
當玩家B有2張森林 | ||
當玩家C有1張森林 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit |
||
當A骰子擲出點數為6時, | ||
B跟C玩家各自要給A 2元 | ||
""") | ||
void purpleStatdiumTest() { | ||
// given | ||
Dice dice = Mockito.mock(Dice.class); | ||
|
||
HandCard handCardA = new HandCard(); | ||
handCardA.addHandCard(new Stadium()); | ||
Player playerA = Player.builder().id("A01").name("A").coins(0).handCard(handCardA).build(); | ||
HandCard handCardB = new HandCard(); | ||
handCardB.addHandCard(new Forest()); | ||
handCardB.addHandCard(new Forest()); | ||
Player playerB = Player.builder().id("B01").name("B").coins(10).handCard(handCardB).build(); | ||
HandCard handCardC = new HandCard(); | ||
handCardC.addHandCard(new Forest()); | ||
Player playerC = Player.builder().id("C01").name("C").coins(6).handCard(handCardC).build(); | ||
|
||
Game game = Game.builder() | ||
.players(List.of(playerA, playerB, playerC)) | ||
.turnPlayer(playerA) | ||
.currentDicePoint(6) | ||
.dices(List.of(dice)) | ||
.bank(new Bank()) | ||
.build(); | ||
|
||
var originalBankCoins = game.getBank().getTotalCoin(); | ||
|
||
// when | ||
Mockito.when(dice.throwDice()).thenReturn(6); | ||
game.rollDice(playerA.getId(), false); | ||
playerC.payCoin(2); | ||
playerB.payCoin(2); | ||
playerA.gainCoin(4); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 已新增takeEffectPurple方法 |
||
// then | ||
assertThat(playerA.getTotalCoins()).isEqualTo(4); | ||
assertThat(playerB.getTotalCoins()).isEqualTo(8); | ||
assertThat(playerC.getTotalCoins()).isEqualTo(4); | ||
} | ||
|
||
@Test | ||
@DisplayName(""" | ||
當玩家A有2張麵包店跟火車站,且輪到A擲骰子 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit, |
||
當玩家B有1張家庭餐廳 | ||
當A骰子擲出點數為10時, | ||
A要給B 2塊 | ||
""") | ||
void redCardFamilyRestaurantTest() { | ||
// given | ||
Dice dice1 = Mockito.mock(Dice.class); | ||
Dice dice2 = Mockito.mock(Dice.class); | ||
Bank bank = new Bank(); | ||
HandCard handCardA = new HandCard(); | ||
handCardA.addHandCard(new Bakery()); | ||
handCardA.addHandCard(new Bakery()); | ||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
HandCard handCardB = new HandCard(); | ||
handCardB.addHandCard(new FamilyRestaurant()); | ||
Player playerB = Player.builder().id("B01").name("B").coins(0).handCard(handCardB).build(); | ||
|
||
Game game = Game.builder() | ||
.players(List.of(playerA, playerB)) | ||
.turnPlayer(playerA) | ||
.currentDicePoint(10) | ||
.dices(List.of(dice1, dice2)) | ||
.bank(bank) | ||
.build(); | ||
|
||
// when | ||
Mockito.when(dice1.throwDice()).thenReturn(5); | ||
Mockito.when(dice2.throwDice()).thenReturn(5); | ||
game.rollDice(playerA.getId(), true); | ||
|
||
//then | ||
assertThat(playerA.getTotalCoins()).isEqualTo(4); | ||
assertThat(playerB.getTotalCoins()).isEqualTo(2); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PlayerA 的 4 元和 PlayerB 的 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、B、C 物件可以抽成屬性,在 @beforeach 內賦值。
如果有測試案例用到 Player 就直接取用這些屬性。
整個檔案出現類似的程式碼都套用這個規則。
在各自的測試方法內呼叫 addCardToHandCard() 加入 handCard