Writing winner logic.
This commit is contained in:
@ -1295,6 +1295,83 @@ void test_pokerWinnerCompare_should_CompareWinningHands(void) {
|
||||
TEST_ASSERT_EQUAL_UINT8(0xFF, kicker);
|
||||
}
|
||||
|
||||
void test_pokerWinnerDetermine_should_DecideTheWinnerCorrectly(void) {
|
||||
poker2_t poker;
|
||||
uint8_t p0i, p1i;
|
||||
poker2player_t *p0;
|
||||
poker2player_t *p1;
|
||||
|
||||
// Outputs
|
||||
uint8_t winnerCount, participantCount;
|
||||
uint8_t winnerPlayers[POKER_PLAYER_COUNT_MAX];
|
||||
uint8_t participants[POKER_PLAYER_COUNT_MAX];
|
||||
poker2playerwinning_t winners[POKER_PLAYER_COUNT_MAX];
|
||||
|
||||
// Set up the players
|
||||
pokerInit(&poker);
|
||||
p0i = pokerPlayerAdd(&poker);
|
||||
p1i = pokerPlayerAdd(&poker);
|
||||
|
||||
p0 = poker.players + p0i;
|
||||
p1 = poker.players + p1i;
|
||||
|
||||
pokerPotAddPlayer(poker.pots + 0, p0i);
|
||||
pokerPotAddPlayer(poker.pots + 0, p1i);
|
||||
|
||||
pokerPlayerChipsAdd(p0, 10000);
|
||||
pokerPlayerChipsAdd(p1, 10000);
|
||||
|
||||
// Set up the community
|
||||
poker.communitySize = 5;
|
||||
poker.community[0] = CARD_HEARTS_TWO;
|
||||
poker.community[1] = CARD_DIAMONDS_NINE;
|
||||
poker.community[2] = CARD_DIAMONDS_FOUR;
|
||||
poker.community[3] = CARD_CLUBS_SIX;
|
||||
poker.community[4] = CARD_HEARTS_EIGHT;
|
||||
|
||||
// Set up the player hands
|
||||
p0->cardCount = 2;
|
||||
p0->cards[0] = CARD_CLUBS_EIGHT;
|
||||
p0->cards[1] = CARD_CLUBS_KING;//Higher, Kicker
|
||||
|
||||
p1->cardCount = 2;
|
||||
p1->cards[0] = CARD_SPADES_EIGHT;
|
||||
p1->cards[1] = CARD_CLUBS_QUEEN;//Low, not
|
||||
|
||||
// Run first test.
|
||||
pokerWinnerDetermineForPot(
|
||||
&poker, poker.pots + 0,
|
||||
winners, winnerPlayers, &winnerCount,
|
||||
participants, &participantCount
|
||||
);
|
||||
|
||||
TEST_ASSERT_EQUAL_UINT8(1, winnerCount);
|
||||
TEST_ASSERT_EQUAL_UINT8(2, participantCount);
|
||||
TEST_ASSERT_EQUAL_UINT8(POKER_WINNING_TYPE_PAIR, winners[0].type);
|
||||
TEST_ASSERT_EQUAL_UINT8(POKER_WINNING_TYPE_PAIR, winners[1].type);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_CLUBS_KING, winners[0].kicker);
|
||||
TEST_ASSERT_EQUAL_UINT8(0, winnerPlayers[0]);
|
||||
TEST_ASSERT_EQUAL_UINT8(0, participants[0]);
|
||||
TEST_ASSERT_EQUAL_UINT8(1, participants[1]);
|
||||
|
||||
// ----- //
|
||||
// Test a difference in hands.
|
||||
p1->cards[1] = CARD_CLUBS_NINE;// Makes p1 have two pair.
|
||||
pokerWinnerDetermineForPot(
|
||||
&poker, poker.pots + 0,
|
||||
winners, winnerPlayers, &winnerCount,
|
||||
participants, &participantCount
|
||||
);
|
||||
TEST_ASSERT_EQUAL_UINT8(1, winnerCount);
|
||||
TEST_ASSERT_EQUAL_UINT8(2, participantCount);
|
||||
TEST_ASSERT_EQUAL_UINT8(POKER_WINNING_TYPE_PAIR, winners[0].type);
|
||||
TEST_ASSERT_EQUAL_UINT8(POKER_WINNING_TYPE_TWO_PAIR, winners[1].type);
|
||||
TEST_ASSERT_EQUAL_UINT8(1, winnerPlayers[0]);
|
||||
TEST_ASSERT_EQUAL_UINT8(0, participants[0]);
|
||||
TEST_ASSERT_EQUAL_UINT8(1, participants[1]);
|
||||
}
|
||||
|
||||
|
||||
int test_poker2() {
|
||||
UNITY_BEGIN();
|
||||
|
||||
@ -1346,6 +1423,7 @@ int test_poker2() {
|
||||
RUN_TEST(test_pokerWinnerGetForPlayer_should_CalculateStraightFlush);
|
||||
RUN_TEST(test_pokerWinnerGetForPlayer_should_CalculateRoyalFlush);
|
||||
RUN_TEST(test_pokerWinnerCompare_should_CompareWinningHands);
|
||||
RUN_TEST(test_pokerWinnerDetermine_should_DecideTheWinnerCorrectly);
|
||||
|
||||
return UNITY_END();
|
||||
}
|
Reference in New Issue
Block a user