Browse Source

test for no winner yet

remotes/origin/ticTacToe
Aimee Reincke 2 years ago
parent
commit
706f6b31bc
  1. 30
      src/c/ticTacToe.c
  2. 17
      test/c/test_ticTacToe.c

30
src/c/ticTacToe.c

@ -69,59 +69,59 @@ int wasGameWon(char field[3][3]){
if (field[0][0] == field[0][1] && field[0][2] == field[0][1]){
winner = PLAYER;
}
else if (field[0][0] == field[1][0] && field[1][0] == field[2][0]){
if (field[0][0] == field[1][0] && field[1][0] == field[2][0]){
winner = PLAYER;
}
else if (field[0][0] == field[1][1] && field[1][1] == field[2][2]){
if (field[0][0] == field[1][1] && field[1][1] == field[2][2]){
winner = PLAYER;
}
}
else if(field[2][2] == 'O'){
if(field[2][2] == 'O'){
if (field[2][2] == field[2][1] && field[2][2] == field[2][0]){
winner = PLAYER;
}
else if (field[2][2] == field[1][2] && field[1][2] == field[0][2]){
if (field[2][2] == field[1][2] && field[1][2] == field[0][2]){
winner = PLAYER;
}
}
else if(field[1][1] == 'O'){
if(field[1][1] == 'O'){
if (field[1][1] == field[0][1] && field[0][1] == field[2][1]){
winner = PLAYER;
}
else if (field[1][1] == field[1][0] && field[1][0] == field[1][2]){
if (field[1][1] == field[1][0] && field[1][0] == field[1][2]){
winner = PLAYER;
}
else if (field[2][0] == field[1][1] && field[1][1] == field[0][2]){
if (field[2][0] == field[1][1] && field[1][1] == field[0][2]){
winner = PLAYER;
}
}
else if(field[0][0] == 'X'){
if(field[0][0] == 'X'){
if (field[0][0] == field[0][1] && field[0][2] == field[0][1]){
winner = COMPUTER;
}
else if (field[0][0] == field[1][0] && field[1][0] == field[2][0]){
if (field[0][0] == field[1][0] && field[1][0] == field[2][0]){
winner = COMPUTER;
}
else if (field[0][0] == field[1][1] && field[1][1] == field[2][2]){
if (field[0][0] == field[1][1] && field[1][1] == field[2][2]){
winner = COMPUTER;
}
}
else if(field[2][2] == 'X'){
if(field[2][2] == 'X'){
if (field[2][2] == field[2][1] && field[2][2] == field[2][0]){
winner = COMPUTER;
}
else if (field[2][2] == field[1][2] && field[1][2] == field[0][2]){
if (field[2][2] == field[1][2] && field[1][2] == field[0][2]){
winner = COMPUTER;
}
}
else if(field[1][1] == 'X'){
if(field[1][1] == 'X'){
if (field[1][1] == field[0][1] && field[0][1] == field[2][1]){
winner = COMPUTER;
}
else if (field[1][1] == field[1][0] && field[1][0] == field[1][2]){
if (field[1][1] == field[1][0] && field[1][0] == field[1][2]){
winner = COMPUTER;
}
else if (field[2][0] == field[1][1] && field[1][1] == field[0][2]){
if (field[2][0] == field[1][1] && field[1][1] == field[0][2]){
winner = COMPUTER;
}
}

17
test/c/test_ticTacToe.c

@ -88,4 +88,21 @@ void test_ticTacToe_NooneWins(void)
TEST_ASSERT_EQUAL_INT(DRAW, result);
}
void test_ticTacToe_NoWinnerYet(void)
{
/* arrange */
int result;
char field[][3] = {
{'X', 'O', 'O'},
{'O', '-', 'X'},
{'X', 'O', 'O'}
};
/* act */
result = wasGameWon(field);
/* assert */
TEST_ASSERT_EQUAL_INT(NOWINNERYET, result);
}
#endif // TEST
Loading…
Cancel
Save