Finished writing tests for poker solver
This commit is contained in:
@ -345,6 +345,7 @@ void pokerWinnerGetForPlayer(
|
||||
number == CARD_ACE ? POKER_WINNING_TYPE_ROYAL_FLUSH :
|
||||
POKER_WINNING_TYPE_STRAIGHT_FLUSH
|
||||
);
|
||||
debug_WinnerFillRemaining(winning);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -386,7 +387,7 @@ void pokerWinnerGetForPlayer(
|
||||
// Winned?
|
||||
if(winning->setSize != POKER_WINNING_SET_SIZE) continue;
|
||||
winning->type = POKER_WINNING_TYPE_FULL_HOUSE;
|
||||
printf("Full House\n");
|
||||
debug_WinnerFillRemaining(winning);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -397,13 +398,13 @@ void pokerWinnerGetForPlayer(
|
||||
winning->setSize = 1;
|
||||
for(j = i+1; j < winning->fullSize; j++) {
|
||||
if(cardGetSuit(winning->full[j]) != suit) continue;
|
||||
winning->set[winning->setSize] = winning->full[j];
|
||||
winning->setSize++;
|
||||
winning->set[winning->setSize++] = winning->full[j];
|
||||
if(winning->setSize == POKER_WINNING_SET_SIZE) break;
|
||||
}
|
||||
if(winning->setSize < POKER_WINNING_SET_SIZE) continue;
|
||||
winning->set[0] = winning->full[0];
|
||||
winning->set[0] = winning->full[i];
|
||||
winning->type = POKER_WINNING_TYPE_FLUSH;
|
||||
debug_WinnerFillRemaining(winning);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1106,20 +1106,20 @@ void test_pokerWinnerGetForPlayer_should_CalculateAFlush(void) {
|
||||
|
||||
poker.communitySize = 5;
|
||||
poker.community[0] = CARD_HEARTS_ACE;
|
||||
poker.community[1] = CARD_SPADES_SIX;
|
||||
poker.community[2] = CARD_SPADES_THREE;
|
||||
poker.community[3] = CARD_SPADES_QUEEN;
|
||||
poker.community[1] = CARD_SPADES_SIX;//+2
|
||||
poker.community[2] = CARD_SPADES_THREE;//+3
|
||||
poker.community[3] = CARD_SPADES_QUEEN;//+1
|
||||
poker.community[4] = CARD_HEARTS_NINE;
|
||||
player->cardCount = 2;
|
||||
player->cards[0] = CARD_SPADES_TWO;
|
||||
player->cards[1] = CARD_SPADES_KING;
|
||||
player->cards[0] = CARD_SPADES_TWO;//+4
|
||||
player->cards[1] = CARD_SPADES_KING;//+0
|
||||
|
||||
pokerWinnerGetForPlayer(&poker, player, &winning);
|
||||
TEST_ASSERT_EQUAL_UINT8(POKER_WINNING_TYPE_FLUSH, winning.type);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_CLUBS_TWO, winning.set[0]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_DIAMONDS_TWO, winning.set[1]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_HEARTS_ACE, winning.set[2]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_ACE, winning.set[3]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_KING, winning.set[0]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_QUEEN, winning.set[1]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_SIX, winning.set[2]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_THREE, winning.set[3]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_TWO, winning.set[4]);
|
||||
}
|
||||
|
||||
@ -1136,12 +1136,12 @@ void test_pokerWinnerGet_should_CalculateFullHouse(void) {
|
||||
poker.communitySize = 5;
|
||||
poker.community[0] = CARD_HEARTS_ACE;
|
||||
poker.community[1] = CARD_SPADES_SIX;
|
||||
poker.community[2] = CARD_SPADES_THREE;
|
||||
poker.community[2] = CARD_SPADES_ACE;
|
||||
poker.community[3] = CARD_SPADES_QUEEN;
|
||||
poker.community[4] = CARD_HEARTS_NINE;
|
||||
poker.community[4] = CARD_DIAMONDS_TWO;
|
||||
player->cardCount = 2;
|
||||
player->cards[0] = CARD_SPADES_TWO;
|
||||
player->cards[1] = CARD_SPADES_KING;
|
||||
player->cards[1] = CARD_CLUBS_TWO;
|
||||
|
||||
pokerWinnerGetForPlayer(&poker, player, &winning);
|
||||
TEST_ASSERT_EQUAL_UINT8(POKER_WINNING_TYPE_FULL_HOUSE, winning.type);
|
||||
@ -1163,20 +1163,20 @@ void test_pokerWinnerGetForPlayer_should_CalculateFourOfAKind(void) {
|
||||
player = poker.players + i;
|
||||
|
||||
poker.communitySize = 5;
|
||||
poker.community[0] = CARD_HEARTS_ACE;
|
||||
poker.community[1] = CARD_SPADES_SIX;
|
||||
poker.community[2] = CARD_SPADES_THREE;
|
||||
poker.community[0] = CARD_HEARTS_TWO;
|
||||
poker.community[1] = CARD_DIAMONDS_TWO;
|
||||
poker.community[2] = CARD_SPADES_TWO;
|
||||
poker.community[3] = CARD_SPADES_QUEEN;
|
||||
poker.community[4] = CARD_HEARTS_NINE;
|
||||
poker.community[4] = CARD_SPADES_ACE;
|
||||
player->cardCount = 2;
|
||||
player->cards[0] = CARD_SPADES_TWO;
|
||||
player->cards[0] = CARD_CLUBS_TWO;
|
||||
player->cards[1] = CARD_SPADES_KING;
|
||||
|
||||
pokerWinnerGetForPlayer(&poker, player, &winning);
|
||||
TEST_ASSERT_EQUAL_UINT8(POKER_WINNING_TYPE_FOUR_OF_A_KIND, winning.type);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_CLUBS_TWO, winning.set[0]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_DIAMONDS_TWO, winning.set[1]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_HEARTS_ACE, winning.set[2]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_HEARTS_TWO, winning.set[2]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_ACE, winning.set[3]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_TWO, winning.set[4]);
|
||||
}
|
||||
@ -1192,22 +1192,22 @@ void test_pokerWinnerGetForPlayer_should_CalculateStraightFlush(void) {
|
||||
player = poker.players + i;
|
||||
|
||||
poker.communitySize = 5;
|
||||
poker.community[0] = CARD_HEARTS_ACE;
|
||||
poker.community[1] = CARD_SPADES_SIX;
|
||||
poker.community[2] = CARD_SPADES_THREE;
|
||||
poker.community[0] = CARD_DIAMONDS_ACE;
|
||||
poker.community[1] = CARD_HEARTS_SIX;
|
||||
poker.community[2] = CARD_HEARTS_THREE;
|
||||
poker.community[3] = CARD_SPADES_QUEEN;
|
||||
poker.community[4] = CARD_HEARTS_NINE;
|
||||
poker.community[4] = CARD_HEARTS_FOUR;
|
||||
player->cardCount = 2;
|
||||
player->cards[0] = CARD_SPADES_TWO;
|
||||
player->cards[1] = CARD_SPADES_KING;
|
||||
player->cards[0] = CARD_HEARTS_TWO;
|
||||
player->cards[1] = CARD_HEARTS_FIVE;
|
||||
|
||||
pokerWinnerGetForPlayer(&poker, player, &winning);
|
||||
TEST_ASSERT_EQUAL_UINT8(POKER_WINNING_TYPE_STRAIGHT_FLUSH, winning.type);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_CLUBS_TWO, winning.set[0]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_DIAMONDS_TWO, winning.set[1]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_HEARTS_ACE, winning.set[2]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_ACE, winning.set[3]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_TWO, winning.set[4]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_HEARTS_SIX, winning.set[0]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_HEARTS_FIVE, winning.set[1]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_HEARTS_FOUR, winning.set[2]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_HEARTS_THREE, winning.set[3]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_HEARTS_TWO, winning.set[4]);
|
||||
}
|
||||
|
||||
void test_pokerWinnerGetForPlayer_should_CalculateRoyalFlush(void) {
|
||||
@ -1221,22 +1221,22 @@ void test_pokerWinnerGetForPlayer_should_CalculateRoyalFlush(void) {
|
||||
player = poker.players + i;
|
||||
|
||||
poker.communitySize = 5;
|
||||
poker.community[0] = CARD_HEARTS_ACE;
|
||||
poker.community[1] = CARD_SPADES_SIX;
|
||||
poker.community[2] = CARD_SPADES_THREE;
|
||||
poker.community[0] = CARD_DIAMONDS_ACE;
|
||||
poker.community[1] = CARD_HEARTS_SIX;
|
||||
poker.community[2] = CARD_SPADES_TEN;
|
||||
poker.community[3] = CARD_SPADES_QUEEN;
|
||||
poker.community[4] = CARD_HEARTS_NINE;
|
||||
poker.community[4] = CARD_SPADES_JACK;
|
||||
player->cardCount = 2;
|
||||
player->cards[0] = CARD_SPADES_TWO;
|
||||
player->cards[1] = CARD_SPADES_KING;
|
||||
player->cards[0] = CARD_SPADES_KING;
|
||||
player->cards[1] = CARD_SPADES_ACE;
|
||||
|
||||
pokerWinnerGetForPlayer(&poker, player, &winning);
|
||||
TEST_ASSERT_EQUAL_UINT8(POKER_WINNING_TYPE_ROYAL_FLUSH, winning.type);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_CLUBS_TWO, winning.set[0]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_DIAMONDS_TWO, winning.set[1]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_HEARTS_ACE, winning.set[2]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_ACE, winning.set[3]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_TWO, winning.set[4]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_ACE, winning.set[0]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_KING, winning.set[1]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_QUEEN, winning.set[2]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_JACK, winning.set[3]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_TEN, winning.set[4]);
|
||||
}
|
||||
|
||||
int test_poker2() {
|
||||
@ -1285,7 +1285,9 @@ int test_poker2() {
|
||||
RUN_TEST(test_pokerWinnerGetForPlayer_should_CalculateThreeOfAKind);
|
||||
RUN_TEST(test_pokerWinnerGetForPlayer_should_CalculateAStraight);
|
||||
RUN_TEST(test_pokerWinnerGetForPlayer_should_CalculateAFlush);
|
||||
RUN_TEST(test_pokerWinnerGet_should_CalculateFullHouse);
|
||||
RUN_TEST(test_pokerWinnerGetForPlayer_should_CalculateFourOfAKind);
|
||||
RUN_TEST(test_pokerWinnerGetForPlayer_should_CalculateStraightFlush);
|
||||
RUN_TEST(test_pokerWinnerGetForPlayer_should_CalculateRoyalFlush);
|
||||
|
||||
return UNITY_END();
|
||||
|
Reference in New Issue
Block a user