Browse Source

board initialize added

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

8
src/main/c/Georg/tictactoe.c

@ -86,6 +86,14 @@ char* getUserInput(){
return userInput; return userInput;
} }
void initializeBoard( bool board[3][3] ){
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
board[i][j] = 0;
}
}
}
int startMenu( int code ){ int startMenu( int code ){
if( code == -1 ){ // command test if( code == -1 ){ // command test
return 1; return 1;

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

@ -1,6 +1,8 @@
#ifndef TICTACTOE_H #ifndef TICTACTOE_H
#define TICTACTOE_H #define TICTACTOE_H
#include <stdbool.h>
#define MAX_INPUT_LENGTH 20 #define MAX_INPUT_LENGTH 20
#define MAX_COMMANDS 3 #define MAX_COMMANDS 3
@ -26,6 +28,7 @@ char* getWelcomeMessageTicTacToe(void);
char* getRulesMessageTicTacToe(void); char* getRulesMessageTicTacToe(void);
struct ticTacToe createTicTacToe(); struct ticTacToe createTicTacToe();
int handleCommand( char* input ); int handleCommand( char* input );
void initializeBoard( bool board[3][3] );
/* commands */ /* commands */
commandFunction getCommandById(int id); commandFunction getCommandById(int id);

23
src/test/c/Georg/test_tictactoe.c

@ -105,4 +105,25 @@ void test_callCommandById_startGame(void){
// assert // assert
TEST_ASSERT_EQUAL_PTR( startGame, actualCommand ); TEST_ASSERT_EQUAL_PTR( startGame, actualCommand );
}
}
void test_initializeBoard(void){
// arrange
bool expectedBoard[3][3]={
{0,0,0},
{0,0,0},
{0,0,0}
};
// act
bool actualBoard[3][3];
initializeBoard(actualBoard);
// assert
for (size_t i = 0; i < 3; i++) {
for (size_t ii = 0; ii < 3; ii++) {
TEST_ASSERT_EQUAL_INT(expectedBoard[i][ii], actualBoard[i][ii]);
}
}
}
Loading…
Cancel
Save