Writing more poker tests.

This commit is contained in:
2021-10-01 22:31:01 -07:00
parent a2646d5952
commit 2168cb5b8f
3 changed files with 107 additions and 2 deletions

View File

@ -10,6 +10,7 @@
void pokerInit(poker2_t *poker) {
pokerResetRound(poker);
poker->playerCount = 0;
poker->state = 0;
}
void pokerResetRound(poker2_t *poker) {
@ -77,8 +78,6 @@ void pokerPlayerChipsAdd(poker2player_t *player, int32_t chips) {
player->chips += chips;
if(player->chips > 0) {
flagOff(player->state, POKER_PLAYER_STATE_OUT);
} else {
player->state |= POKER_PLAYER_STATE_OUT;
}
}

View File

@ -49,6 +49,8 @@ typedef struct {
poker2player_t players[POKER_PLAYER_COUNT_MAX];
uint8_t playerCount;
uint8_t state;
} poker2_t;

View File

@ -11,6 +11,7 @@ void test_pokerInit_should_InitializePokerGame(void) {
poker2_t poker;
pokerInit(&poker);
TEST_ASSERT_EQUAL_INT8(0, poker.playerCount);
TEST_ASSERT_EQUAL_INT8(0, poker.state);
}
void test_pokerResetRound_should_ResetTheRound(void) {
@ -93,6 +94,104 @@ void test_pokerPlayerAdd_should_ResetThePlayer(void) {
TEST_ASSERT_EQUAL_UINT8(0, player->cardCount);
}
void test_pokerTurn_should_TurnCardsFromTheDeck(void) {
poker2_t poker;
pokerInit(&poker);
TEST_ASSERT_EQUAL_UINT8(CARD_DECK_SIZE, poker.deckSize);
TEST_ASSERT_EQUAL_UINT8(0, poker.communitySize);
pokerTurn(&poker, 1);
TEST_ASSERT_EQUAL_UINT8(CARD_DECK_SIZE - 1, poker.deckSize);
TEST_ASSERT_EQUAL_UINT8(1, poker.communitySize);
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_ACE, poker.community[0]);
pokerTurn(&poker, 3);
TEST_ASSERT_EQUAL_UINT8(CARD_DECK_SIZE - 4, poker.deckSize);
TEST_ASSERT_EQUAL_UINT8(4, poker.communitySize);
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_KING, poker.community[1]);
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_QUEEN, poker.community[2]);
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_JACK, poker.community[3]);
}
void test_pokerBurn_should_SendCardsToTheGrave(void) {
poker2_t poker;
pokerInit(&poker);
TEST_ASSERT_EQUAL_UINT8(CARD_DECK_SIZE, poker.deckSize);
TEST_ASSERT_EQUAL_UINT8(0, poker.graveSize);
pokerBurn(&poker, 1);
TEST_ASSERT_EQUAL_UINT8(CARD_DECK_SIZE - 1, poker.deckSize);
TEST_ASSERT_EQUAL_UINT8(1, poker.graveSize);
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_ACE, poker.grave[0]);
pokerBurn(&poker, 3);
TEST_ASSERT_EQUAL_UINT8(CARD_DECK_SIZE - 4, poker.deckSize);
TEST_ASSERT_EQUAL_UINT8(4, poker.graveSize);
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_KING, poker.grave[1]);
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_QUEEN, poker.grave[2]);
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_JACK, poker.grave[3]);
}
void test_pokerPlayerDeal_should_DealCardsToThePlayer(void) {
poker2_t poker;
uint8_t playerIndex;
poker2player_t *player;
pokerInit(&poker);
playerIndex = pokerPlayerAdd(&poker);
player = poker.players + playerIndex;
TEST_ASSERT_EQUAL_UINT8(CARD_DECK_SIZE, poker.deckSize);
TEST_ASSERT_EQUAL_UINT8(0, player->cardCount);
pokerPlayerDeal(&poker, player, 0x01);
TEST_ASSERT_EQUAL_UINT8(CARD_DECK_SIZE - 1, poker.deckSize);
TEST_ASSERT_EQUAL_UINT8(1, player->cardCount);
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_ACE, player->cards[0]);
pokerPlayerDeal(&poker, player, 0x01);
TEST_ASSERT_EQUAL_UINT8(CARD_DECK_SIZE - 2, poker.deckSize);
TEST_ASSERT_EQUAL_UINT8(2, player->cardCount);
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_KING, player->cards[1]);
}
void test_pokerPlayerChipsAdd_should_AddChipsToThePlayer(void) {
poker2_t poker;
uint8_t playerIndex;
poker2player_t *player;
pokerInit(&poker);
playerIndex = pokerPlayerAdd(&poker);
player = poker.players + playerIndex;
TEST_ASSERT_EQUAL_INT32(0, player->chips);
pokerPlayerChipsAdd(player, 32);
TEST_ASSERT_EQUAL_INT32(32, player->chips);
pokerPlayerChipsAdd(player, 10);
TEST_ASSERT_EQUAL_INT32(42, player->chips);
pokerPlayerChipsAdd(player, -30);
TEST_ASSERT_EQUAL_INT32(12, player->chips);
}
void test_pokerPlayerChipsAdd_should_TurnOutStateOff(void) {
poker2_t poker;
uint8_t playerIndex;
poker2player_t *player;
pokerInit(&poker);
playerIndex = pokerPlayerAdd(&poker);
player = poker.players + playerIndex;
player->state |= POKER_PLAYER_STATE_OUT;
TEST_ASSERT_EQUAL(true, player->state & POKER_PLAYER_STATE_OUT);
pokerPlayerChipsAdd(player, 32);
TEST_ASSERT_EQUAL(false, player->state & POKER_PLAYER_STATE_OUT);
}
int test_poker2() {
UNITY_BEGIN();
@ -102,6 +201,11 @@ int test_poker2() {
RUN_TEST(test_pokerPotAdd_should_ResetThePot);
RUN_TEST(test_pokerPotAddPlayer_should_AddAPlayer);
RUN_TEST(test_pokerPlayerAdd_should_ResetThePlayer);
RUN_TEST(test_pokerTurn_should_TurnCardsFromTheDeck);
RUN_TEST(test_pokerBurn_should_SendCardsToTheGrave);
RUN_TEST(test_pokerPlayerDeal_should_DealCardsToThePlayer);
RUN_TEST(test_pokerPlayerChipsAdd_should_AddChipsToThePlayer);
RUN_TEST(test_pokerPlayerChipsAdd_should_TurnOutStateOff);
return UNITY_END();
}