From 771ddc1091873a09a16246481e58c7392cbe6f09 Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Sat, 2 Oct 2021 17:09:35 -0700 Subject: [PATCH] More poker tests. --- src/poker2/poker.h | 3 ++- test/poker2/poker.c | 53 ++++++++++++++++++++++++++++++++++++++++----- test/tests.c | 2 +- 3 files changed, 51 insertions(+), 7 deletions(-) diff --git a/src/poker2/poker.h b/src/poker2/poker.h index 9f8ebb22..fb5019fa 100644 --- a/src/poker2/poker.h +++ b/src/poker2/poker.h @@ -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 -); \ No newline at end of file +); +void pokerPlayerBet(poker2_t *poker, uint8_t playerIndex, int32_t chips); \ No newline at end of file diff --git a/test/poker2/poker.c b/test/poker2/poker.c index 1bd6d210..18d0289f 100644 --- a/test/poker2/poker.c +++ b/test/poker2/poker.c @@ -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(); } \ No newline at end of file diff --git a/test/tests.c b/test/tests.c index 67598416..5bf81215 100644 --- a/test/tests.c +++ b/test/tests.c @@ -11,6 +11,6 @@ int main() { return ( test_card() || - test_poker2() + test_poker() ) || 0; } \ No newline at end of file