From b155dc4909447f7338f2b480223efb58f3f3b805 Mon Sep 17 00:00:00 2001 From: fdai7472 Date: Mon, 5 Feb 2024 18:13:40 +0100 Subject: [PATCH] Implemenitierung calculateWinnings + Tests --- src/main/c/Stefan/blackjack.c | 14 +++++++++++++- src/main/c/Stefan/blackjack.h | 1 + src/test/c/Stefan/test_blackjack.c | 28 ++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/main/c/Stefan/blackjack.c b/src/main/c/Stefan/blackjack.c index 06a765a..5e995bd 100644 --- a/src/main/c/Stefan/blackjack.c +++ b/src/main/c/Stefan/blackjack.c @@ -73,6 +73,8 @@ int getRandCard(){ int playBJ(int bet, int balance){ + int winnings = 0; + int *computerCardArray = (int*) malloc(10 * sizeof(int)); if(computerCardArray){ @@ -88,7 +90,10 @@ int playBJ(int bet, int balance){ userCardArray[1] = getRandCard(); printf("user rand card: %d\n", userCardArray[1]); - checkForBlackjack(userCardArray); + if(checkForBlackjack(userCardArray)){ + winnings = calculateWinnings(true, bet); + return balance + winnings; + } free(userCardArray); @@ -121,4 +126,11 @@ int calculateCardsTotal(int cardsArray[], int len){ sum += cardsArray[i]; } return sum; +} + +int calculateWinnings(bool blackjack, int bet){ + if(blackjack){ + return 3 * bet; + } + return 2 * bet; } \ No newline at end of file diff --git a/src/main/c/Stefan/blackjack.h b/src/main/c/Stefan/blackjack.h index be79c7b..71656e0 100644 --- a/src/main/c/Stefan/blackjack.h +++ b/src/main/c/Stefan/blackjack.h @@ -11,5 +11,6 @@ int getRandCard(); int playBJ(int bet, int balance); bool checkForBlackjack(int userCards[]); int calculateCardsTotal(int cardsArray[], int len); +int calculateWinnings(bool blackjack, int bet); #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 334affa..5fee88e 100644 --- a/src/test/c/Stefan/test_blackjack.c +++ b/src/test/c/Stefan/test_blackjack.c @@ -100,4 +100,32 @@ void test_cards_ace_10_total_equals_21() { //assert TEST_ASSERT_EQUAL_INT(expected_result, actual_result); +} + +void test_blackjack_bet_equals_10() { + + //arrange + int bet = 10; + int expected_result = 30; + + //act + int actual_result = calculateWinnings(true, bet); + + //assert + TEST_ASSERT_EQUAL_INT(expected_result, actual_result); + +} + +void test_no_blackjack_bet_equals_10() { + + //arrange + int bet = 10; + int expected_result = 20; + + //act + int actual_result = calculateWinnings(false, bet); + + //assert + TEST_ASSERT_EQUAL_INT(expected_result, actual_result); + } \ No newline at end of file