Browse Source

ueberprueft, ob Ass den Wert 1 oder 11 haben muss + Tests

remotes/origin/stefan
fdai7472 11 months ago
parent
commit
ff65ed4d40
  1. 7
      src/main/c/Stefan/blackjack.c
  2. 56
      src/test/c/Stefan/test_blackjack.c

7
src/main/c/Stefan/blackjack.c

@ -110,7 +110,14 @@ bool checkForBlackjack(int userCardArray[]){
int calculateCardsTotal(int cardsArray[], int len){
int sum = 0;
bool aceFound = false;
for(int i = 0; i < len; i++){
if(cardsArray[i] == 11){
aceFound = true;
}
if(aceFound && sum + cardsArray[i] > 21){
sum -= 10;
}
sum += cardsArray[i];
}
return sum;

56
src/test/c/Stefan/test_blackjack.c

@ -44,4 +44,60 @@ void test_2_cards_total_equals_20() {
//assert
TEST_ASSERT_EQUAL_INT(expected_result, actual_result);
}
void test_cards_10_2_ace_total_equals_13() {
//arrange
int userCards[] = {10, 2, 11};
int expected_result = 13;
//act
int actual_result = calculateCardsTotal(userCards, 3);
//assert
TEST_ASSERT_EQUAL_INT(expected_result, actual_result);
}
void test_cards_8_ace_ace_total_equals_20() {
//arrange
int userCards[] = {8, 11, 11};
int expected_result = 20;
//act
int actual_result = calculateCardsTotal(userCards, 3);
//assert
TEST_ASSERT_EQUAL_INT(expected_result, actual_result);
}
void test_cards_8_ace_10_total_equals_19() {
//arrange
int userCards[] = {8, 11, 10};
int expected_result = 19;
//act
int actual_result = calculateCardsTotal(userCards, 3);
//assert
TEST_ASSERT_EQUAL_INT(expected_result, actual_result);
}
void test_cards_ace_10_total_equals_21() {
//arrange
int userCards[] = { 11, 10};
int expected_result = 21;
//act
int actual_result = calculateCardsTotal(userCards, 2);
//assert
TEST_ASSERT_EQUAL_INT(expected_result, actual_result);
}
Loading…
Cancel
Save