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

add 4ColorsCard usecase #99

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open

add 4ColorsCard usecase #99

wants to merge 7 commits into from

Conversation

ChanWu77
Copy link
Contributor

我在GameTest補上4種不同顏色卡的測試案例:
1.GREEN:麵包店
2.BLUE森林
3.PURPLE體育館
4.RED家庭餐廳
問題:紅色卡牌家庭餐廳(點數9~10)的測試不知道要怎麼寫成模擬兩顆假骰子一起骰,Mockito的部分還在想要怎麼寫

Copy link
Collaborator

@shmily7829 shmily7829 left a 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 Show resolved Hide resolved
game.rollDice(playerB.getId(), 1);

// then
int bakerySize = handCard.getEstablishments(Bakery.class).size();
Copy link
Collaborator

Choose a reason for hiding this comment

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

這裡不應該計算 bakerySize,而是手牌中 bakery 數量可獲得的金額,建議可改成 totalBakeryBonuses

Comment on lines 189 to 190
assertThat(playerB.getTotalCoins()).isEqualTo(2);
assertThat(game.getBank().getTotalCoin()).isEqualTo(originalBankCoins - bakerySize);
Copy link
Collaborator

Choose a reason for hiding this comment

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

  1. isEqualTo(2) 改為 isEqualTo(totalBakeryBonuses)
  2. bakerySize 改為 totalBakeryBonuses

當A骰子擲出點數為5時,
B可以從銀行得到2元,C可以從銀行得到1元
""")
void BLUE5_當B有2張森林B得到2元_當C有1張森林C得到1元() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

function name buleCardForestTest

Comment on lines 309 to 310
int point1 = dice1.throwDice();
int point2 = dice2.throwDice();
Copy link
Collaborator

Choose a reason for hiding this comment

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

可以移除

@shmily7829 shmily7829 changed the base branch from main to develop October 4, 2023 13:44
Copy link
Collaborator

@shmily7829 shmily7829 left a comment

Choose a reason for hiding this comment

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

Review done.

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();
Copy link
Collaborator

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);
Copy link
Collaborator

Choose a reason for hiding this comment

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

放在 mock 骰子物件下方。
這不是 when 的程式碼,而是 given 模擬的資料。
整個檔案出現類似的程式碼都套用這個規則


// then
int totalBakeryBonuses = handCard.getEstablishments(Bakery.class).size();
assertThat(playerB.getTotalCoins()).isEqualTo(2);
Copy link
Collaborator

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 都套用此規則

Copy link
Contributor Author

Choose a reason for hiding this comment

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

調整DisplayName說明清楚

Comment on lines 274 to 276
playerC.payCoin(2);
playerB.payCoin(2);
playerA.gainCoin(4);
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit,
體育館的發動效果沒有在 takeAllPlayersEffect() 裡面是正常的嗎?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

已新增takeEffectPurple方法

Comment on lines 241 to 242
當玩家B有2張森林
當玩家C有1張森林
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit
測試 PlayerA 體育館的效果,PlayerB、C 可以不用有手牌也可以測試體育館效果。


@Test
@DisplayName("""
當玩家A有2張麵包店跟火車站,且輪到A擲骰子
Copy link
Collaborator

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);
Copy link
Collaborator

@shmily7829 shmily7829 Oct 17, 2023

Choose a reason for hiding this comment

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

  1. 應該要在 Game new 出來之後火車站才能翻牌,並且需要使用 Game 物件裡面的 bank

Comment on lines 320 to 321
assertThat(playerA.getTotalCoins()).isEqualTo(4);
assertThat(playerB.getTotalCoins()).isEqualTo(2);
Copy link
Collaborator

Choose a reason for hiding this comment

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

PlayerA 的 4 元和 PlayerB 的 2 元如何得出的?

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();
Copy link
Collaborator

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);
Copy link
Collaborator

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 的時候建立模擬丟骰子的資料

@ChanWu77 ChanWu77 requested a review from shmily7829 November 1, 2023 11:51
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.

2 participants