Browse Source

refactoring: more cohesive naming

remotes/origin/ticTacToe
Aimee Reincke 2 years ago
parent
commit
de66f5ef8d
  1. 9
      src/c/ticTacToe.c
  2. 2
      src/c/ticTacToe.h
  3. 4
      test/c/test_ticTacToe.c

9
src/c/ticTacToe.c

@ -38,14 +38,14 @@ void getPlayerInput(char field[3][3]){
scanf("%d %d", &row, &col);
row -= 1;
col -= 1;
if(validateUserInput(row, col)){
if(validatePlayerInput(row, col)){
field[row][col] = 'O';
valid = validateUserInput(row, col);
valid = validatePlayerInput(row, col);
}
}
}
bool validateUserInput(int row, int col){
bool validatePlayerInput(int row, int col){
if (row < 3 && row >= 0){
if (col < 3 && col >= 0){
return true;
@ -136,4 +136,5 @@ int wasGameWon(char field[3][3]){
}
}
return winner;
}
}

2
src/c/ticTacToe.h

@ -13,7 +13,7 @@ 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);
bool validatePlayerInput(int row, int col);
int wasGameWon(char field[3][3]);
#endif

4
test/c/test_ticTacToe.c

@ -18,7 +18,7 @@ void test_ticTacToe_validUserInput(void)
int row = 2, col = 0;
/* act */
result = validateUserInput(row, col);
result = validatePlayerInput(row, col);
/* assert */
TEST_ASSERT_EQUAL_INT(true, result);
@ -31,7 +31,7 @@ void test_ticTacToe_invalidUserInput(void)
int row = 1, col = 3;
/* act */
result = validateUserInput(row, col);
result = validatePlayerInput(row, col);
/* assert */
TEST_ASSERT_EQUAL_INT(false, result);

Loading…
Cancel
Save