Browse Source

add function to parse the game commands

remotes/origin/georg
KaffeeMaus 11 months ago
parent
commit
25c6e54e25
  1. 13
      src/main/c/Georg/tictactoe.c
  2. 1
      src/main/c/Georg/tictactoe.h
  3. 14
      src/test/c/Georg/test_tictactoe.c

13
src/main/c/Georg/tictactoe.c

@ -149,6 +149,19 @@ void printBoard(){
printf("\n"); printf("\n");
} }
int* getMarkerParameters( char* input ){
int* array = (int*)malloc(2 * sizeof(int));
int index = strchr(input, ',') - input;
int firstArgument = input[index-1] - '0';
int secondArgument = input[index+1] - '0';
array[0] = firstArgument;
array[1] = secondArgument;
return array;
}
int startGame( int code ){ int startGame( int code ){
if( code == -1 ){ // command test if( code == -1 ){ // command test
return 1; return 1;

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

@ -32,6 +32,7 @@ struct ticTacToe createTicTacToe();
int handleCommand( char* input ); int handleCommand( char* input );
void initializeBoard( bool board[3][3] ); void initializeBoard( bool board[3][3] );
int handleGameInput( char* input ); int handleGameInput( char* input );
int* getMarkerParameters();
/* commands */ /* commands */
commandFunction getCommandById(int id); commandFunction getCommandById(int id);

14
src/test/c/Georg/test_tictactoe.c

@ -139,3 +139,17 @@ void test_handleGameInput(void){
// assert // assert
TEST_ASSERT_EQUAL_INT( expectedCommand, actualState ); TEST_ASSERT_EQUAL_INT( expectedCommand, actualState );
} }
void test_getMarkerParameters(void){
// arrange
char* teststring = "set 3,3";
int expectedParams[2] = {3, 3};
// act
int* actualParams = getMarkerParameters( teststring );
// assert
for( int i = 0; i < 2; i++ ){
TEST_ASSERT_EQUAL_INT( expectedParams[i], actualParams[i] );
}
}
Loading…
Cancel
Save