Split turn tests out.

This commit is contained in:
2021-10-14 23:57:00 -07:00
parent 9cbf3df529
commit 8945c79450
5 changed files with 116 additions and 88 deletions

View File

@ -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);

102
test/poker/turn.c Normal file
View File

@ -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();
}

11
test/poker/turn.h Normal file
View File

@ -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 <unity.h>
#include <poker/turn.h>
#include <poker/poker.h>
int test_turn_h();

View File

@ -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() ||

View File

@ -11,5 +11,6 @@
#include "poker/card.h"
#include "poker/player.h"
#include "poker/poker.h"
#include "poker/turn.h"
int32_t main();