From 6f5ce4501e58cea1c4448e4fc5fa5c92f638ff1d Mon Sep 17 00:00:00 2001 From: KaffeeMaus Date: Fri, 26 Jan 2024 12:01:37 +0100 Subject: [PATCH] board initialize added --- src/main/c/Georg/tictactoe.c | 8 ++++++++ src/main/c/Georg/tictactoe.h | 3 +++ src/test/c/Georg/test_tictactoe.c | 23 ++++++++++++++++++++++- 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/main/c/Georg/tictactoe.c b/src/main/c/Georg/tictactoe.c index c62338a..3f2bfdc 100644 --- a/src/main/c/Georg/tictactoe.c +++ b/src/main/c/Georg/tictactoe.c @@ -86,6 +86,14 @@ char* getUserInput(){ 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 ){ if( code == -1 ){ // command test return 1; diff --git a/src/main/c/Georg/tictactoe.h b/src/main/c/Georg/tictactoe.h index 315b22c..fb29d59 100644 --- a/src/main/c/Georg/tictactoe.h +++ b/src/main/c/Georg/tictactoe.h @@ -1,6 +1,8 @@ #ifndef TICTACTOE_H #define TICTACTOE_H +#include + #define MAX_INPUT_LENGTH 20 #define MAX_COMMANDS 3 @@ -26,6 +28,7 @@ char* getWelcomeMessageTicTacToe(void); char* getRulesMessageTicTacToe(void); struct ticTacToe createTicTacToe(); int handleCommand( char* input ); +void initializeBoard( bool board[3][3] ); /* commands */ commandFunction getCommandById(int id); diff --git a/src/test/c/Georg/test_tictactoe.c b/src/test/c/Georg/test_tictactoe.c index 2562299..dcc71be 100644 --- a/src/test/c/Georg/test_tictactoe.c +++ b/src/test/c/Georg/test_tictactoe.c @@ -105,4 +105,25 @@ void test_callCommandById_startGame(void){ // assert TEST_ASSERT_EQUAL_PTR( startGame, actualCommand ); -} \ No newline at end of file +} + + +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]); + } + } +}