diff --git a/build/test/cache/defines_dependency.yml b/build/test/cache/defines_dependency.yml index 2fbf0ff..9ce76ed 100644 --- a/build/test/cache/defines_dependency.yml +++ b/build/test/cache/defines_dependency.yml @@ -1 +1,3 @@ ---- {} +--- +src/main/duellist-spielesammlung-projekt.c: +- TEST diff --git a/build/test/cache/test_duellist_spielesammlung_projekt.c b/build/test/cache/test_duellist_spielesammlung_projekt.c index e69de29..74c99eb 100644 --- a/build/test/cache/test_duellist_spielesammlung_projekt.c +++ b/build/test/cache/test_duellist_spielesammlung_projekt.c @@ -0,0 +1,509 @@ +#include "src/main/duellist-spielesammlung-projekt.h" +#include "C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h" + + + + + + +void setUp(void) {} + + + +void tearDown(void) {} + + + + + +void test_coinflip_player_x_starts(void) { + + + + TicTacToeGame game; + + + + + + GameResult result = initializeGame(&game); + + + + + + UnityAssertEqualNumber((UNITY_INT)((SUCCESS)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(19), UNITY_DISPLAY_STYLE_INT); + + do {if ((game.currentPlayer == PLAYER_X || game.currentPlayer == PLAYER_O)) {} else {UnityFail( ((" Expected TRUE Was FALSE")), (UNITY_UINT)((UNITY_UINT)(20)));}} while(0); + +} + + + +void test_coinflip_player_o_starts(void) { + + + + TicTacToeGame game; + + + + + + GameResult result = initializeGame(&game); + + + + + + UnityAssertEqualNumber((UNITY_INT)((SUCCESS)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(31), UNITY_DISPLAY_STYLE_INT); + + do {if ((game.currentPlayer == PLAYER_X || game.currentPlayer == PLAYER_O)) {} else {UnityFail( ((" Expected TRUE Was FALSE")), (UNITY_UINT)((UNITY_UINT)(32)));}} while(0); + +} + + + +void test_vertical_win(void) { + + + + TicTacToeGame game = { .board = {{PLAYER_X, EMPTY, EMPTY}, + + {PLAYER_X, EMPTY, EMPTY}, + + {PLAYER_X, EMPTY, EMPTY}}, + + .currentPlayer = PLAYER_O }; + + + + + + GameResult result = checkGameResult(&game); + + + + + + UnityAssertEqualNumber((UNITY_INT)((GAME_WIN)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(46), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_horizontal_win(void) { + + + + TicTacToeGame game = { .board = {{PLAYER_X, PLAYER_X, PLAYER_X}, + + {EMPTY, EMPTY, EMPTY}, + + {EMPTY, EMPTY, EMPTY}}, + + .currentPlayer = PLAYER_O }; + + + + + + GameResult result = checkGameResult(&game); + + + + + + UnityAssertEqualNumber((UNITY_INT)((GAME_WIN)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(60), UNITY_DISPLAY_STYLE_INT); + +} + +void test_diagonal_win(void) { + + + + TicTacToeGame game = { .board = {{PLAYER_X, EMPTY, EMPTY}, + + {EMPTY, PLAYER_X, EMPTY}, + + {EMPTY, EMPTY, PLAYER_X}}, + + .currentPlayer = PLAYER_O }; + + + + + + GameResult result = checkGameResult(&game); + + + + + + UnityAssertEqualNumber((UNITY_INT)((GAME_WIN)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(73), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_valid_move_and_switch_player(void) { + + + + TicTacToeGame game = { .board = {{EMPTY, EMPTY, EMPTY}, + + {EMPTY, EMPTY, EMPTY}, + + {EMPTY, EMPTY, EMPTY}}, + + .currentPlayer = PLAYER_X }; + + + + + + GameResult moveResult = makeMove(&game, 1, 1); + + + + + + UnityAssertEqualNumber((UNITY_INT)((SUCCESS)), (UNITY_INT)((moveResult)), ( + + ((void *)0) + + ), (UNITY_UINT)(87), UNITY_DISPLAY_STYLE_INT); + + UnityAssertEqualNumber((UNITY_INT)((PLAYER_O)), (UNITY_INT)((game.currentPlayer)), ( + + ((void *)0) + + ), (UNITY_UINT)(88), UNITY_DISPLAY_STYLE_INT); + +} + + + + + +void test_invalid_input(void) { + + + + TicTacToeGame game = { .board = {{PLAYER_X, EMPTY, EMPTY}, + + {EMPTY, EMPTY, EMPTY}, + + {EMPTY, EMPTY, EMPTY}}, + + .currentPlayer = PLAYER_O }; + + + + + + GameResult result = makeMove(&game, 0, 0); + + + + + + UnityAssertEqualNumber((UNITY_INT)((INVALID_MOVE)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(103), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_valid_input(void) { + + + + TicTacToeGame game = { .board = {{EMPTY, EMPTY, EMPTY}, + + {EMPTY, EMPTY, EMPTY}, + + {EMPTY, EMPTY, EMPTY}}, + + .currentPlayer = PLAYER_X }; + + + + + + GameResult result = makeMove(&game, 1, 1); + + + + + + UnityAssertEqualNumber((UNITY_INT)((SUCCESS)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(117), UNITY_DISPLAY_STYLE_INT); + +} + + + + + +void test_invalid_input_type1(void) { + + + + TicTacToeGame game = { .board = {{PLAYER_X, EMPTY, EMPTY}, + + {EMPTY, EMPTY, EMPTY}, + + {EMPTY, EMPTY, EMPTY}}, + + .currentPlayer = PLAYER_O }; + + + + + + GameResult result = makeMove(&game, -1, 0); + + + + + + UnityAssertEqualNumber((UNITY_INT)((INVALID_MOVE)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(132), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_invalid_input_type2(void) { + + + + TicTacToeGame game = { .board = {{PLAYER_X, EMPTY, EMPTY}, + + {EMPTY, EMPTY, EMPTY}, + + {EMPTY, EMPTY, EMPTY}}, + + .currentPlayer = PLAYER_O }; + + + + + + GameResult result = makeMove(&game, 0, 3); + + + + + + UnityAssertEqualNumber((UNITY_INT)((INVALID_MOVE)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(146), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_getNumberOfMoves_returns_correct_number_of_moves(void) { + + + + TicTacToeGame game = { .board = {{PLAYER_X, EMPTY, EMPTY}, + + {EMPTY, PLAYER_O, EMPTY}, + + {EMPTY, EMPTY, EMPTY}}, + + .currentPlayer = PLAYER_X }; + + + + + + int moves = getNumberOfMoves(&game); + + + + + + UnityAssertEqualNumber((UNITY_INT)((2)), (UNITY_INT)((moves)), ( + + ((void *)0) + + ), (UNITY_UINT)(160), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_BoardFull_returns_false_when_board_is_not_full(void) { + + + + TicTacToeGame game = { .board = {{PLAYER_X, EMPTY, EMPTY}, + + {EMPTY, PLAYER_O, EMPTY}, + + {EMPTY, EMPTY, EMPTY}}, + + .currentPlayer = PLAYER_X }; + + + + + + int boardFull = BoardFull(&game); + + + + + + do {if (!(boardFull)) {} else {UnityFail( ((" Expected FALSE Was TRUE")), (UNITY_UINT)((UNITY_UINT)(174)));}} while(0); + +} + +void test_BoardFull_returns_true_when_board_is_full(void) { + + + + TicTacToeGame game = { .board = {{PLAYER_X, PLAYER_X, PLAYER_O}, + + {PLAYER_O, PLAYER_O, PLAYER_X}, + + {PLAYER_X, PLAYER_X, PLAYER_O}}, + + .currentPlayer = PLAYER_X }; + + + + + + int boardFull = BoardFull(&game); + + + + + + do {if ((boardFull)) {} else {UnityFail( ((" Expected TRUE Was FALSE")), (UNITY_UINT)((UNITY_UINT)(187)));}} while(0); + +} + +void test_getCurrentPlayer_returns_correct_player(void) { + + + + TicTacToeGame game = { .board = {{PLAYER_X, EMPTY, EMPTY}, + + {EMPTY, PLAYER_O, EMPTY}, + + {EMPTY, EMPTY, EMPTY}}, + + .currentPlayer = PLAYER_O }; + + + + + + Player currentPlayer = getCurrentPlayer(&game); + + + + + + UnityAssertEqualNumber((UNITY_INT)((PLAYER_O)), (UNITY_INT)((currentPlayer)), ( + + ((void *)0) + + ), (UNITY_UINT)(200), UNITY_DISPLAY_STYLE_INT); + +} + +void test_FieldEmpty_returns_true_for_empty_field(void) { + + + + TicTacToeGame game = { .board = {{PLAYER_X, EMPTY, EMPTY}, + + {EMPTY, PLAYER_O, EMPTY}, + + {EMPTY, EMPTY, EMPTY}} }; + + + + + + int result = FieldEmpty(&game, 0, 2); + + + + + + UnityAssertEqualNumber((UNITY_INT)((1)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(212), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_FieldEmpty_returns_false_for_nonempty_field(void) { + + + + TicTacToeGame game = { .board = {{PLAYER_X, EMPTY, EMPTY}, + + {EMPTY, PLAYER_O, EMPTY}, + + {EMPTY, EMPTY, EMPTY}} }; + + + + + + int result = FieldEmpty(&game, 0, 0); + + + + + + UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(225), UNITY_DISPLAY_STYLE_INT); + +} diff --git a/build/test/dependencies/test_duellist_spielesammlung_projekt.d b/build/test/dependencies/test_duellist_spielesammlung_projekt.d index 598e388..96c50a9 100644 --- a/build/test/dependencies/test_duellist_spielesammlung_projekt.d +++ b/build/test/dependencies/test_duellist_spielesammlung_projekt.d @@ -1,2 +1,5 @@ build/test/out/c/test_duellist_spielesammlung_projekt.o: \ - src/test/test_duellist_spielesammlung_projekt.c + src/test/test_duellist_spielesammlung_projekt.c \ + C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h \ + C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/ceedling-0.31.1/vendor/unity/src/unity_internals.h \ + src/main/duellist-spielesammlung-projekt.h diff --git a/build/test/out/c/test_duellist_spielesammlung_projekt.o b/build/test/out/c/test_duellist_spielesammlung_projekt.o index 61d37cc..7bf0ec4 100644 Binary files a/build/test/out/c/test_duellist_spielesammlung_projekt.o and b/build/test/out/c/test_duellist_spielesammlung_projekt.o differ diff --git a/build/test/out/c/test_duellist_spielesammlung_projekt_runner.o b/build/test/out/c/test_duellist_spielesammlung_projekt_runner.o index 70dfa74..02e689f 100644 Binary files a/build/test/out/c/test_duellist_spielesammlung_projekt_runner.o and b/build/test/out/c/test_duellist_spielesammlung_projekt_runner.o differ diff --git a/build/test/preprocess/files/test_duellist_spielesammlung_projekt.c b/build/test/preprocess/files/test_duellist_spielesammlung_projekt.c index e69de29..74c99eb 100644 --- a/build/test/preprocess/files/test_duellist_spielesammlung_projekt.c +++ b/build/test/preprocess/files/test_duellist_spielesammlung_projekt.c @@ -0,0 +1,509 @@ +#include "src/main/duellist-spielesammlung-projekt.h" +#include "C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h" + + + + + + +void setUp(void) {} + + + +void tearDown(void) {} + + + + + +void test_coinflip_player_x_starts(void) { + + + + TicTacToeGame game; + + + + + + GameResult result = initializeGame(&game); + + + + + + UnityAssertEqualNumber((UNITY_INT)((SUCCESS)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(19), UNITY_DISPLAY_STYLE_INT); + + do {if ((game.currentPlayer == PLAYER_X || game.currentPlayer == PLAYER_O)) {} else {UnityFail( ((" Expected TRUE Was FALSE")), (UNITY_UINT)((UNITY_UINT)(20)));}} while(0); + +} + + + +void test_coinflip_player_o_starts(void) { + + + + TicTacToeGame game; + + + + + + GameResult result = initializeGame(&game); + + + + + + UnityAssertEqualNumber((UNITY_INT)((SUCCESS)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(31), UNITY_DISPLAY_STYLE_INT); + + do {if ((game.currentPlayer == PLAYER_X || game.currentPlayer == PLAYER_O)) {} else {UnityFail( ((" Expected TRUE Was FALSE")), (UNITY_UINT)((UNITY_UINT)(32)));}} while(0); + +} + + + +void test_vertical_win(void) { + + + + TicTacToeGame game = { .board = {{PLAYER_X, EMPTY, EMPTY}, + + {PLAYER_X, EMPTY, EMPTY}, + + {PLAYER_X, EMPTY, EMPTY}}, + + .currentPlayer = PLAYER_O }; + + + + + + GameResult result = checkGameResult(&game); + + + + + + UnityAssertEqualNumber((UNITY_INT)((GAME_WIN)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(46), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_horizontal_win(void) { + + + + TicTacToeGame game = { .board = {{PLAYER_X, PLAYER_X, PLAYER_X}, + + {EMPTY, EMPTY, EMPTY}, + + {EMPTY, EMPTY, EMPTY}}, + + .currentPlayer = PLAYER_O }; + + + + + + GameResult result = checkGameResult(&game); + + + + + + UnityAssertEqualNumber((UNITY_INT)((GAME_WIN)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(60), UNITY_DISPLAY_STYLE_INT); + +} + +void test_diagonal_win(void) { + + + + TicTacToeGame game = { .board = {{PLAYER_X, EMPTY, EMPTY}, + + {EMPTY, PLAYER_X, EMPTY}, + + {EMPTY, EMPTY, PLAYER_X}}, + + .currentPlayer = PLAYER_O }; + + + + + + GameResult result = checkGameResult(&game); + + + + + + UnityAssertEqualNumber((UNITY_INT)((GAME_WIN)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(73), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_valid_move_and_switch_player(void) { + + + + TicTacToeGame game = { .board = {{EMPTY, EMPTY, EMPTY}, + + {EMPTY, EMPTY, EMPTY}, + + {EMPTY, EMPTY, EMPTY}}, + + .currentPlayer = PLAYER_X }; + + + + + + GameResult moveResult = makeMove(&game, 1, 1); + + + + + + UnityAssertEqualNumber((UNITY_INT)((SUCCESS)), (UNITY_INT)((moveResult)), ( + + ((void *)0) + + ), (UNITY_UINT)(87), UNITY_DISPLAY_STYLE_INT); + + UnityAssertEqualNumber((UNITY_INT)((PLAYER_O)), (UNITY_INT)((game.currentPlayer)), ( + + ((void *)0) + + ), (UNITY_UINT)(88), UNITY_DISPLAY_STYLE_INT); + +} + + + + + +void test_invalid_input(void) { + + + + TicTacToeGame game = { .board = {{PLAYER_X, EMPTY, EMPTY}, + + {EMPTY, EMPTY, EMPTY}, + + {EMPTY, EMPTY, EMPTY}}, + + .currentPlayer = PLAYER_O }; + + + + + + GameResult result = makeMove(&game, 0, 0); + + + + + + UnityAssertEqualNumber((UNITY_INT)((INVALID_MOVE)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(103), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_valid_input(void) { + + + + TicTacToeGame game = { .board = {{EMPTY, EMPTY, EMPTY}, + + {EMPTY, EMPTY, EMPTY}, + + {EMPTY, EMPTY, EMPTY}}, + + .currentPlayer = PLAYER_X }; + + + + + + GameResult result = makeMove(&game, 1, 1); + + + + + + UnityAssertEqualNumber((UNITY_INT)((SUCCESS)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(117), UNITY_DISPLAY_STYLE_INT); + +} + + + + + +void test_invalid_input_type1(void) { + + + + TicTacToeGame game = { .board = {{PLAYER_X, EMPTY, EMPTY}, + + {EMPTY, EMPTY, EMPTY}, + + {EMPTY, EMPTY, EMPTY}}, + + .currentPlayer = PLAYER_O }; + + + + + + GameResult result = makeMove(&game, -1, 0); + + + + + + UnityAssertEqualNumber((UNITY_INT)((INVALID_MOVE)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(132), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_invalid_input_type2(void) { + + + + TicTacToeGame game = { .board = {{PLAYER_X, EMPTY, EMPTY}, + + {EMPTY, EMPTY, EMPTY}, + + {EMPTY, EMPTY, EMPTY}}, + + .currentPlayer = PLAYER_O }; + + + + + + GameResult result = makeMove(&game, 0, 3); + + + + + + UnityAssertEqualNumber((UNITY_INT)((INVALID_MOVE)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(146), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_getNumberOfMoves_returns_correct_number_of_moves(void) { + + + + TicTacToeGame game = { .board = {{PLAYER_X, EMPTY, EMPTY}, + + {EMPTY, PLAYER_O, EMPTY}, + + {EMPTY, EMPTY, EMPTY}}, + + .currentPlayer = PLAYER_X }; + + + + + + int moves = getNumberOfMoves(&game); + + + + + + UnityAssertEqualNumber((UNITY_INT)((2)), (UNITY_INT)((moves)), ( + + ((void *)0) + + ), (UNITY_UINT)(160), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_BoardFull_returns_false_when_board_is_not_full(void) { + + + + TicTacToeGame game = { .board = {{PLAYER_X, EMPTY, EMPTY}, + + {EMPTY, PLAYER_O, EMPTY}, + + {EMPTY, EMPTY, EMPTY}}, + + .currentPlayer = PLAYER_X }; + + + + + + int boardFull = BoardFull(&game); + + + + + + do {if (!(boardFull)) {} else {UnityFail( ((" Expected FALSE Was TRUE")), (UNITY_UINT)((UNITY_UINT)(174)));}} while(0); + +} + +void test_BoardFull_returns_true_when_board_is_full(void) { + + + + TicTacToeGame game = { .board = {{PLAYER_X, PLAYER_X, PLAYER_O}, + + {PLAYER_O, PLAYER_O, PLAYER_X}, + + {PLAYER_X, PLAYER_X, PLAYER_O}}, + + .currentPlayer = PLAYER_X }; + + + + + + int boardFull = BoardFull(&game); + + + + + + do {if ((boardFull)) {} else {UnityFail( ((" Expected TRUE Was FALSE")), (UNITY_UINT)((UNITY_UINT)(187)));}} while(0); + +} + +void test_getCurrentPlayer_returns_correct_player(void) { + + + + TicTacToeGame game = { .board = {{PLAYER_X, EMPTY, EMPTY}, + + {EMPTY, PLAYER_O, EMPTY}, + + {EMPTY, EMPTY, EMPTY}}, + + .currentPlayer = PLAYER_O }; + + + + + + Player currentPlayer = getCurrentPlayer(&game); + + + + + + UnityAssertEqualNumber((UNITY_INT)((PLAYER_O)), (UNITY_INT)((currentPlayer)), ( + + ((void *)0) + + ), (UNITY_UINT)(200), UNITY_DISPLAY_STYLE_INT); + +} + +void test_FieldEmpty_returns_true_for_empty_field(void) { + + + + TicTacToeGame game = { .board = {{PLAYER_X, EMPTY, EMPTY}, + + {EMPTY, PLAYER_O, EMPTY}, + + {EMPTY, EMPTY, EMPTY}} }; + + + + + + int result = FieldEmpty(&game, 0, 2); + + + + + + UnityAssertEqualNumber((UNITY_INT)((1)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(212), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_FieldEmpty_returns_false_for_nonempty_field(void) { + + + + TicTacToeGame game = { .board = {{PLAYER_X, EMPTY, EMPTY}, + + {EMPTY, PLAYER_O, EMPTY}, + + {EMPTY, EMPTY, EMPTY}} }; + + + + + + int result = FieldEmpty(&game, 0, 0); + + + + + + UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(225), UNITY_DISPLAY_STYLE_INT); + +} diff --git a/build/test/preprocess/includes/test_duellist_spielesammlung_projekt.c b/build/test/preprocess/includes/test_duellist_spielesammlung_projekt.c index dcd024e..c5516ae 100644 --- a/build/test/preprocess/includes/test_duellist_spielesammlung_projekt.c +++ b/build/test/preprocess/includes/test_duellist_spielesammlung_projekt.c @@ -1 +1,3 @@ ---- [] +--- +- C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h +- src/main/duellist-spielesammlung-projekt.h diff --git a/build/test/results/test_duellist_spielesammlung_projekt.pass b/build/test/results/test_duellist_spielesammlung_projekt.pass deleted file mode 100644 index 5046e33..0000000 --- a/build/test/results/test_duellist_spielesammlung_projekt.pass +++ /dev/null @@ -1,14 +0,0 @@ ---- -:source: - :path: src/test - :file: test_duellist_spielesammlung_projekt.c -:successes: [] -:failures: [] -:ignores: [] -:counts: - :total: 0 - :passed: 0 - :failed: 0 - :ignored: 0 -:stdout: [] -:time: 0.014711899915710092 diff --git a/build/test/runners/test_duellist_spielesammlung_projekt_runner.c b/build/test/runners/test_duellist_spielesammlung_projekt_runner.c index bba31ca..f4e3d01 100644 --- a/build/test/runners/test_duellist_spielesammlung_projekt_runner.c +++ b/build/test/runners/test_duellist_spielesammlung_projekt_runner.c @@ -10,6 +10,22 @@ char* GlobalOrderError; /*=======External Functions This Runner Calls=====*/ extern void setUp(void); extern void tearDown(void); +extern void test_coinflip_player_x_starts(void); +extern void test_coinflip_player_o_starts(void); +extern void test_vertical_win(void); +extern void test_horizontal_win(void); +extern void test_diagonal_win(void); +extern void test_valid_move_and_switch_player(void); +extern void test_invalid_input(void); +extern void test_valid_input(void); +extern void test_invalid_input_type1(void); +extern void test_invalid_input_type2(void); +extern void test_getNumberOfMoves_returns_correct_number_of_moves(void); +extern void test_BoardFull_returns_false_when_board_is_not_full(void); +extern void test_BoardFull_returns_true_when_board_is_full(void); +extern void test_getCurrentPlayer_returns_correct_player(void); +extern void test_FieldEmpty_returns_true_for_empty_field(void); +extern void test_FieldEmpty_returns_false_for_nonempty_field(void); /*=======Mock Management=====*/ @@ -26,12 +42,6 @@ static void CMock_Destroy(void) { } -/*=======Setup (stub)=====*/ -void setUp(void) {} - -/*=======Teardown (stub)=====*/ -void tearDown(void) {} - /*=======Test Reset Options=====*/ void resetTest(void); void resetTest(void) @@ -48,10 +58,54 @@ void verifyTest(void) CMock_Verify(); } +/*=======Test Runner Used To Run Each Test=====*/ +static void run_test(UnityTestFunction func, const char* name, UNITY_LINE_TYPE line_num) +{ + Unity.CurrentTestName = name; + Unity.CurrentTestLineNumber = line_num; +#ifdef UNITY_USE_COMMAND_LINE_ARGS + if (!UnityTestMatches()) + return; +#endif + Unity.NumberOfTests++; + UNITY_CLR_DETAILS(); + UNITY_EXEC_TIME_START(); + CMock_Init(); + if (TEST_PROTECT()) + { + setUp(); + func(); + } + if (TEST_PROTECT()) + { + tearDown(); + CMock_Verify(); + } + CMock_Destroy(); + UNITY_EXEC_TIME_STOP(); + UnityConcludeTest(); +} + /*=======MAIN=====*/ int main(void) { UnityBegin("test_duellist_spielesammlung_projekt.c"); + run_test(test_coinflip_player_x_starts, "test_coinflip_player_x_starts", 11); + run_test(test_coinflip_player_o_starts, "test_coinflip_player_o_starts", 23); + run_test(test_vertical_win, "test_vertical_win", 35); + run_test(test_horizontal_win, "test_horizontal_win", 49); + run_test(test_diagonal_win, "test_diagonal_win", 62); + run_test(test_valid_move_and_switch_player, "test_valid_move_and_switch_player", 76); + run_test(test_invalid_input, "test_invalid_input", 92); + run_test(test_valid_input, "test_valid_input", 106); + run_test(test_invalid_input_type1, "test_invalid_input_type1", 121); + run_test(test_invalid_input_type2, "test_invalid_input_type2", 135); + run_test(test_getNumberOfMoves_returns_correct_number_of_moves, "test_getNumberOfMoves_returns_correct_number_of_moves", 149); + run_test(test_BoardFull_returns_false_when_board_is_not_full, "test_BoardFull_returns_false_when_board_is_not_full", 163); + run_test(test_BoardFull_returns_true_when_board_is_full, "test_BoardFull_returns_true_when_board_is_full", 176); + run_test(test_getCurrentPlayer_returns_correct_player, "test_getCurrentPlayer_returns_correct_player", 189); + run_test(test_FieldEmpty_returns_true_for_empty_field, "test_FieldEmpty_returns_true_for_empty_field", 202); + run_test(test_FieldEmpty_returns_false_for_nonempty_field, "test_FieldEmpty_returns_false_for_nonempty_field", 215); return UnityEnd(); } diff --git a/src/main/duellist-spielesammlung-projekt.c b/src/main/duellist-spielesammlung-projekt.c index 4267153..63b1395 100644 --- a/src/main/duellist-spielesammlung-projekt.c +++ b/src/main/duellist-spielesammlung-projekt.c @@ -106,16 +106,22 @@ int FieldEmpty(const TicTacToeGame* game, int row, int col) { } GameResult checkGameResult(const TicTacToeGame* game) { - // Prüfen, ob ein Sieg oder ein Unentschieden vorliegt und das entsprechende Ergebnis zurückgeben + // Überprüfen, ob ein Sieg oder ein Unentschieden vorliegt und das entsprechende Ergebnis zurückgeben for (int i = 0; i < 3; ++i) { - //Zeilen und Spalten auf einen Gewinn prüfen + // Zeilen und Spalten auf einen Gewinn prüfen if ((game->board[i][0] == game->board[i][1] && game->board[i][1] == game->board[i][2] && game->board[i][0] != EMPTY) || (game->board[0][i] == game->board[1][i] && game->board[1][i] == game->board[2][i] && game->board[0][i] != EMPTY)) { return GAME_WIN; } } - + // Diagonalen auf einen Gewinn prüfen + if ((game->board[0][0] == game->board[1][1] && game->board[1][1] == game->board[2][2] && game->board[0][0] != EMPTY) || + (game->board[0][2] == game->board[1][1] && game->board[1][1] == game->board[2][0] && game->board[0][2] != EMPTY)) { + return GAME_WIN; + } + + // Überprüfen auf Unentschieden int draw = 1; for (int i = 0; i < 3; ++i) { for (int j = 0; j < 3; ++j) { diff --git a/src/main/duellist-spielesammlung-projekt.h b/src/main/duellist-spielesammlung-projekt.h index 63f6ef9..514eff2 100644 --- a/src/main/duellist-spielesammlung-projekt.h +++ b/src/main/duellist-spielesammlung-projekt.h @@ -1,6 +1,9 @@ #ifndef DUELLIST_SPIELESAMMLUNG_PROJEKT_H #define DUELLIST_SPIELESAMMLUNG_PROJEKT_H +#define MIN_AGE 12 + + typedef enum { SUCCESS,