diff --git a/src/main/c/Stefan/blackjack.c b/src/main/c/Stefan/blackjack.c index 2268373..3c2a20c 100644 --- a/src/main/c/Stefan/blackjack.c +++ b/src/main/c/Stefan/blackjack.c @@ -106,4 +106,12 @@ bool checkForBlackjack(int userCardArray[]){ return true; } return false; +} + +int calculateCardsTotal(int cardsArray[], int len){ + int sum = 0; + for(int i = 0; i < len; i++){ + sum += cardsArray[i]; + } + return sum; } \ No newline at end of file diff --git a/src/main/c/Stefan/blackjack.h b/src/main/c/Stefan/blackjack.h index 1388b18..be79c7b 100644 --- a/src/main/c/Stefan/blackjack.h +++ b/src/main/c/Stefan/blackjack.h @@ -10,5 +10,6 @@ int userInputBJ(); int getRandCard(); int playBJ(int bet, int balance); bool checkForBlackjack(int userCards[]); +int calculateCardsTotal(int cardsArray[], int len); #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 6217651..2d6b01c 100644 --- a/src/test/c/Stefan/test_blackjack.c +++ b/src/test/c/Stefan/test_blackjack.c @@ -30,4 +30,18 @@ void test_no_blackjack() { //assert TEST_ASSERT_FALSE(result); +} + +void test_2_cards_total_equals_20() { + + //arrange + int userCards[] = {10, 10}; + int expected_result = 20; + + //act + int actual_result = calculateCardsTotal(userCards, 2); + + //assert + TEST_ASSERT_EQUAL_INT(expected_result, actual_result); + } \ No newline at end of file