More poker tests.

This commit is contained in:
2021-10-02 17:09:35 -07:00
parent 1d56e068fa
commit 771ddc1091
3 changed files with 51 additions and 7 deletions

View File

@ -71,4 +71,5 @@ void pokerPlayerChipsAdd(poker2player_t *player, int32_t chips);
void pokerPlayerDealAll(poker2_t *poker, uint8_t count);
void pokerPlayerBetPot(
poker2_t *poker, poker2pot_t *pot, uint8_t playerIndex, int32_t chips
);
);
void pokerPlayerBet(poker2_t *poker, uint8_t playerIndex, int32_t chips);

View File

@ -192,7 +192,7 @@ void test_pokerPlayerChipsAdd_should_TurnOutStateOff(void) {
TEST_ASSERT_BIT_LOW(POKER_PLAYER_STATE_OUT, player->state);
}
void test_pokerPLayerDealAll_should_DealCardsToEveryone(void) {
void test_pokerPlayerDealAll_should_DealCardsToEveryone(void) {
poker2_t poker;
pokerInit(&poker);
@ -215,7 +215,7 @@ void test_pokerPLayerDealAll_should_DealCardsToEveryone(void) {
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_QUEEN, poker.players[2].cards[0]);
}
void test_pokerPLayerDealAll_should_DealMultipleCardsToEveryone(void) {
void test_pokerPlayerDealAll_should_DealMultipleCardsToEveryone(void) {
poker2_t poker;
pokerInit(&poker);
@ -239,7 +239,48 @@ void test_pokerPLayerDealAll_should_DealMultipleCardsToEveryone(void) {
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_NINE, poker.players[2].cards[1]);
}
int test_poker2() {
void test_pokerPlayerBetPot_should_AddChipsToThePot(void) {
poker2_t poker;
poker2pot_t *pot;
poker2player_t *player;
uint8_t i;
pokerInit(&poker);
pot = poker.pots;
i = pokerPlayerAdd(&poker);
player = poker.players + i;
pokerPlayerChipsAdd(player, 1000);
TEST_ASSERT_EQUAL_INT32(0, pot->chips);
TEST_ASSERT_EQUAL_INT32(1000, player->chips);
pokerPlayerBetPot(&poker, pot, i, 100);
TEST_ASSERT_EQUAL_INT32(100, pot->chips);
TEST_ASSERT_EQUAL_INT32(900, player->chips);
}
void test_pokerPlayerBet_should_BetToTheActivePot(void) {
poker2_t poker;
poker2pot_t *pot;
uint8_t i, j;
pokerInit(&poker);
i = pokerPlayerAdd(&poker);
pokerPlayerChipsAdd(poker.players+i, 1000);
pot = poker.pots;
TEST_ASSERT_EQUAL_INT32(0, pot->chips);
pokerPlayerBet(&poker, i, 100);
TEST_ASSERT_EQUAL_INT32(100, pot->chips);
j = pokerPotAdd(&poker);
pokerPlayerBet(&poker, i, 50);
TEST_ASSERT_EQUAL_INT32(100, pot->chips);
pot = poker.pots + j;
TEST_ASSERT_EQUAL_INT32(50, pot->chips);
}
int test_poker() {
UNITY_BEGIN();
RUN_TEST(test_pokerInit_should_InitializePokerGame);
@ -253,8 +294,10 @@ int test_poker2() {
RUN_TEST(test_pokerPlayerDeal_should_DealCardsToThePlayer);
RUN_TEST(test_pokerPlayerChipsAdd_should_AddChipsToThePlayer);
RUN_TEST(test_pokerPlayerChipsAdd_should_TurnOutStateOff);
RUN_TEST(test_pokerPLayerDealAll_should_DealCardsToEveryone);
RUN_TEST(test_pokerPLayerDealAll_should_DealMultipleCardsToEveryone);
RUN_TEST(test_pokerPlayerDealAll_should_DealCardsToEveryone);
RUN_TEST(test_pokerPlayerDealAll_should_DealMultipleCardsToEveryone);
RUN_TEST(test_pokerPlayerBetPot_should_AddChipsToThePot);
RUN_TEST(test_pokerPlayerBet_should_BetToTheActivePot);
return UNITY_END();
}

View File

@ -11,6 +11,6 @@
int main() {
return (
test_card() ||
test_poker2()
test_poker()
) || 0;
}