From f93b71405b08dd76d8c2aed121a6d17fea6bc1b5 Mon Sep 17 00:00:00 2001 From: fdai7892 Date: Wed, 7 Feb 2024 22:00:29 +0100 Subject: [PATCH] =?UTF-8?q?=20Funktion=20ge=C3=A4ndert=20und=20define=20hi?= =?UTF-8?q?nzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/test/cache/defines_dependency.yml | 4 +- .../test_duellist_spielesammlung_projekt.c | 509 ++++++++++++++++++ .../test_duellist_spielesammlung_projekt.d | 5 +- .../c/test_duellist_spielesammlung_projekt.o | Bin 564 -> 10168 bytes ...t_duellist_spielesammlung_projekt_runner.o | Bin 4523 -> 7114 bytes .../test_duellist_spielesammlung_projekt.c | 509 ++++++++++++++++++ .../test_duellist_spielesammlung_projekt.c | 4 +- .../test_duellist_spielesammlung_projekt.pass | 14 - ...t_duellist_spielesammlung_projekt_runner.c | 66 ++- src/main/duellist-spielesammlung-projekt.c | 12 +- src/main/duellist-spielesammlung-projekt.h | 3 + 11 files changed, 1100 insertions(+), 26 deletions(-) delete mode 100644 build/test/results/test_duellist_spielesammlung_projekt.pass 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 61d37cc0e772ffe0431c67854c52481ec4c738ff..7bf0ec4c005b05cfab59d5b317568befb9176236 100644 GIT binary patch literal 10168 zcmcIq3v3+48J@k{voEooII$BajZu$cAXV@=PC^JF4?FhRxHwMa2O(<8az5{!m)yhM z+jAbIf;LnnMYM#{@@QHiD6~L9l=2i%ChtlGd@IJl*U}^^Di!BcGIr5a#vVOK zK%{PA)oYrXmr5HF+R=ut*&ayPEnesWLnz%+$JkS!7qAaE&bQ=Z0od0!!1oC3UbpQ~ z6m}P1;<0N$Y3p1MBhJORe*8pnCaXTn(hXi<3l*YyFm;iZG#v&&K zcoJ!2lV&6gg9&vdA5J4%>()aAIVf(2M34#f5a1`R$BIu@4-v%4hg}a*t8q~}CT>nW zgzn7w=z`ni`Pi`YME@-V2c9ARXE6lX?zc}pJQg|0BjBmqca`pwrhWqqCWHbaJ0n!G z-(FQ{>OQ5N`}#FL2GB3vCq-0lj}fJ_eNs-Xa97E5(q<$mkhix})AM@Jrf`Z?aA$rzw|xrrqP{j38OIg32?I-jy!U(aliz>uAy2!H zU`n>9UbhR|)9U4C=)V6~J$8QWLndbPN2wNS1HEqYdgs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TfDDj?1A~B*zM&bArw8R2 znS<5C2o)fM1!xK~a9}WSm^?>PMOiN`Gba@)^Y1?cLpoTY8nW8Sj7q|+V1db!N}&@2 qSd@LC(jXTyGb$r12D2j=7$(Q4C{NDgQs>qyN=Yn9RH>?}VgLZ-rW^tQ 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 70dfa7409334a2d094cec374838ce3fa0aa581a3..02e689ff7a87c4614fdf0dc7b36ad26362d99ada 100644 GIT binary patch literal 7114 zcmbVQdu$v>8K1q~J6~cacH&EMXe2JFo1{?R*?Bch6UT`kkwso4aa$Lc?LGF+o80Z5 z_V%1O1gXNR`jncg0t8qpArx8=CI3*NKGPRbijXMKcak=t6{#qqNJRqLCj7pcxxGEF z9Rg#|+&919_sx7e^X<&+Y*m^Vr3AfD#X~w3S*zPi254*#98NU ziEPSE`Shj}dsyf3M7ms_j`L%;lU~*_GVYjB#YZ6=)2cP`%iDA6JMM#jZQ+1kPjXc~ zb`Clt4ba82QksL@!&){cyXc8(sUOeUO{6bzy_KClgvNleiMfn@Pqqg)M0=}N*XgZC zdq<)7nAAg6=&io4PH(yj?|04GI;tJDcbe-UwAa~_yzcrs@Smuun6qEWe(~sBZ|Ls# zPk6&Mopkut7og)WCq9gxr?$_(ck$xI^Y2sfI2D8)K1tf=Uq)S+OnlgOZ-3KKnz?)X zTaHrH9EqWrIIbL}-xJ{|N=hffBKpv99_A;s_T@l%t9Kl)%;v(q{n3lRo0d6$6S;76 zy&n_reKhf53%7(3bt2@x_GlyZ*w?NtqhHBwqi(@{PICP|u1j)PNiO5#7D%p3aupx< zuM48hZpq#4<4#L%tK=qq+;fr}k=!#r?qSL8mE0>n?rzDAOYWSHD@yK8$$jGEz9PAA zNiK%Ktd7fS$sLv4Rv))ea>pchyN~jB=`2EL5z#UUKZc#y&TZ5o#IRv~mTrq?Zb*al_FM z=w&zMxaH|tyN(?*9M{aG3i^K268fXIV;;0E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Xyo+Nr==3+6$Hwjl}epSD(%0tg|C#>0%VW66?b z7cM0&J6o*gOq^HA)78wz@ZiAZ(UD})%HZ6~Y$OY2sglHbnHW@J)--cPI1UUZhKCYE z$%{DS%1*M%t2J41vhVF^-aRG}9;Ox!wZs~tCs~hy9o=;7bg=>u%cA1utg^D>w}XZ0 z&@LvfUAuN-;>5({_~iKX#44xBiPfnqtJhaUA@qK6c6Kb@|Dp7Vg6TP8+!-)b=anmdD;5yKfT-jHedspSG#Xt+_k?2_&joNz5N+w zC%#Lvp$T^iqQg?c)T9qdX&ogGOBY>2iPZw$7Rn!;z7K6YfZT${2ZG`l^7v3kheGOKjU1dN zINk{IZmNGVa?5-5qW-mr^}IKy?xl!d501Iph$kiLUWxdz;2dq>Fu)fHPW;a`!EZ!< z7Y5UBJe7N+34R|orayZSju>#_DAm|P@YBCN36DW=_+8joRg(wt+|UHi@5aP898Ua@ z)dauuxYb}f1eC{ylZqtKfJ_Gv!>IjL_NmQ{GvKIHLyQ1oK}+P!OtpZmIA5;G=}g8k zFZ!C3whOozdPE!wW=+P8fYiV0+uYowgt=zqW#PR)p$v7yke3Bd_O2A3R=ax` x{+-3xz0??W_n!Z+Gjg`Qtp|;7TJj(jn!K9Tpt^gSA@8#@W&t-eCC}qh_&?lVZkzxB 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,