Split out pot tests.
This commit is contained in:
@ -126,87 +126,6 @@ void test_pokerTakeBlinds_should_TakeTheBlinds(void) {
|
|||||||
TEST_ASSERT_EQUAL_INT32(800, (poker.players + 4)->chips);
|
TEST_ASSERT_EQUAL_INT32(800, (poker.players + 4)->chips);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_pokerPotAdd_should_AddAPot(void) {
|
|
||||||
poker_t poker;
|
|
||||||
pokerInit(&poker);
|
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL_UINT8(1, poker.potCount);
|
|
||||||
TEST_ASSERT_EQUAL_UINT8(1, pokerPotAdd(&poker));
|
|
||||||
TEST_ASSERT_EQUAL_UINT8(2, poker.potCount);
|
|
||||||
}
|
|
||||||
|
|
||||||
void test_pokerPotAdd_should_ResetThePot(void) {
|
|
||||||
poker_t poker;
|
|
||||||
pokerpot_t *pot;
|
|
||||||
uint8_t i;
|
|
||||||
pokerInit(&poker);
|
|
||||||
|
|
||||||
i = pokerPotAdd(&poker);
|
|
||||||
pot = poker.pots + i;
|
|
||||||
TEST_ASSERT_EQUAL_UINT8(0, pot->playerCount);
|
|
||||||
TEST_ASSERT_EQUAL_INT32(0, pot->chips);
|
|
||||||
TEST_ASSERT_EQUAL_INT32(0, pot->call);
|
|
||||||
}
|
|
||||||
|
|
||||||
void test_pokerPotHasPlayer_should_DetermineIfPlayerInThePot(void) {
|
|
||||||
poker_t poker;
|
|
||||||
pokerpot_t *pot;
|
|
||||||
uint8_t p0, p1, p2;
|
|
||||||
|
|
||||||
pokerInit(&poker);
|
|
||||||
p0 = pokerPlayerAdd(&poker);
|
|
||||||
p1 = pokerPlayerAdd(&poker);
|
|
||||||
p2 = pokerPlayerAdd(&poker);
|
|
||||||
|
|
||||||
pot = poker.pots + 0;
|
|
||||||
TEST_ASSERT_EQUAL(false, pokerPotHasPlayer(pot, p0));
|
|
||||||
TEST_ASSERT_EQUAL(false, pokerPotHasPlayer(pot, p1));
|
|
||||||
TEST_ASSERT_EQUAL(false, pokerPotHasPlayer(pot, p2));
|
|
||||||
|
|
||||||
pokerPotAddPlayer(pot, p0);
|
|
||||||
TEST_ASSERT_EQUAL(true, pokerPotHasPlayer(pot, p0));
|
|
||||||
TEST_ASSERT_EQUAL(false, pokerPotHasPlayer(pot, p1));
|
|
||||||
TEST_ASSERT_EQUAL(false, pokerPotHasPlayer(pot, p2));
|
|
||||||
|
|
||||||
pokerPotAddPlayer(pot, p2);
|
|
||||||
TEST_ASSERT_EQUAL(true, pokerPotHasPlayer(pot, p0));
|
|
||||||
TEST_ASSERT_EQUAL(false, pokerPotHasPlayer(pot, p1));
|
|
||||||
TEST_ASSERT_EQUAL(true, pokerPotHasPlayer(pot, p2));
|
|
||||||
|
|
||||||
pokerPotAddPlayer(pot, p1);
|
|
||||||
TEST_ASSERT_EQUAL(true, pokerPotHasPlayer(pot, p0));
|
|
||||||
TEST_ASSERT_EQUAL(true, pokerPotHasPlayer(pot, p1));
|
|
||||||
TEST_ASSERT_EQUAL(true, pokerPotHasPlayer(pot, p2));
|
|
||||||
|
|
||||||
pokerPotAdd(&poker);
|
|
||||||
pot = poker.pots + 1;
|
|
||||||
|
|
||||||
pokerPotAddPlayer(pot, p1);
|
|
||||||
TEST_ASSERT_EQUAL(false, pokerPotHasPlayer(pot, p0));
|
|
||||||
TEST_ASSERT_EQUAL(true, pokerPotHasPlayer(pot, p1));
|
|
||||||
TEST_ASSERT_EQUAL(false, pokerPotHasPlayer(pot, p2));
|
|
||||||
}
|
|
||||||
|
|
||||||
void test_pokerPotAddPlayer_should_AddAPlayer(void) {
|
|
||||||
poker_t poker;
|
|
||||||
pokerpot_t *pot;
|
|
||||||
|
|
||||||
pokerInit(&poker);
|
|
||||||
pokerPlayerAdd(&poker);
|
|
||||||
pokerPlayerAdd(&poker);
|
|
||||||
|
|
||||||
pot = poker.pots + 0;
|
|
||||||
TEST_ASSERT_EQUAL_UINT8(0, pot->playerCount);
|
|
||||||
|
|
||||||
pokerPotAddPlayer(pot, 1);
|
|
||||||
TEST_ASSERT_EQUAL_UINT8(1, pot->playerCount);
|
|
||||||
TEST_ASSERT_EQUAL_UINT8(0x01, pot->players[0]);
|
|
||||||
|
|
||||||
pokerPotAddPlayer(pot, 0);
|
|
||||||
TEST_ASSERT_EQUAL_UINT8(2, pot->playerCount);
|
|
||||||
TEST_ASSERT_EQUAL_UINT8(0x00, pot->players[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
void test_pokerPlayerGetCallBet_should_GetCallBet(void) {
|
void test_pokerPlayerGetCallBet_should_GetCallBet(void) {
|
||||||
poker_t poker;
|
poker_t poker;
|
||||||
uint8_t p0, p1, p2;
|
uint8_t p0, p1, p2;
|
||||||
@ -858,11 +777,7 @@ int test_poker() {
|
|||||||
RUN_TEST(test_pokerResetRound_should_ResetTheRound);
|
RUN_TEST(test_pokerResetRound_should_ResetTheRound);
|
||||||
RUN_TEST(test_pokerResetRound_should_ResetThePlayers);
|
RUN_TEST(test_pokerResetRound_should_ResetThePlayers);
|
||||||
RUN_TEST(test_pokerResetBettingRound_should_ResetTheBettingRound);
|
RUN_TEST(test_pokerResetBettingRound_should_ResetTheBettingRound);
|
||||||
RUN_TEST(test_pokerPotAdd_should_AddAPot);
|
|
||||||
RUN_TEST(test_pokerPotAdd_should_ResetThePot);
|
|
||||||
RUN_TEST(test_pokerPotHasPlayer_should_DetermineIfPlayerInThePot);
|
|
||||||
RUN_TEST(test_pokerTakeBlinds_should_TakeTheBlinds);
|
RUN_TEST(test_pokerTakeBlinds_should_TakeTheBlinds);
|
||||||
RUN_TEST(test_pokerPotAddPlayer_should_AddAPlayer);
|
|
||||||
RUN_TEST(test_pokerPlayerGetCallBet_should_GetCallBet);
|
RUN_TEST(test_pokerPlayerGetCallBet_should_GetCallBet);
|
||||||
RUN_TEST(test_pokerInRoundGetCount_should_ReturnCountOfPlayersInRound);
|
RUN_TEST(test_pokerInRoundGetCount_should_ReturnCountOfPlayersInRound);
|
||||||
RUN_TEST(test_pokerTurnFold_should_ReturnAFoldAction);
|
RUN_TEST(test_pokerTurnFold_should_ReturnAFoldAction);
|
||||||
|
128
test/poker/pot.c
Normal file
128
test/poker/pot.c
Normal file
@ -0,0 +1,128 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2021 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "pot.h"
|
||||||
|
|
||||||
|
void test_pokerPotAdd_should_AddAPot(void) {
|
||||||
|
poker_t poker;
|
||||||
|
pokerInit(&poker);
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(1, poker.potCount);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(1, pokerPotAdd(&poker));
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(2, poker.potCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_pokerPotAdd_should_ResetThePot(void) {
|
||||||
|
poker_t poker;
|
||||||
|
pokerpot_t *pot;
|
||||||
|
uint8_t i;
|
||||||
|
pokerInit(&poker);
|
||||||
|
|
||||||
|
i = pokerPotAdd(&poker);
|
||||||
|
pot = poker.pots + i;
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(0, pot->playerCount);
|
||||||
|
TEST_ASSERT_EQUAL_INT32(0, pot->chips);
|
||||||
|
TEST_ASSERT_EQUAL_INT32(0, pot->call);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_pokerPotHasPlayer_should_DetermineIfPlayerInThePot(void) {
|
||||||
|
poker_t poker;
|
||||||
|
pokerpot_t *pot;
|
||||||
|
uint8_t p0, p1, p2;
|
||||||
|
|
||||||
|
pokerInit(&poker);
|
||||||
|
p0 = pokerPlayerAdd(&poker);
|
||||||
|
p1 = pokerPlayerAdd(&poker);
|
||||||
|
p2 = pokerPlayerAdd(&poker);
|
||||||
|
|
||||||
|
pot = poker.pots + 0;
|
||||||
|
TEST_ASSERT_EQUAL(false, pokerPotHasPlayer(pot, p0));
|
||||||
|
TEST_ASSERT_EQUAL(false, pokerPotHasPlayer(pot, p1));
|
||||||
|
TEST_ASSERT_EQUAL(false, pokerPotHasPlayer(pot, p2));
|
||||||
|
|
||||||
|
pokerPotAddPlayer(pot, p0);
|
||||||
|
TEST_ASSERT_EQUAL(true, pokerPotHasPlayer(pot, p0));
|
||||||
|
TEST_ASSERT_EQUAL(false, pokerPotHasPlayer(pot, p1));
|
||||||
|
TEST_ASSERT_EQUAL(false, pokerPotHasPlayer(pot, p2));
|
||||||
|
|
||||||
|
pokerPotAddPlayer(pot, p2);
|
||||||
|
TEST_ASSERT_EQUAL(true, pokerPotHasPlayer(pot, p0));
|
||||||
|
TEST_ASSERT_EQUAL(false, pokerPotHasPlayer(pot, p1));
|
||||||
|
TEST_ASSERT_EQUAL(true, pokerPotHasPlayer(pot, p2));
|
||||||
|
|
||||||
|
pokerPotAddPlayer(pot, p1);
|
||||||
|
TEST_ASSERT_EQUAL(true, pokerPotHasPlayer(pot, p0));
|
||||||
|
TEST_ASSERT_EQUAL(true, pokerPotHasPlayer(pot, p1));
|
||||||
|
TEST_ASSERT_EQUAL(true, pokerPotHasPlayer(pot, p2));
|
||||||
|
|
||||||
|
pokerPotAdd(&poker);
|
||||||
|
pot = poker.pots + 1;
|
||||||
|
|
||||||
|
pokerPotAddPlayer(pot, p1);
|
||||||
|
TEST_ASSERT_EQUAL(false, pokerPotHasPlayer(pot, p0));
|
||||||
|
TEST_ASSERT_EQUAL(true, pokerPotHasPlayer(pot, p1));
|
||||||
|
TEST_ASSERT_EQUAL(false, pokerPotHasPlayer(pot, p2));
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_pokerPotAddPlayer_should_AddAPlayer(void) {
|
||||||
|
poker_t poker;
|
||||||
|
pokerpot_t *pot;
|
||||||
|
|
||||||
|
pokerInit(&poker);
|
||||||
|
pokerPlayerAdd(&poker);
|
||||||
|
pokerPlayerAdd(&poker);
|
||||||
|
|
||||||
|
pot = poker.pots + 0;
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(0, pot->playerCount);
|
||||||
|
|
||||||
|
pokerPotAddPlayer(pot, 1);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(1, pot->playerCount);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(0x01, pot->players[0]);
|
||||||
|
|
||||||
|
pokerPotAddPlayer(pot, 0);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(2, pot->playerCount);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(0x00, pot->players[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_pokerPotGetSumOfChipsForPlayer_should_SumPlayersPotsChips(){
|
||||||
|
poker_t poker;
|
||||||
|
uint8_t p0i, p1i;
|
||||||
|
pokerplayer_t *p0;
|
||||||
|
pokerplayer_t *p1;
|
||||||
|
|
||||||
|
pokerInit(&poker);
|
||||||
|
|
||||||
|
p0i = pokerPlayerAdd(&poker);
|
||||||
|
p1i = pokerPlayerAdd(&poker);
|
||||||
|
p0 = poker.players + p0i;
|
||||||
|
p1 = poker.players + p1i;
|
||||||
|
pokerPlayerChipsAdd(p0, 10000);
|
||||||
|
pokerPlayerChipsAdd(p1, 10000);
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL_INT32(0, pokerPotGetSumOfChipsForPlayer(&poker, p0i));
|
||||||
|
TEST_ASSERT_EQUAL_INT32(0, pokerPotGetSumOfChipsForPlayer(&poker, p1i));
|
||||||
|
|
||||||
|
pokerBetForPlayer(&poker, p0i, 100);
|
||||||
|
TEST_ASSERT_EQUAL_INT32(100, pokerPotGetSumOfChipsForPlayer(&poker, p0i));
|
||||||
|
TEST_ASSERT_EQUAL_INT32(0, pokerPotGetSumOfChipsForPlayer(&poker, p1i));
|
||||||
|
|
||||||
|
pokerBetForPlayer(&poker, p1i, 200);
|
||||||
|
TEST_ASSERT_EQUAL_INT32(300, pokerPotGetSumOfChipsForPlayer(&poker, p0i));
|
||||||
|
TEST_ASSERT_EQUAL_INT32(300, pokerPotGetSumOfChipsForPlayer(&poker, p1i));
|
||||||
|
}
|
||||||
|
|
||||||
|
int test_pot_h() {
|
||||||
|
UNITY_BEGIN();
|
||||||
|
|
||||||
|
RUN_TEST(test_pokerPotAdd_should_AddAPot);
|
||||||
|
RUN_TEST(test_pokerPotAdd_should_ResetThePot);
|
||||||
|
RUN_TEST(test_pokerPotHasPlayer_should_DetermineIfPlayerInThePot);
|
||||||
|
RUN_TEST(test_pokerPotAddPlayer_should_AddAPlayer);
|
||||||
|
RUN_TEST(test_pokerPotGetSumOfChipsForPlayer_should_SumPlayersPotsChips);
|
||||||
|
|
||||||
|
return UNITY_END();
|
||||||
|
}
|
14
test/poker/pot.h
Normal file
14
test/poker/pot.h
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
/**
|
||||||
|
* 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/pot.h>
|
||||||
|
#include <poker/poker.h>
|
||||||
|
#include <poker/bet.h>
|
||||||
|
|
||||||
|
int test_pot_h();
|
@ -16,11 +16,12 @@ void tearDown(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int32_t main() {
|
int32_t main() {
|
||||||
return test_player_h();
|
return test_pot_h();
|
||||||
// return (
|
// return (
|
||||||
|
// test_player_h() ||
|
||||||
// test_dealer_h() ||
|
// test_dealer_h() ||
|
||||||
// test_bet_h() ||
|
// test_bet_h() ||
|
||||||
// test_card() ||
|
// test_card_h() ||
|
||||||
// test_poker()
|
// test_poker()
|
||||||
// );
|
// );
|
||||||
}
|
}
|
Reference in New Issue
Block a user