Split out player tests.
This commit is contained in:
@ -15,8 +15,8 @@ uint8_t pokerPlayerAdd(poker_t *poker) {
|
||||
player->cardCount = 0;
|
||||
player->chips = 0;
|
||||
player->currentBet = 0;
|
||||
player->state = POKER_PLAYER_STATE_OUT;
|
||||
player->timesRaised = 0;
|
||||
player->state = POKER_PLAYER_STATE_OUT;
|
||||
|
||||
return i;
|
||||
}
|
||||
|
236
test/poker/player.c
Normal file
236
test/poker/player.c
Normal file
@ -0,0 +1,236 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "player.h"
|
||||
|
||||
void test_pokerPlayerAdd_should_AddAPlayer(void) {
|
||||
poker_t poker;
|
||||
pokerInit(&poker);
|
||||
|
||||
TEST_ASSERT_EQUAL_UINT8(0, poker.playerCount);
|
||||
TEST_ASSERT_EQUAL(0, pokerPlayerAdd(&poker));
|
||||
TEST_ASSERT_EQUAL_UINT8(1, poker.playerCount);
|
||||
TEST_ASSERT_EQUAL(1, pokerPlayerAdd(&poker));
|
||||
TEST_ASSERT_EQUAL_UINT8(2, poker.playerCount);
|
||||
}
|
||||
|
||||
void test_pokerPlayerAdd_should_ResetThePlayer(void) {
|
||||
poker_t poker;
|
||||
pokerplayer_t *player;
|
||||
pokerInit(&poker);
|
||||
|
||||
player = poker.players + pokerPlayerAdd(&poker);
|
||||
TEST_ASSERT_EQUAL_INT32(0, player->chips);
|
||||
TEST_ASSERT_EQUAL_INT32(0, player->currentBet);
|
||||
TEST_ASSERT_EQUAL_UINT8(0, player->cardCount);
|
||||
TEST_ASSERT_EQUAL_UINT8(0, player->timesRaised);
|
||||
TEST_ASSERT_EQUAL_UINT8(POKER_PLAYER_STATE_OUT, player->state);
|
||||
}
|
||||
|
||||
void test_pokerPlayerChipsAdd_should_AddChipsToThePlayer(void) {
|
||||
poker_t poker;
|
||||
uint8_t playerIndex;
|
||||
pokerplayer_t *player;
|
||||
|
||||
pokerInit(&poker);
|
||||
playerIndex = pokerPlayerAdd(&poker);
|
||||
player = poker.players + playerIndex;
|
||||
|
||||
TEST_ASSERT_EQUAL_INT32(0, player->chips);
|
||||
pokerPlayerChipsAdd(player, 32);
|
||||
TEST_ASSERT_EQUAL_INT32(32, player->chips);
|
||||
pokerPlayerChipsAdd(player, 10);
|
||||
TEST_ASSERT_EQUAL_INT32(42, player->chips);
|
||||
pokerPlayerChipsAdd(player, -30);
|
||||
TEST_ASSERT_EQUAL_INT32(12, player->chips);
|
||||
}
|
||||
|
||||
void test_pokerPlayerChipsAdd_should_TurnOutStateOff(void) {
|
||||
poker_t poker;
|
||||
uint8_t playerIndex;
|
||||
pokerplayer_t *player;
|
||||
|
||||
pokerInit(&poker);
|
||||
playerIndex = pokerPlayerAdd(&poker);
|
||||
player = poker.players + playerIndex;
|
||||
|
||||
player->state |= POKER_PLAYER_STATE_OUT;
|
||||
TEST_ASSERT_BITS_HIGH(POKER_PLAYER_STATE_OUT, player->state);
|
||||
pokerPlayerChipsAdd(player, 32);
|
||||
TEST_ASSERT_BITS_LOW(POKER_PLAYER_STATE_OUT, player->state);
|
||||
}
|
||||
|
||||
void test_pokerPlayerDoesNeedToBetThisRound_should_CheckCallValue(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);
|
||||
|
||||
pokerBetForPlayer(&poker, first, 100);
|
||||
TEST_ASSERT_EQUAL(false, pokerPlayerDoesNeedToBetThisRound(&poker, first));
|
||||
TEST_ASSERT_EQUAL(true, pokerPlayerDoesNeedToBetThisRound(&poker, second));
|
||||
|
||||
pokerBetForPlayer(&poker, second, 200);
|
||||
TEST_ASSERT_EQUAL(true, pokerPlayerDoesNeedToBetThisRound(&poker, first));
|
||||
TEST_ASSERT_EQUAL(false, pokerPlayerDoesNeedToBetThisRound(&poker, second));
|
||||
|
||||
pokerBetForPlayer(&poker, first, 100);
|
||||
TEST_ASSERT_EQUAL(false, pokerPlayerDoesNeedToBetThisRound(&poker, first));
|
||||
TEST_ASSERT_EQUAL(false, pokerPlayerDoesNeedToBetThisRound(&poker, second));
|
||||
}
|
||||
|
||||
void test_pokerPlayerDoesNeedToBetThisRound_should_CheckWhetherHasBetYet(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(true, pokerPlayerDoesNeedToBetThisRound(&poker, first));
|
||||
TEST_ASSERT_EQUAL(true, pokerPlayerDoesNeedToBetThisRound(&poker, second));
|
||||
|
||||
pokerBetForPlayer(&poker, first, 100);
|
||||
TEST_ASSERT_EQUAL(false, pokerPlayerDoesNeedToBetThisRound(&poker, first));
|
||||
TEST_ASSERT_EQUAL(true, pokerPlayerDoesNeedToBetThisRound(&poker, second));
|
||||
|
||||
pokerBetForPlayer(&poker, second, 100);
|
||||
TEST_ASSERT_EQUAL(false, pokerPlayerDoesNeedToBetThisRound(&poker, first));
|
||||
TEST_ASSERT_EQUAL(false, pokerPlayerDoesNeedToBetThisRound(&poker, second));
|
||||
}
|
||||
|
||||
void test_pokerPlayerDoesNeedToBetThisRound_should_IgnoreFoldedPlayers(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(true, pokerPlayerDoesNeedToBetThisRound(&poker, first));
|
||||
TEST_ASSERT_EQUAL(true, pokerPlayerDoesNeedToBetThisRound(&poker, second));
|
||||
|
||||
pokerBetForPlayer(&poker, first, 100);
|
||||
TEST_ASSERT_EQUAL(false, pokerPlayerDoesNeedToBetThisRound(&poker, first));
|
||||
TEST_ASSERT_EQUAL(true, pokerPlayerDoesNeedToBetThisRound(&poker, second));
|
||||
|
||||
poker.players[second].state |= POKER_PLAYER_STATE_FOLDED;
|
||||
TEST_ASSERT_EQUAL(false, pokerPlayerDoesNeedToBetThisRound(&poker, first));
|
||||
TEST_ASSERT_EQUAL(false, pokerPlayerDoesNeedToBetThisRound(&poker, second));
|
||||
|
||||
pokerBetForPlayer(&poker, first, 100);
|
||||
TEST_ASSERT_EQUAL(false, pokerPlayerDoesNeedToBetThisRound(&poker, first));
|
||||
TEST_ASSERT_EQUAL(false, pokerPlayerDoesNeedToBetThisRound(&poker, second));
|
||||
}
|
||||
|
||||
void test_pokerPlayerCanCheck_should_CompareThePotAndPlayerBet(void) {
|
||||
poker_t poker;
|
||||
uint8_t p0, p1, p2;
|
||||
pokerInit(&poker);
|
||||
|
||||
p0 = pokerPlayerAdd(&poker);
|
||||
p1 = pokerPlayerAdd(&poker);
|
||||
p2 = pokerPlayerAdd(&poker);
|
||||
pokerPlayerChipsAdd(poker.players + p0, 1000);
|
||||
pokerPlayerChipsAdd(poker.players + p1, 1000);
|
||||
pokerPlayerChipsAdd(poker.players + p2, 1000);
|
||||
|
||||
pokerBetForPlayer(&poker, p0, 100);
|
||||
TEST_ASSERT_EQUAL(true, pokerPlayerCanCheck(&poker, poker.players+p0));
|
||||
TEST_ASSERT_EQUAL(false, pokerPlayerCanCheck(&poker, poker.players+p1));
|
||||
TEST_ASSERT_EQUAL(false, pokerPlayerCanCheck(&poker, poker.players+p2));
|
||||
|
||||
pokerBetForPlayer(&poker, p1, 100);
|
||||
TEST_ASSERT_EQUAL(true, pokerPlayerCanCheck(&poker, poker.players+p0));
|
||||
TEST_ASSERT_EQUAL(true, pokerPlayerCanCheck(&poker, poker.players+p1));
|
||||
TEST_ASSERT_EQUAL(false, pokerPlayerCanCheck(&poker, poker.players+p2));
|
||||
|
||||
pokerBetForPlayer(&poker, p2, 100);
|
||||
TEST_ASSERT_EQUAL(true, pokerPlayerCanCheck(&poker, poker.players+p0));
|
||||
TEST_ASSERT_EQUAL(true, pokerPlayerCanCheck(&poker, poker.players+p1));
|
||||
TEST_ASSERT_EQUAL(true, pokerPlayerCanCheck(&poker, poker.players+p2));
|
||||
|
||||
pokerBetForPlayer(&poker, p2, 100);
|
||||
TEST_ASSERT_EQUAL(false, pokerPlayerCanCheck(&poker, poker.players+p0));
|
||||
TEST_ASSERT_EQUAL(false, pokerPlayerCanCheck(&poker, poker.players+p1));
|
||||
TEST_ASSERT_EQUAL(true, pokerPlayerCanCheck(&poker, poker.players+p2));
|
||||
|
||||
pokerBetForPlayer(&poker, p1, 100);
|
||||
TEST_ASSERT_EQUAL(false, pokerPlayerCanCheck(&poker, poker.players+p0));
|
||||
TEST_ASSERT_EQUAL(true, pokerPlayerCanCheck(&poker, poker.players+p1));
|
||||
TEST_ASSERT_EQUAL(true, pokerPlayerCanCheck(&poker, poker.players+p2));
|
||||
}
|
||||
|
||||
void test_pokerPlayerGetFullHand_should_ReturnTheFullHand(void) {
|
||||
poker_t poker;
|
||||
pokerplayer_t *player;
|
||||
uint8_t i;
|
||||
card_t cards[POKER_WINNING_FULL_SIZE];
|
||||
|
||||
pokerInit(&poker);
|
||||
i = pokerPlayerAdd(&poker);
|
||||
player = poker.players + i;
|
||||
|
||||
pokerDeal(&poker, player, POKER_PLAYER_HAND_SIZE_MAX);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_ACE, player->cards[0]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_KING, player->cards[1]);
|
||||
|
||||
pokerDealerTurn(&poker, POKER_COMMUNITY_SIZE_MAX);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_QUEEN, poker.community[0]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_JACK, poker.community[1]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_TEN, poker.community[2]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_NINE, poker.community[3]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_EIGHT, poker.community[4]);
|
||||
|
||||
pokerPlayerGetFullHand(&poker, player, cards);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_QUEEN, cards[0]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_JACK, cards[1]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_TEN, cards[2]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_NINE, cards[3]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_EIGHT, cards[4]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_ACE, cards[5]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_KING, cards[6]);
|
||||
|
||||
poker.community[0] = CARD_CLUBS_THREE;
|
||||
poker.community[1] = CARD_DIAMONDS_TWO;
|
||||
poker.community[2] = CARD_SPADES_EIGHT;
|
||||
poker.community[3] = CARD_DIAMONDS_ACE;
|
||||
poker.community[4] = CARD_SPADES_FIVE;
|
||||
player->cards[0] = CARD_DIAMONDS_KING;
|
||||
player->cards[1] = CARD_HEARTS_QUEEN;
|
||||
|
||||
pokerPlayerGetFullHand(&poker, player, cards);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_CLUBS_THREE, cards[0]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_DIAMONDS_TWO, cards[1]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_EIGHT, cards[2]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_DIAMONDS_ACE, cards[3]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_FIVE, cards[4]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_DIAMONDS_KING, cards[5]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_HEARTS_QUEEN, cards[6]);
|
||||
}
|
||||
|
||||
int test_player_h() {
|
||||
UNITY_BEGIN();
|
||||
|
||||
RUN_TEST(test_pokerPlayerAdd_should_ResetThePlayer);
|
||||
RUN_TEST(test_pokerPlayerChipsAdd_should_AddChipsToThePlayer);
|
||||
RUN_TEST(test_pokerPlayerChipsAdd_should_TurnOutStateOff);
|
||||
RUN_TEST(test_pokerPlayerDoesNeedToBetThisRound_should_CheckCallValue);
|
||||
RUN_TEST(test_pokerPlayerDoesNeedToBetThisRound_should_CheckWhetherHasBetYet);
|
||||
RUN_TEST(test_pokerPlayerDoesNeedToBetThisRound_should_IgnoreFoldedPlayers);
|
||||
RUN_TEST(test_pokerPlayerCanCheck_should_CompareThePotAndPlayerBet);
|
||||
RUN_TEST(test_pokerPlayerGetFullHand_should_ReturnTheFullHand);
|
||||
|
||||
return UNITY_END();
|
||||
}
|
13
test/poker/player.h
Normal file
13
test/poker/player.h
Normal file
@ -0,0 +1,13 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <unity.h>
|
||||
#include <poker/poker.h>
|
||||
#include <poker/player.h>
|
||||
|
||||
int test_player_h();
|
@ -207,133 +207,6 @@ void test_pokerPotAddPlayer_should_AddAPlayer(void) {
|
||||
TEST_ASSERT_EQUAL_UINT8(0x00, pot->players[1]);
|
||||
}
|
||||
|
||||
void test_pokerPlayerAdd_should_AddAPlayer(void) {
|
||||
poker_t poker;
|
||||
pokerInit(&poker);
|
||||
|
||||
TEST_ASSERT_EQUAL_UINT8(0, poker.playerCount);
|
||||
TEST_ASSERT_EQUAL(0, pokerPlayerAdd(&poker));
|
||||
TEST_ASSERT_EQUAL_UINT8(1, poker.playerCount);
|
||||
TEST_ASSERT_EQUAL(1, pokerPlayerAdd(&poker));
|
||||
TEST_ASSERT_EQUAL_UINT8(2, poker.playerCount);
|
||||
}
|
||||
|
||||
void test_pokerPlayerAdd_should_ResetThePlayer(void) {
|
||||
poker_t poker;
|
||||
pokerplayer_t *player;
|
||||
pokerInit(&poker);
|
||||
|
||||
player = poker.players + pokerPlayerAdd(&poker);
|
||||
TEST_ASSERT_EQUAL_INT32(0, player->chips);
|
||||
TEST_ASSERT_EQUAL_INT32(0, player->currentBet);
|
||||
TEST_ASSERT_EQUAL_UINT8(0, player->cardCount);
|
||||
TEST_ASSERT_EQUAL_UINT8(0, player->timesRaised);
|
||||
TEST_ASSERT_EQUAL_UINT8(POKER_PLAYER_STATE_OUT, player->state);
|
||||
}
|
||||
|
||||
void test_pokerPlayerChipsAdd_should_AddChipsToThePlayer(void) {
|
||||
poker_t poker;
|
||||
uint8_t playerIndex;
|
||||
pokerplayer_t *player;
|
||||
|
||||
pokerInit(&poker);
|
||||
playerIndex = pokerPlayerAdd(&poker);
|
||||
player = poker.players + playerIndex;
|
||||
|
||||
TEST_ASSERT_EQUAL_INT32(0, player->chips);
|
||||
pokerPlayerChipsAdd(player, 32);
|
||||
TEST_ASSERT_EQUAL_INT32(32, player->chips);
|
||||
pokerPlayerChipsAdd(player, 10);
|
||||
TEST_ASSERT_EQUAL_INT32(42, player->chips);
|
||||
pokerPlayerChipsAdd(player, -30);
|
||||
TEST_ASSERT_EQUAL_INT32(12, player->chips);
|
||||
}
|
||||
|
||||
void test_pokerPlayerChipsAdd_should_TurnOutStateOff(void) {
|
||||
poker_t poker;
|
||||
uint8_t playerIndex;
|
||||
pokerplayer_t *player;
|
||||
|
||||
pokerInit(&poker);
|
||||
playerIndex = pokerPlayerAdd(&poker);
|
||||
player = poker.players + playerIndex;
|
||||
|
||||
player->state |= POKER_PLAYER_STATE_OUT;
|
||||
TEST_ASSERT_BITS_HIGH(POKER_PLAYER_STATE_OUT, player->state);
|
||||
pokerPlayerChipsAdd(player, 32);
|
||||
TEST_ASSERT_BITS_LOW(POKER_PLAYER_STATE_OUT, player->state);
|
||||
}
|
||||
|
||||
void test_pokerPlayerDoesNeedToBetThisRound_should_CheckCallValue(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);
|
||||
|
||||
pokerBetForPlayer(&poker, first, 100);
|
||||
TEST_ASSERT_EQUAL(false, pokerPlayerDoesNeedToBetThisRound(&poker, first));
|
||||
TEST_ASSERT_EQUAL(true, pokerPlayerDoesNeedToBetThisRound(&poker, second));
|
||||
|
||||
pokerBetForPlayer(&poker, second, 200);
|
||||
TEST_ASSERT_EQUAL(true, pokerPlayerDoesNeedToBetThisRound(&poker, first));
|
||||
TEST_ASSERT_EQUAL(false, pokerPlayerDoesNeedToBetThisRound(&poker, second));
|
||||
|
||||
pokerBetForPlayer(&poker, first, 100);
|
||||
TEST_ASSERT_EQUAL(false, pokerPlayerDoesNeedToBetThisRound(&poker, first));
|
||||
TEST_ASSERT_EQUAL(false, pokerPlayerDoesNeedToBetThisRound(&poker, second));
|
||||
}
|
||||
|
||||
void test_pokerPlayerDoesNeedToBetThisRound_should_CheckWhetherHasBetYet(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(true, pokerPlayerDoesNeedToBetThisRound(&poker, first));
|
||||
TEST_ASSERT_EQUAL(true, pokerPlayerDoesNeedToBetThisRound(&poker, second));
|
||||
|
||||
pokerBetForPlayer(&poker, first, 100);
|
||||
TEST_ASSERT_EQUAL(false, pokerPlayerDoesNeedToBetThisRound(&poker, first));
|
||||
TEST_ASSERT_EQUAL(true, pokerPlayerDoesNeedToBetThisRound(&poker, second));
|
||||
|
||||
pokerBetForPlayer(&poker, second, 100);
|
||||
TEST_ASSERT_EQUAL(false, pokerPlayerDoesNeedToBetThisRound(&poker, first));
|
||||
TEST_ASSERT_EQUAL(false, pokerPlayerDoesNeedToBetThisRound(&poker, second));
|
||||
}
|
||||
|
||||
void test_pokerPlayerDoesNeedToBetThisRound_should_IgnoreFoldedPlayers(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(true, pokerPlayerDoesNeedToBetThisRound(&poker, first));
|
||||
TEST_ASSERT_EQUAL(true, pokerPlayerDoesNeedToBetThisRound(&poker, second));
|
||||
|
||||
pokerBetForPlayer(&poker, first, 100);
|
||||
TEST_ASSERT_EQUAL(false, pokerPlayerDoesNeedToBetThisRound(&poker, first));
|
||||
TEST_ASSERT_EQUAL(true, pokerPlayerDoesNeedToBetThisRound(&poker, second));
|
||||
|
||||
poker.players[second].state |= POKER_PLAYER_STATE_FOLDED;
|
||||
TEST_ASSERT_EQUAL(false, pokerPlayerDoesNeedToBetThisRound(&poker, first));
|
||||
TEST_ASSERT_EQUAL(false, pokerPlayerDoesNeedToBetThisRound(&poker, second));
|
||||
|
||||
pokerBetForPlayer(&poker, first, 100);
|
||||
TEST_ASSERT_EQUAL(false, pokerPlayerDoesNeedToBetThisRound(&poker, first));
|
||||
TEST_ASSERT_EQUAL(false, pokerPlayerDoesNeedToBetThisRound(&poker, second));
|
||||
}
|
||||
|
||||
void test_pokerPlayerGetCallBet_should_GetCallBet(void) {
|
||||
poker_t poker;
|
||||
uint8_t p0, p1, p2;
|
||||
@ -385,44 +258,6 @@ void test_pokerInRoundGetCount_should_ReturnCountOfPlayersInRound(void) {
|
||||
TEST_ASSERT_EQUAL_UINT8(0x00, pokerInRoundGetCount(&poker));
|
||||
}
|
||||
|
||||
void test_pokerPlayerCanCheck_should_CompareThePotAndPlayerBet(void) {
|
||||
poker_t poker;
|
||||
uint8_t p0, p1, p2;
|
||||
pokerInit(&poker);
|
||||
|
||||
p0 = pokerPlayerAdd(&poker);
|
||||
p1 = pokerPlayerAdd(&poker);
|
||||
p2 = pokerPlayerAdd(&poker);
|
||||
pokerPlayerChipsAdd(poker.players + p0, 1000);
|
||||
pokerPlayerChipsAdd(poker.players + p1, 1000);
|
||||
pokerPlayerChipsAdd(poker.players + p2, 1000);
|
||||
|
||||
pokerBetForPlayer(&poker, p0, 100);
|
||||
TEST_ASSERT_EQUAL(true, pokerPlayerCanCheck(&poker, poker.players+p0));
|
||||
TEST_ASSERT_EQUAL(false, pokerPlayerCanCheck(&poker, poker.players+p1));
|
||||
TEST_ASSERT_EQUAL(false, pokerPlayerCanCheck(&poker, poker.players+p2));
|
||||
|
||||
pokerBetForPlayer(&poker, p1, 100);
|
||||
TEST_ASSERT_EQUAL(true, pokerPlayerCanCheck(&poker, poker.players+p0));
|
||||
TEST_ASSERT_EQUAL(true, pokerPlayerCanCheck(&poker, poker.players+p1));
|
||||
TEST_ASSERT_EQUAL(false, pokerPlayerCanCheck(&poker, poker.players+p2));
|
||||
|
||||
pokerBetForPlayer(&poker, p2, 100);
|
||||
TEST_ASSERT_EQUAL(true, pokerPlayerCanCheck(&poker, poker.players+p0));
|
||||
TEST_ASSERT_EQUAL(true, pokerPlayerCanCheck(&poker, poker.players+p1));
|
||||
TEST_ASSERT_EQUAL(true, pokerPlayerCanCheck(&poker, poker.players+p2));
|
||||
|
||||
pokerBetForPlayer(&poker, p2, 100);
|
||||
TEST_ASSERT_EQUAL(false, pokerPlayerCanCheck(&poker, poker.players+p0));
|
||||
TEST_ASSERT_EQUAL(false, pokerPlayerCanCheck(&poker, poker.players+p1));
|
||||
TEST_ASSERT_EQUAL(true, pokerPlayerCanCheck(&poker, poker.players+p2));
|
||||
|
||||
pokerBetForPlayer(&poker, p1, 100);
|
||||
TEST_ASSERT_EQUAL(false, pokerPlayerCanCheck(&poker, poker.players+p0));
|
||||
TEST_ASSERT_EQUAL(true, pokerPlayerCanCheck(&poker, poker.players+p1));
|
||||
TEST_ASSERT_EQUAL(true, pokerPlayerCanCheck(&poker, poker.players+p2));
|
||||
}
|
||||
|
||||
void test_pokerTurnFold_should_ReturnAFoldAction(void) {
|
||||
poker_t poker;
|
||||
pokerturn_t turn;
|
||||
@ -505,54 +340,6 @@ void test_pokerTurnBet_should_ReturnARaiseAction(void) {
|
||||
TEST_ASSERT_EQUAL_FLOAT(1.0f, turn.confidence);
|
||||
}
|
||||
|
||||
void test_pokerPlayerGetFullHand_should_ReturnTheFullHand(void) {
|
||||
poker_t poker;
|
||||
pokerplayer_t *player;
|
||||
uint8_t i;
|
||||
card_t cards[POKER_WINNING_FULL_SIZE];
|
||||
|
||||
pokerInit(&poker);
|
||||
i = pokerPlayerAdd(&poker);
|
||||
player = poker.players + i;
|
||||
|
||||
pokerDeal(&poker, player, POKER_PLAYER_HAND_SIZE_MAX);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_ACE, player->cards[0]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_KING, player->cards[1]);
|
||||
|
||||
pokerDealerTurn(&poker, POKER_COMMUNITY_SIZE_MAX);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_QUEEN, poker.community[0]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_JACK, poker.community[1]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_TEN, poker.community[2]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_NINE, poker.community[3]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_EIGHT, poker.community[4]);
|
||||
|
||||
pokerPlayerGetFullHand(&poker, player, cards);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_QUEEN, cards[0]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_JACK, cards[1]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_TEN, cards[2]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_NINE, cards[3]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_EIGHT, cards[4]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_ACE, cards[5]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_KING, cards[6]);
|
||||
|
||||
poker.community[0] = CARD_CLUBS_THREE;
|
||||
poker.community[1] = CARD_DIAMONDS_TWO;
|
||||
poker.community[2] = CARD_SPADES_EIGHT;
|
||||
poker.community[3] = CARD_DIAMONDS_ACE;
|
||||
poker.community[4] = CARD_SPADES_FIVE;
|
||||
player->cards[0] = CARD_DIAMONDS_KING;
|
||||
player->cards[1] = CARD_HEARTS_QUEEN;
|
||||
|
||||
pokerPlayerGetFullHand(&poker, player, cards);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_CLUBS_THREE, cards[0]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_DIAMONDS_TWO, cards[1]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_EIGHT, cards[2]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_DIAMONDS_ACE, cards[3]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_FIVE, cards[4]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_DIAMONDS_KING, cards[5]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_HEARTS_QUEEN, cards[6]);
|
||||
}
|
||||
|
||||
void test_pokerWinnerFillRemaining_should_FillTheRestOfTheArray(void) {
|
||||
pokerplayerwinning_t winning;
|
||||
winning.fullSize = 7;
|
||||
@ -1076,21 +863,13 @@ int test_poker() {
|
||||
RUN_TEST(test_pokerPotHasPlayer_should_DetermineIfPlayerInThePot);
|
||||
RUN_TEST(test_pokerTakeBlinds_should_TakeTheBlinds);
|
||||
RUN_TEST(test_pokerPotAddPlayer_should_AddAPlayer);
|
||||
RUN_TEST(test_pokerPlayerAdd_should_ResetThePlayer);
|
||||
RUN_TEST(test_pokerPlayerChipsAdd_should_AddChipsToThePlayer);
|
||||
RUN_TEST(test_pokerPlayerChipsAdd_should_TurnOutStateOff);
|
||||
RUN_TEST(test_pokerPlayerDoesNeedToBetThisRound_should_CheckCallValue);
|
||||
RUN_TEST(test_pokerPlayerDoesNeedToBetThisRound_should_CheckWhetherHasBetYet);
|
||||
RUN_TEST(test_pokerPlayerDoesNeedToBetThisRound_should_IgnoreFoldedPlayers);
|
||||
RUN_TEST(test_pokerPlayerGetCallBet_should_GetCallBet);
|
||||
RUN_TEST(test_pokerInRoundGetCount_should_ReturnCountOfPlayersInRound);
|
||||
RUN_TEST(test_pokerPlayerCanCheck_should_CompareThePotAndPlayerBet);
|
||||
RUN_TEST(test_pokerTurnFold_should_ReturnAFoldAction);
|
||||
RUN_TEST(test_pokerTurnBet_should_ReturnACheckAction);
|
||||
RUN_TEST(test_pokerTurnBet_should_ReturnAnAllInAction);
|
||||
RUN_TEST(test_pokerTurnBet_should_ReturnACallAction);
|
||||
RUN_TEST(test_pokerTurnBet_should_ReturnARaiseAction);
|
||||
RUN_TEST(test_pokerPlayerGetFullHand_should_ReturnTheFullHand);
|
||||
RUN_TEST(test_pokerWinnerFillRemaining_should_FillTheRestOfTheArray);
|
||||
RUN_TEST(test_pokerWinnerGetForPlayer_should_CalculateHighCard);
|
||||
RUN_TEST(test_pokerWinnerGetForPlayer_should_CalculatePair);
|
||||
|
@ -8,14 +8,17 @@
|
||||
#include "tests.h"
|
||||
|
||||
void setUp(void) {
|
||||
|
||||
}
|
||||
|
||||
void tearDown(void) {
|
||||
|
||||
}
|
||||
|
||||
int32_t main() {
|
||||
return test_dealer_h();
|
||||
return test_player_h();
|
||||
// return (
|
||||
// test_dealer_h() ||
|
||||
// test_bet_h() ||
|
||||
// test_card() ||
|
||||
// test_poker()
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "poker/bet.h"
|
||||
#include "poker/dealer.h"
|
||||
#include "poker/card.h"
|
||||
#include "poker/player.h"
|
||||
#include "poker/poker.h"
|
||||
|
||||
int32_t main();
|
Reference in New Issue
Block a user