Browse Source

add defenition for the board size

remotes/origin/georg
KaffeeMaus 11 months ago
parent
commit
c29eff6aa4
  1. 4
      src/main/c/Georg/tictactoe.c
  2. 2
      src/main/c/Georg/tictactoe.h
  3. 8
      src/test/c/Georg/test_tictactoe.c

4
src/main/c/Georg/tictactoe.c

@ -86,7 +86,7 @@ char* getUserInput(){
return userInput;
}
void initializeBoard( bool board[3][3] ){
void initializeBoard( bool board[BORAD_SIZE][BORAD_SIZE] ){
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
board[i][j] = 0;
@ -120,6 +120,8 @@ int startGame( int code ){
}
printf("Welcome to the game!\n");
bool board[BORAD_SIZE][BORAD_SIZE];
initializeBoard( board );
while( GAME.currentState == 1 ){
int nextState = handleCommand( getUserInput() );

2
src/main/c/Georg/tictactoe.h

@ -5,9 +5,11 @@
#define MAX_INPUT_LENGTH 20
#define MAX_COMMANDS 3
#define BORAD_SIZE 3
struct ticTacToe{
int currentState;
bool board[BORAD_SIZE][BORAD_SIZE];
};
// Typdefinition für einen Funktionszeiger

8
src/test/c/Georg/test_tictactoe.c

@ -110,19 +110,19 @@ void test_callCommandById_startGame(void){
void test_initializeBoard(void){
// arrange
bool expectedBoard[3][3]={
bool expectedBoard[BORAD_SIZE][BORAD_SIZE]={
{0,0,0},
{0,0,0},
{0,0,0}
};
// act
bool actualBoard[3][3];
bool actualBoard[BORAD_SIZE][BORAD_SIZE];
initializeBoard(actualBoard);
// assert
for (size_t i = 0; i < 3; i++) {
for (size_t ii = 0; ii < 3; ii++) {
for (size_t i = 0; i < BORAD_SIZE; i++) {
for (size_t ii = 0; ii < BORAD_SIZE; ii++) {
TEST_ASSERT_EQUAL_INT(expectedBoard[i][ii], actualBoard[i][ii]);
}
}

Loading…
Cancel
Save