Browse Source

valid user Input

remotes/origin/ticTacToe
Aimee Reincke 2 years ago
parent
commit
2cbe1727f0
  1. 15
      src/c/ticTacToe.c
  2. 3
      src/c/ticTacToe.h
  3. 11
      test/c/test_ticTacToe.c

15
src/c/ticTacToe.c

@ -1,14 +1,11 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#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;
}
}
}

3
src/c/ticTacToe.h

@ -1,10 +1,11 @@
#ifndef TICTACTOE_H
#define TICTACTOE_H
#include <stdbool.h>
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

11
test/c/test_ticTacToe.c

@ -1,6 +1,7 @@
#ifdef TEST
#include "unity.h"
#include "ticTacToe.h"
#include <stdbool.h>
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
Loading…
Cancel
Save