From 77d4338a759e6ca35517665e5ec439af749bdfab Mon Sep 17 00:00:00 2001 From: fdai7472 Date: Wed, 7 Feb 2024 10:28:38 +0100 Subject: [PATCH] Implementierung Funktion, die Wetteinsatz vom Guthaben abzieht + Test --- src/main/c/Stefan/blackjack.c | 6 +++++- src/main/c/Stefan/blackjack.h | 1 + src/test/c/Stefan/test_blackjack.c | 17 ++++++++++++++++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/main/c/Stefan/blackjack.c b/src/main/c/Stefan/blackjack.c index 838b676..c22ae30 100644 --- a/src/main/c/Stefan/blackjack.c +++ b/src/main/c/Stefan/blackjack.c @@ -22,7 +22,7 @@ int blackjack(){ } // Bei jeder Runde wird der Wetteinsatz vom Guthaben abgezogen - balance -= bet; + balance = subtractBetFromBalanceBJ(bet, balance); // Nach jeder Runde wird das Guthaben aktualisiert balance = playBJ(bet, balance); @@ -31,6 +31,10 @@ int blackjack(){ return 0; } +int subtractBetFromBalanceBJ(int bet, int balance){ + return balance - bet; +} + int getBalanceBJ(){ printf("Guthaben einwerfen: "); int balance = userInputBJ(); diff --git a/src/main/c/Stefan/blackjack.h b/src/main/c/Stefan/blackjack.h index 2e610b2..bb70cd7 100644 --- a/src/main/c/Stefan/blackjack.h +++ b/src/main/c/Stefan/blackjack.h @@ -19,5 +19,6 @@ int calculateWinnings(bool blackjack, int bet); bool hit(); bool calculateIfYouWon(int userCardsTotal, int computerCardsTotal); char generateCardAscii(int cardValue); +int subtractBetFromBalanceBJ(int bet, int balance); #endif // BLACKJACK_H \ No newline at end of file diff --git a/src/test/c/Stefan/test_blackjack.c b/src/test/c/Stefan/test_blackjack.c index feab3b0..7790cd9 100644 --- a/src/test/c/Stefan/test_blackjack.c +++ b/src/test/c/Stefan/test_blackjack.c @@ -282,4 +282,19 @@ void test_generate_char_for_card_5() { //assert TEST_ASSERT_EQUAL_CHAR(expected_result, actual_result); -} \ No newline at end of file +} + +void test_subtract_bet_10_from_balance_100() { + + //arrange + int bet = 10; + int balance = 100; + int expected_result = 90; + + //act + int actual_result = subtractBetFromBalanceBJ(bet, balance); + + //assert + TEST_ASSERT_EQUAL_INT(expected_result, actual_result); + +}