From 706f6b31bc05e0e5be1f5078b1d3fa8c47b8945a Mon Sep 17 00:00:00 2001 From: Aimee Reincke Date: Wed, 1 Feb 2023 15:33:27 +0100 Subject: [PATCH] test for no winner yet --- src/c/ticTacToe.c | 30 +++++++++++++++--------------- test/c/test_ticTacToe.c | 17 +++++++++++++++++ 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/src/c/ticTacToe.c b/src/c/ticTacToe.c index 985549d..8d0d1fb 100644 --- a/src/c/ticTacToe.c +++ b/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; } } diff --git a/test/c/test_ticTacToe.c b/test/c/test_ticTacToe.c index bc4439f..69870d1 100644 --- a/test/c/test_ticTacToe.c +++ b/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 \ No newline at end of file