Browse Source

Implementierung CheckForBlackjack + Tests

remotes/origin/stefan
fdai7472 11 months ago
parent
commit
2d844a3694
  1. 15
      src/main/c/Stefan/blackjack.c
  2. 2
      src/main/c/Stefan/blackjack.h
  3. 12
      src/test/c/Stefan/test_blackjack.c

15
src/main/c/Stefan/blackjack.c

@ -1,8 +1,7 @@
#include "blackjack.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <stdbool.h>
int blackjack(){
@ -62,6 +61,8 @@ int getRandCard(){
if(r > 10){
return 10;
} else if(r == 1){
return 11;
}
return r;
@ -87,6 +88,8 @@ int playBJ(int bet, int balance){
userCardArray[1] = getRandCard();
printf("user rand card: %d\n", userCardArray[1]);
checkForBlackjack(userCardArray);
free(userCardArray);
}
@ -95,4 +98,12 @@ int playBJ(int bet, int balance){
}
return balance;
}
bool checkForBlackjack(int userCardArray[]){
if(userCardArray[0] + userCardArray[1] == 21){
printf("BLACKJACK!\n");
return true;
}
return false;
}

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

@ -1,6 +1,7 @@
#ifndef BLACKJACK_H
#define BLACKJACK_H
#include <stdbool.h>
int blackjack();
int getBalanceBJ();
@ -8,5 +9,6 @@ int getBetBJ(int balance);
int userInputBJ();
int getRandCard();
int playBJ(int bet, int balance);
bool checkForBlackjack(int userCards[]);
#endif // BLACKJACK_H

12
src/test/c/Stefan/test_blackjack.c

@ -6,22 +6,28 @@ void setUp() {}
void tearDown() {}
void test_1() {
void test_blackjack() {
//arrange
int userCards[] = {10, 11};
//act
bool result = checkForBlackjack(userCards);
//assert
TEST_ASSERT_TRUE(result);
}
void test_2() {
void test_no_blackjack() {
//arrange
int userCards[] = {10, 10};
//act
bool result = checkForBlackjack(userCards);
//assert
TEST_ASSERT_FALSE(result);
}
Loading…
Cancel
Save