From 3a6e65993d5353987c1c46a9eec8166ce26ff6ec Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Fri, 1 Oct 2021 21:30:54 -0700 Subject: [PATCH] Fixed test dir. --- .github/workflows/test.yml | 2 +- src/poker2/poker.c | 2 +- test/CMakeLists.txt | 2 +- test/{poker2 => poker}/card.c | 5 +- test/poker/card.h | 10 ++++ test/poker2/poker.c | 107 ++++++++++++++++++++++++++++++++++ test/poker2/poker.h | 10 ++++ test/tests.c | 16 +++++ 8 files changed, 148 insertions(+), 6 deletions(-) rename test/{poker2 => poker}/card.c (99%) create mode 100644 test/poker/card.h create mode 100644 test/poker2/poker.c create mode 100644 test/poker2/poker.h create mode 100644 test/tests.c diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1947f199..f7e6162a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -28,4 +28,4 @@ jobs: - name: Test run: | - ./build/bin/tests \ No newline at end of file + ./build/test/tests \ No newline at end of file diff --git a/src/poker2/poker.c b/src/poker2/poker.c index 279d48a9..c5507f99 100644 --- a/src/poker2/poker.c +++ b/src/poker2/poker.c @@ -31,7 +31,7 @@ uint8_t pokerPotAdd(poker2_t *poker) { } void pokerPotAddPlayer(poker2pot_t *pot, uint8_t playerIndex) { - if(!arrayContains( + if(arrayContains( sizeof(uint8_t), pot->players, pot->playerCount, &playerIndex )) return; pot->players[pot->playerCount++] = playerIndex; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 60915a83..28f5f460 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -3,4 +3,4 @@ file(GLOB_RECURSE SRCS ${CMAKE_CURRENT_SOURCE_DIR}/*.c) add_executable(tests ${SRCS}) target_link_libraries(tests game unity) -add_test(card tests) \ No newline at end of file +add_test(tests tests) \ No newline at end of file diff --git a/test/poker2/card.c b/test/poker/card.c similarity index 99% rename from test/poker2/card.c rename to test/poker/card.c index 4f67e56e..b87e9488 100644 --- a/test/poker2/card.c +++ b/test/poker/card.c @@ -5,8 +5,7 @@ * https://opensource.org/licenses/MIT */ -#include -#include +#include "card.h" void setUp(void) { } @@ -239,7 +238,7 @@ void test_cardWriteDeck_should_ReturnCardsWritten(void) { TEST_ASSERT_EQUAL_UINT8(CARD_DECK_SIZE, cardWriteDeck(cards)); } -int main() { +int test_card() { UNITY_BEGIN(); RUN_TEST(test_cardGetSuit_should_ReturnCardsSuit); diff --git a/test/poker/card.h b/test/poker/card.h new file mode 100644 index 00000000..209e5c76 --- /dev/null +++ b/test/poker/card.h @@ -0,0 +1,10 @@ +// Copyright (c) 2021 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#pragma once +#include +#include + +int test_card(); \ No newline at end of file diff --git a/test/poker2/poker.c b/test/poker2/poker.c new file mode 100644 index 00000000..f9e6c5be --- /dev/null +++ b/test/poker2/poker.c @@ -0,0 +1,107 @@ +/** + * Copyright (c) 2021 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include "poker.h" + +void test_pokerInit_should_InitializePokerGame(void) { + poker2_t poker; + pokerInit(&poker); + TEST_ASSERT_EQUAL_INT8(0, poker.playerCount); +} + +void test_pokerResetRound_should_ResetTheRound(void) { + poker2_t poker; + pokerInit(&poker); + + poker.potCount = 0x03; + poker.graveSize = 0x10; + poker.communitySize = 0x03; + poker.deckSize = 0x0; + + pokerResetRound(&poker); + + TEST_ASSERT_NOT_EQUAL_UINT8(0, poker.deckSize); + TEST_ASSERT_EQUAL_UINT8(0, poker.graveSize); + TEST_ASSERT_EQUAL_UINT8(0, poker.communitySize); + TEST_ASSERT_EQUAL_UINT8(1, poker.potCount); +} + +void test_pokerPotAdd_should_AddAPot(void) { + poker2_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) { + poker2_t poker; + poker2pot_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); +} + +void test_pokerPotAddPlayer_should_AddAPlayer(void) { + poker2_t poker; + poker2pot_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_pokerPlayerAdd_should_AddAPlayer(void) { + poker2_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) { + poker2_t poker; + poker2player_t *player; + pokerInit(&poker); + + player = poker.players + pokerPlayerAdd(&poker); + TEST_ASSERT_EQUAL_INT32(0, player->chips); + TEST_ASSERT_EQUAL_UINT8(0, player->state); + TEST_ASSERT_EQUAL_UINT8(0, player->cardCount); +} + +int test_poker2() { + UNITY_BEGIN(); + + RUN_TEST(test_pokerInit_should_InitializePokerGame); + RUN_TEST(test_pokerResetRound_should_ResetTheRound); + RUN_TEST(test_pokerPotAdd_should_AddAPot); + RUN_TEST(test_pokerPotAdd_should_ResetThePot); + RUN_TEST(test_pokerPotAddPlayer_should_AddAPlayer); + RUN_TEST(test_pokerPlayerAdd_should_ResetThePlayer); + + return UNITY_END(); +} \ No newline at end of file diff --git a/test/poker2/poker.h b/test/poker2/poker.h new file mode 100644 index 00000000..a85bb158 --- /dev/null +++ b/test/poker2/poker.h @@ -0,0 +1,10 @@ +// Copyright (c) 2021 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#pragma once +#include +#include + +int test_poker2(); \ No newline at end of file diff --git a/test/tests.c b/test/tests.c new file mode 100644 index 00000000..d7eef589 --- /dev/null +++ b/test/tests.c @@ -0,0 +1,16 @@ +/** + * Copyright (c) 2021 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include "poker/card.h" +#include "poker/poker.h" + +int main() { + return ( + !test_card() && + !test_poker2() + ); +} \ No newline at end of file