diff --git a/src/c/ticTacToe.c b/src/c/ticTacToe.c index c2347cb..5eab4a2 100644 --- a/src/c/ticTacToe.c +++ b/src/c/ticTacToe.c @@ -1,14 +1,11 @@ #include #include #include +#include #include "ticTacToe.h" -int something(int a){ - return a; -} - void printPrompt(){ printf("Let's play Tic Tac Toe. You will use O, I will use X.\nJust enter the number of the field you choose as row col.\nYou start.\n"); } @@ -37,5 +34,15 @@ void getPlayerInput(char field[3][3]){ int row, col; printf("Enter the field as row col: "); scanf("%d %d", &row, &col); + row -= 1; + col -= 1; field[row][col] = 'O'; +} + +bool validateUserInput(int row, int col){ + if (row < 3 && row >= 0){ + if (col < 3 && col >= 0){ + return true; + } + } } \ No newline at end of file diff --git a/src/c/ticTacToe.h b/src/c/ticTacToe.h index 832972c..250a462 100644 --- a/src/c/ticTacToe.h +++ b/src/c/ticTacToe.h @@ -1,10 +1,11 @@ #ifndef TICTACTOE_H #define TICTACTOE_H +#include -int something(int a); void printPrompt(); void printField(char field[3][3]); void initField(char field[3][3]); void getPlayerInput(char field[3][3]); +bool validateUserInput(int row, int col); #endif \ No newline at end of file diff --git a/test/c/test_ticTacToe.c b/test/c/test_ticTacToe.c index c76d3f9..d912a7a 100644 --- a/test/c/test_ticTacToe.c +++ b/test/c/test_ticTacToe.c @@ -1,6 +1,7 @@ #ifdef TEST #include "unity.h" #include "ticTacToe.h" +#include void setUp(void) { @@ -10,17 +11,17 @@ void tearDown(void) { } -void test_runExampleTest(void) +void test_ticTacToe_validUserInput(void) { /* arrange */ - int result; - int input = 1; + bool result; + int row = 2, col = 0; /* act */ - result = something(input); + result = validateUserInput(row, col); /* assert */ - TEST_ASSERT_EQUAL_INT(1, result); + TEST_ASSERT_EQUAL_INT(true, result); } #endif // TEST \ No newline at end of file