Writing more tests.
This commit is contained in:
@ -1239,6 +1239,62 @@ void test_pokerWinnerGetForPlayer_should_CalculateRoyalFlush(void) {
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_TEN, winning.set[4]);
|
||||
}
|
||||
|
||||
void test_pokerWinnerCompare_should_CompareWinningHands(void) {
|
||||
poker2_t poker;
|
||||
uint8_t p0i, p1i;
|
||||
poker2player_t *p0;
|
||||
poker2player_t *p1;
|
||||
poker2playerwinning_t w0, w1;
|
||||
card_t kicker;
|
||||
|
||||
// Construct two hands of the same type (pairs of eights)
|
||||
pokerInit(&poker);
|
||||
p0i = pokerPlayerAdd(&poker);
|
||||
p1i = pokerPlayerAdd(&poker);
|
||||
p0 = poker.players + p0i;
|
||||
p1 = poker.players + p1i;
|
||||
|
||||
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;
|
||||
|
||||
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
|
||||
|
||||
// Confirm both hands are pairs.
|
||||
pokerWinnerGetForPlayer(&poker, p0, &w0);
|
||||
pokerWinnerGetForPlayer(&poker, p1, &w1);
|
||||
TEST_ASSERT_EQUAL_UINT8(POKER_WINNING_TYPE_PAIR, w0.type);
|
||||
TEST_ASSERT_EQUAL_UINT8(POKER_WINNING_TYPE_PAIR, w1.type);
|
||||
TEST_ASSERT_EQUAL_UINT8(w0.type, w1.type);
|
||||
|
||||
// Get the kicker, should be the king.
|
||||
kicker = debug_pokerWinnerCompare(&w0, &w1);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_CLUBS_KING, kicker);
|
||||
|
||||
// Change the kickers
|
||||
p0->cards[1] = CARD_HEARTS_ACE;
|
||||
p1->cards[1] = CARD_CLUBS_KING;
|
||||
pokerWinnerGetForPlayer(&poker, p0, &w0);
|
||||
pokerWinnerGetForPlayer(&poker, p1, &w1);
|
||||
kicker = debug_pokerWinnerCompare(&w0, &w1);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_HEARTS_ACE, kicker);
|
||||
|
||||
// Low left weight
|
||||
p0->cards[1] = CARD_HEARTS_JACK;
|
||||
pokerWinnerGetForPlayer(&poker, p0, &w0);
|
||||
kicker = debug_pokerWinnerCompare(&w0, &w1);
|
||||
TEST_ASSERT_EQUAL_UINT8(0xFF, kicker);
|
||||
}
|
||||
|
||||
int test_poker2() {
|
||||
UNITY_BEGIN();
|
||||
|
||||
@ -1289,6 +1345,7 @@ int test_poker2() {
|
||||
RUN_TEST(test_pokerWinnerGetForPlayer_should_CalculateFourOfAKind);
|
||||
RUN_TEST(test_pokerWinnerGetForPlayer_should_CalculateStraightFlush);
|
||||
RUN_TEST(test_pokerWinnerGetForPlayer_should_CalculateRoyalFlush);
|
||||
RUN_TEST(test_pokerWinnerCompare_should_CompareWinningHands);
|
||||
|
||||
return UNITY_END();
|
||||
}
|
Reference in New Issue
Block a user