Improved bet tests.

This commit is contained in:
2021-10-14 22:51:47 -07:00
parent 466cb1e2b9
commit 02401337a8
3 changed files with 70 additions and 63 deletions

View File

@ -36,7 +36,7 @@ void pokerBet(
player->currentBet += chips;
pot->chips += chips;
pot->call = mathMax(pot->call, chips);
pot->call = mathMax(pot->call, player->currentBet);
pokerPotAddPlayer(pot, playerIndex);
player->state |= POKER_PLAYER_STATE_HAS_BET_THIS_ROUND;
@ -53,13 +53,14 @@ int32_t pokerBetGetCurrentCallValue(poker_t *poker) {
uint8_t i;
int32_t call;
call = 0;
for(i = 0; i < poker->playerCount; i++) {
call = mathMax(call, poker->players[i].currentBet);
for(i = 0; i < poker->potCount; i++) {
call = mathMax(call, poker->pots[i].call);
}
return call;
}
//eh
int32_t pokerPlayerGetCallBet(poker_t *poker, pokerplayer_t *player) {
return pokerBetGetCurrentCallValue(poker) - player->currentBet;

View File

@ -102,28 +102,59 @@ void test_pokerBetGetRemainingBetterCount_should_ReturnCountNeedsToBet(void){
void test_pokerBet_should_AddChipsToThePot(void) {
poker_t poker;
pokerpot_t *pot;
pokerplayer_t *player;
uint8_t i;
pokerplayer_t *p0;
pokerplayer_t *p1;
uint8_t p0i, p1i;
pokerInit(&poker);
pot = poker.pots;
i = pokerPlayerAdd(&poker);
player = poker.players + i;
pokerPlayerChipsAdd(player, 1000);
p0i = pokerPlayerAdd(&poker);
p1i = pokerPlayerAdd(&poker);
p0 = poker.players + p0i;
p1 = poker.players + p1i;
pokerPlayerChipsAdd(p0, 1000);
pokerPlayerChipsAdd(p1, 1000);
TEST_ASSERT_EQUAL_INT32(0, pot->chips);
TEST_ASSERT_EQUAL_INT32(0, pot->call);
TEST_ASSERT_EQUAL_INT32(1000, player->chips);
TEST_ASSERT_EQUAL_INT32(1000, p0->chips);
TEST_ASSERT_EQUAL_INT32(1000, p1->chips);
pokerBet(&poker, pot, i, 100);
pokerBet(&poker, pot, p0i, 100);
TEST_ASSERT_EQUAL_INT32(100, pot->chips);
TEST_ASSERT_EQUAL_INT32(100, pot->call);
TEST_ASSERT_EQUAL_INT32(900, player->chips);
TEST_ASSERT_EQUAL_INT32(900, p0->chips);
TEST_ASSERT_EQUAL_INT32(1000, p1->chips);
pokerBet(&poker, pot, i, 100);
pokerBet(&poker, pot, p0i, 100);
TEST_ASSERT_EQUAL_INT32(200, pot->chips);
TEST_ASSERT_EQUAL_INT32(100, pot->call);
TEST_ASSERT_EQUAL_INT32(800, player->chips);
TEST_ASSERT_EQUAL_INT32(200, pot->call);
TEST_ASSERT_EQUAL_INT32(800, p0->chips);
TEST_ASSERT_EQUAL_INT32(1000, p1->chips);
pokerBet(&poker, pot, p1i, 300);
TEST_ASSERT_EQUAL_INT32(500, pot->chips);
TEST_ASSERT_EQUAL_INT32(300, pot->call);
TEST_ASSERT_EQUAL_INT32(800, p0->chips);
TEST_ASSERT_EQUAL_INT32(700, p1->chips);
// Second pot
pot = poker.pots + pokerPotAdd(&poker);
pokerBet(&poker, pot, p0i, 300);
TEST_ASSERT_EQUAL_INT32(300, pot->chips);
TEST_ASSERT_EQUAL_INT32(500, pot->call);
TEST_ASSERT_EQUAL_INT32(500, p0->chips);
TEST_ASSERT_EQUAL_INT32(700, p1->chips);
pokerBet(&poker, pot, p1i, 400);
TEST_ASSERT_EQUAL_INT32(700, pot->chips);
TEST_ASSERT_EQUAL_INT32(700, pot->call);
TEST_ASSERT_EQUAL_INT32(500, p0->chips);
TEST_ASSERT_EQUAL_INT32(300, p1->chips);
}
void test_pokerBet_should_UpdatePlayerState(void) {
@ -171,16 +202,39 @@ void test_pokerBetForPlayer_should_BetToTheActivePot(void) {
TEST_ASSERT_EQUAL_INT32(50, pot->chips);
}
void test_pokerBetGetCurrentCallValue_should_CalculateTheCallValue(void) {
poker_t poker;
uint8_t first, second;
pokerInit(&poker);
first = pokerPlayerAdd(&poker);
second = pokerPlayerAdd(&poker);
pokerPlayerChipsAdd(poker.players + first, 10000);
pokerPlayerChipsAdd(poker.players + second, 10000);
TEST_ASSERT_EQUAL_INT32(0, pokerBetGetCurrentCallValue(&poker));
pokerBetForPlayer(&poker, first, 100);
TEST_ASSERT_EQUAL_INT32(100, pokerBetGetCurrentCallValue(&poker));
pokerBetForPlayer(&poker, second, 150);
TEST_ASSERT_EQUAL_INT32(150, pokerBetGetCurrentCallValue(&poker));
// Second Pot
pokerPotAdd(&poker);
TEST_ASSERT_EQUAL_INT32(150, pokerBetGetCurrentCallValue(&poker));
TEST_ASSERT_EQUAL_INT32(0, poker.pots[1].chips);
pokerBetForPlayer(&poker, second, 50);
TEST_ASSERT_EQUAL_INT32(200, pokerBetGetCurrentCallValue(&poker));
TEST_ASSERT_EQUAL_INT32(50, poker.pots[1].chips);
}
int test_bet_h() {
UNITY_BEGIN();
// RUN_TEST(test_pokerBetGetRemainingPlayer_should_ReturnRemainingBetters);
RUN_TEST(test_pokerBetGetNextPlayer_should_GetTheNextBetter);
RUN_TEST(test_pokerBetGetRemainingBetterCount_should_ReturnCountNeedsToBet);
RUN_TEST(test_pokerBet_should_AddChipsToThePot);
RUN_TEST(test_pokerBet_should_UpdatePlayerState);
RUN_TEST(test_pokerBetForPlayer_should_BetToTheActivePot);
RUN_TEST(test_pokerBetGetCurrentCallValue_should_CalculateTheCallValue);
return UNITY_END();
}

View File

@ -384,53 +384,6 @@ void test_pokerDealerBurn_should_SendCardsToTheGrave(void) {
}
void test_pokerBetGetCurrentCallValue_should_CalculateTheCallValue(void) {
poker_t poker;
uint8_t first, second;
pokerInit(&poker);
first = pokerPlayerAdd(&poker);
second = pokerPlayerAdd(&poker);
pokerPlayerChipsAdd(poker.players + first, 10000);
pokerPlayerChipsAdd(poker.players + second, 10000);
TEST_ASSERT_EQUAL_INT32(0, pokerBetGetCurrentCallValue(&poker));
pokerBetForPlayer(&poker, first, 100);
TEST_ASSERT_EQUAL_INT32(100, pokerBetGetCurrentCallValue(&poker));
pokerBetForPlayer(&poker, second, 150);
TEST_ASSERT_EQUAL_INT32(150, pokerBetGetCurrentCallValue(&poker));
pokerPotAdd(&poker);
TEST_ASSERT_EQUAL_INT32(150, pokerBetGetCurrentCallValue(&poker));
TEST_ASSERT_EQUAL_INT32(0, poker.pots[1].chips);
pokerBetForPlayer(&poker, second, 50);
TEST_ASSERT_EQUAL_INT32(200, pokerBetGetCurrentCallValue(&poker));
TEST_ASSERT_EQUAL_INT32(50, poker.pots[1].chips);
}
void test_pokerBetGetCurrentCallValue_should_SkipOutPlayers(void) {
poker_t poker;
uint8_t i;
pokerInit(&poker);
i = pokerPlayerAdd(&poker);
pokerPlayerChipsAdd(poker.players + i, 10000);
pokerBetForPlayer(&poker, i, 300);
i = pokerPlayerAdd(&poker);
pokerPlayerChipsAdd(poker.players + i, 10000);
pokerBetForPlayer(&poker, i, 500);
i = pokerPlayerAdd(&poker);
pokerPlayerChipsAdd(poker.players + i, 10000);
pokerBetForPlayer(&poker, i, 200);
TEST_ASSERT_EQUAL_INT32(500, pokerBetGetCurrentCallValue(&poker));
poker.players[1].state |= POKER_PLAYER_STATE_OUT;
TEST_ASSERT_EQUAL_INT32(300, pokerBetGetCurrentCallValue(&poker));
poker.players[0].state |= POKER_PLAYER_STATE_OUT;
TEST_ASSERT_EQUAL_INT32(200, pokerBetGetCurrentCallValue(&poker));
}
void test_pokerDeal_should_DealCardsToThePlayer(void) {
poker_t poker;
uint8_t playerIndex;
@ -1396,7 +1349,6 @@ int test_poker() {
RUN_TEST(test_pokerPlayerAdd_should_ResetThePlayer);
RUN_TEST(test_pokerDealerTurn_should_TurnCardsFromTheDeck);
RUN_TEST(test_pokerDealerBurn_should_SendCardsToTheGrave);
RUN_TEST(test_pokerBetGetCurrentCallValue_should_CalculateTheCallValue);
RUN_TEST(test_pokerDeal_should_DealCardsToThePlayer);
RUN_TEST(test_pokerPlayerChipsAdd_should_AddChipsToThePlayer);
RUN_TEST(test_pokerPlayerChipsAdd_should_TurnOutStateOff);