Browse Source

berechnet Gesamtwert zweier Karten + Test

remotes/origin/stefan
fdai7472 11 months ago
parent
commit
f114cab616
  1. 8
      src/main/c/Stefan/blackjack.c
  2. 1
      src/main/c/Stefan/blackjack.h
  3. 14
      src/test/c/Stefan/test_blackjack.c

8
src/main/c/Stefan/blackjack.c

@ -106,4 +106,12 @@ bool checkForBlackjack(int userCardArray[]){
return true; return true;
} }
return false; return false;
}
int calculateCardsTotal(int cardsArray[], int len){
int sum = 0;
for(int i = 0; i < len; i++){
sum += cardsArray[i];
}
return sum;
} }

1
src/main/c/Stefan/blackjack.h

@ -10,5 +10,6 @@ int userInputBJ();
int getRandCard(); int getRandCard();
int playBJ(int bet, int balance); int playBJ(int bet, int balance);
bool checkForBlackjack(int userCards[]); bool checkForBlackjack(int userCards[]);
int calculateCardsTotal(int cardsArray[], int len);
#endif // BLACKJACK_H #endif // BLACKJACK_H

14
src/test/c/Stefan/test_blackjack.c

@ -30,4 +30,18 @@ void test_no_blackjack() {
//assert //assert
TEST_ASSERT_FALSE(result); 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);
} }
Loading…
Cancel
Save