From 8945c794504d9d2bccda6b6e20435fdefb0c4705 Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Thu, 14 Oct 2021 23:57:00 -0700 Subject: [PATCH] Split turn tests out. --- test/poker/poker.c | 87 -------------------------------------- test/poker/turn.c | 102 +++++++++++++++++++++++++++++++++++++++++++++ test/poker/turn.h | 11 +++++ test/tests.c | 3 +- test/tests.h | 1 + 5 files changed, 116 insertions(+), 88 deletions(-) create mode 100644 test/poker/turn.c create mode 100644 test/poker/turn.h diff --git a/test/poker/poker.c b/test/poker/poker.c index d23d6941..02721839 100644 --- a/test/poker/poker.c +++ b/test/poker/poker.c @@ -177,88 +177,6 @@ void test_pokerInRoundGetCount_should_ReturnCountOfPlayersInRound(void) { TEST_ASSERT_EQUAL_UINT8(0x00, pokerInRoundGetCount(&poker)); } -void test_pokerTurnFold_should_ReturnAFoldAction(void) { - poker_t poker; - pokerturn_t turn; - pokerInit(&poker); - pokerPlayerAdd(&poker); - - turn = pokerTurnFold(&poker, 0x00); - TEST_ASSERT_EQUAL_INT32(0, turn.chips); - TEST_ASSERT_EQUAL_UINT8(POKER_TURN_TYPE_FOLD, turn.type); - TEST_ASSERT_EQUAL_FLOAT(1.0f, turn.confidence); -} - -void test_pokerTurnBet_should_ReturnACheckAction(void) { - poker_t poker; - pokerturn_t turn; - pokerInit(&poker); - pokerPlayerAdd(&poker); - - turn = pokerTurnBet(&poker, 0x00, 0); - TEST_ASSERT_EQUAL_INT32(0, turn.chips); - TEST_ASSERT_EQUAL_UINT8(POKER_TURN_TYPE_CHECK, turn.type); - TEST_ASSERT_EQUAL_FLOAT(1.0f, turn.confidence); -} - -void test_pokerTurnBet_should_ReturnAnAllInAction(void) { - poker_t poker; - pokerturn_t turn; - pokerInit(&poker); - pokerPlayerAdd(&poker); - pokerPlayerChipsAdd(poker.players, 500); - - turn = pokerTurnBet(&poker, 0x00, 500); - TEST_ASSERT_EQUAL_INT32(500, turn.chips); - TEST_ASSERT_EQUAL_UINT8(POKER_TURN_TYPE_ALL_IN, turn.type); - TEST_ASSERT_EQUAL_FLOAT(1.0f, turn.confidence); - - pokerPlayerChipsAdd(poker.players, 500); - turn = pokerTurnBet(&poker, 0x00, 1001); - TEST_ASSERT_EQUAL_INT32(1000, turn.chips); - TEST_ASSERT_EQUAL_UINT8(POKER_TURN_TYPE_ALL_IN, turn.type); - TEST_ASSERT_EQUAL_FLOAT(1.0f, turn.confidence); -} - -void test_pokerTurnBet_should_ReturnACallAction(void) { - poker_t poker; - pokerturn_t turn; - pokerInit(&poker); - pokerPlayerChipsAdd(poker.players + pokerPlayerAdd(&poker), 1000); - pokerPlayerChipsAdd(poker.players + pokerPlayerAdd(&poker), 1000); - - pokerBetForPlayer(&poker, 0, 300); - pokerBetForPlayer(&poker, 1, 500); - - turn = pokerTurnBet(&poker, 0x00, 200); - TEST_ASSERT_EQUAL_INT32(200, turn.chips); - TEST_ASSERT_EQUAL_UINT8(POKER_TURN_TYPE_CALL, turn.type); - TEST_ASSERT_EQUAL_FLOAT(1.0f, turn.confidence); - - pokerBetForPlayer(&poker, 0, 300); - turn = pokerTurnBet(&poker, 0x01, 100); - TEST_ASSERT_EQUAL_INT32(100, turn.chips); - TEST_ASSERT_EQUAL_UINT8(POKER_TURN_TYPE_CALL, turn.type); - TEST_ASSERT_EQUAL_FLOAT(1.0f, turn.confidence); -} - -void test_pokerTurnBet_should_ReturnARaiseAction(void) { - poker_t poker; - pokerturn_t turn; - pokerInit(&poker); - pokerPlayerChipsAdd(poker.players + pokerPlayerAdd(&poker), 1000); - - turn = pokerTurnBet(&poker, 0x00, 300); - TEST_ASSERT_EQUAL_INT32(300, turn.chips); - TEST_ASSERT_EQUAL_UINT8(POKER_TURN_TYPE_BET, turn.type); - TEST_ASSERT_EQUAL_FLOAT(1.0f, turn.confidence); - - turn = pokerTurnBet(&poker, 0x00, 200); - TEST_ASSERT_EQUAL_INT32(200, turn.chips); - TEST_ASSERT_EQUAL_UINT8(POKER_TURN_TYPE_BET, turn.type); - TEST_ASSERT_EQUAL_FLOAT(1.0f, turn.confidence); -} - void test_pokerWinnerFillRemaining_should_FillTheRestOfTheArray(void) { pokerplayerwinning_t winning; winning.fullSize = 7; @@ -780,11 +698,6 @@ int test_poker() { RUN_TEST(test_pokerTakeBlinds_should_TakeTheBlinds); RUN_TEST(test_pokerPlayerGetCallBet_should_GetCallBet); RUN_TEST(test_pokerInRoundGetCount_should_ReturnCountOfPlayersInRound); - 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_pokerWinnerFillRemaining_should_FillTheRestOfTheArray); RUN_TEST(test_pokerWinnerGetForPlayer_should_CalculateHighCard); RUN_TEST(test_pokerWinnerGetForPlayer_should_CalculatePair); diff --git a/test/poker/turn.c b/test/poker/turn.c new file mode 100644 index 00000000..374b09cf --- /dev/null +++ b/test/poker/turn.c @@ -0,0 +1,102 @@ +/** + * Copyright (c) 2021 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include "turn.h" + +void test_pokerTurnFold_should_ReturnAFoldAction(void) { + poker_t poker; + pokerturn_t turn; + pokerInit(&poker); + pokerPlayerAdd(&poker); + + turn = pokerTurnFold(&poker, 0x00); + TEST_ASSERT_EQUAL_INT32(0, turn.chips); + TEST_ASSERT_EQUAL_UINT8(POKER_TURN_TYPE_FOLD, turn.type); + TEST_ASSERT_EQUAL_FLOAT(1.0f, turn.confidence); +} + +void test_pokerTurnBet_should_ReturnACheckAction(void) { + poker_t poker; + pokerturn_t turn; + pokerInit(&poker); + pokerPlayerAdd(&poker); + + turn = pokerTurnBet(&poker, 0x00, 0); + TEST_ASSERT_EQUAL_INT32(0, turn.chips); + TEST_ASSERT_EQUAL_UINT8(POKER_TURN_TYPE_CHECK, turn.type); + TEST_ASSERT_EQUAL_FLOAT(1.0f, turn.confidence); +} + +void test_pokerTurnBet_should_ReturnAnAllInAction(void) { + poker_t poker; + pokerturn_t turn; + pokerInit(&poker); + pokerPlayerAdd(&poker); + pokerPlayerChipsAdd(poker.players, 500); + + turn = pokerTurnBet(&poker, 0x00, 500); + TEST_ASSERT_EQUAL_INT32(500, turn.chips); + TEST_ASSERT_EQUAL_UINT8(POKER_TURN_TYPE_ALL_IN, turn.type); + TEST_ASSERT_EQUAL_FLOAT(1.0f, turn.confidence); + + pokerPlayerChipsAdd(poker.players, 500); + turn = pokerTurnBet(&poker, 0x00, 1001); + TEST_ASSERT_EQUAL_INT32(1000, turn.chips); + TEST_ASSERT_EQUAL_UINT8(POKER_TURN_TYPE_ALL_IN, turn.type); + TEST_ASSERT_EQUAL_FLOAT(1.0f, turn.confidence); +} + +void test_pokerTurnBet_should_ReturnACallAction(void) { + poker_t poker; + pokerturn_t turn; + pokerInit(&poker); + pokerPlayerChipsAdd(poker.players + pokerPlayerAdd(&poker), 1000); + pokerPlayerChipsAdd(poker.players + pokerPlayerAdd(&poker), 1000); + + pokerBetForPlayer(&poker, 0, 300); + pokerBetForPlayer(&poker, 1, 500); + + turn = pokerTurnBet(&poker, 0x00, 200); + TEST_ASSERT_EQUAL_INT32(200, turn.chips); + TEST_ASSERT_EQUAL_UINT8(POKER_TURN_TYPE_CALL, turn.type); + TEST_ASSERT_EQUAL_FLOAT(1.0f, turn.confidence); + + pokerBetForPlayer(&poker, 0, 300); + turn = pokerTurnBet(&poker, 0x01, 100); + TEST_ASSERT_EQUAL_INT32(100, turn.chips); + TEST_ASSERT_EQUAL_UINT8(POKER_TURN_TYPE_CALL, turn.type); + TEST_ASSERT_EQUAL_FLOAT(1.0f, turn.confidence); +} + +void test_pokerTurnBet_should_ReturnARaiseAction(void) { + poker_t poker; + pokerturn_t turn; + pokerInit(&poker); + pokerPlayerChipsAdd(poker.players + pokerPlayerAdd(&poker), 1000); + + turn = pokerTurnBet(&poker, 0x00, 300); + TEST_ASSERT_EQUAL_INT32(300, turn.chips); + TEST_ASSERT_EQUAL_UINT8(POKER_TURN_TYPE_BET, turn.type); + TEST_ASSERT_EQUAL_FLOAT(1.0f, turn.confidence); + + turn = pokerTurnBet(&poker, 0x00, 200); + TEST_ASSERT_EQUAL_INT32(200, turn.chips); + TEST_ASSERT_EQUAL_UINT8(POKER_TURN_TYPE_BET, turn.type); + TEST_ASSERT_EQUAL_FLOAT(1.0f, turn.confidence); +} + +int test_turn_h() { + UNITY_BEGIN(); + + 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); + + return UNITY_END(); +} \ No newline at end of file diff --git a/test/poker/turn.h b/test/poker/turn.h new file mode 100644 index 00000000..ff721c97 --- /dev/null +++ b/test/poker/turn.h @@ -0,0 +1,11 @@ +// Copyright (c) 2021 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#pragma once +#include +#include +#include + +int test_turn_h(); \ No newline at end of file diff --git a/test/tests.c b/test/tests.c index 7f84c399..d22be028 100644 --- a/test/tests.c +++ b/test/tests.c @@ -16,8 +16,9 @@ void tearDown(void) { } int32_t main() { - return test_pot_h(); + return test_turn_h(); // return ( + // test_pot_h() || // test_player_h() || // test_dealer_h() || // test_bet_h() || diff --git a/test/tests.h b/test/tests.h index 768d52c4..b5af2189 100644 --- a/test/tests.h +++ b/test/tests.h @@ -11,5 +11,6 @@ #include "poker/card.h" #include "poker/player.h" #include "poker/poker.h" +#include "poker/turn.h" int32_t main(); \ No newline at end of file