diff --git a/build/test/cache/test_duellist_spielesammlung_projekt.c b/build/test/cache/test_duellist_spielesammlung_projekt.c index 74c99eb..e0df2e2 100644 --- a/build/test/cache/test_duellist_spielesammlung_projekt.c +++ b/build/test/cache/test_duellist_spielesammlung_projekt.c @@ -16,7 +16,7 @@ void tearDown(void) {} -void test_coinflip_player_x_starts(void) { +void test_coinflip_x_starts(void) { @@ -44,7 +44,7 @@ void test_coinflip_player_x_starts(void) { -void test_coinflip_player_o_starts(void) { +void test_coinflip_o_starts(void) { @@ -166,7 +166,7 @@ void test_diagonal_win(void) { -void test_valid_move_and_switch_player(void) { +void test_valid_move_and_switch(void) { @@ -272,7 +272,7 @@ void test_valid_input(void) { -void test_invalid_input_type1(void) { +void test_invalid_input_negative_row(void) { @@ -304,7 +304,7 @@ void test_invalid_input_type1(void) { -void test_invalid_input_type2(void) { +void test_invalid_input_overflow_column(void) { @@ -336,7 +336,7 @@ void test_invalid_input_type2(void) { -void test_getNumberOfMoves_returns_correct_number_of_moves(void) { +void test_NumberOfMoves_returns_correct_number_of_moves(void) { @@ -352,7 +352,7 @@ void test_getNumberOfMoves_returns_correct_number_of_moves(void) { - int moves = getNumberOfMoves(&game); + int moves = NumberOfMoves(&game); @@ -420,7 +420,7 @@ void test_BoardFull_returns_true_when_board_is_full(void) { } -void test_getCurrentPlayer_returns_correct_player(void) { +void test_CurrentPlayer_returns_correct_player(void) { @@ -436,7 +436,7 @@ void test_getCurrentPlayer_returns_correct_player(void) { - Player currentPlayer = getCurrentPlayer(&game); + Player currentPlayer = CurrentPlayer(&game); @@ -507,3 +507,459 @@ void test_FieldEmpty_returns_false_for_nonempty_field(void) { ), (UNITY_UINT)(225), UNITY_DISPLAY_STYLE_INT); } + + + +void test_calculate_mines_HeightWidthOne(void) + +{ + + + + int height = 1; + + int width = 1; + + int expected = 0; + + + + + + int result = calculate_mines(height, width); + + + + + + UnityAssertEqualNumber((UNITY_INT)((expected)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(239), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_calculate_mines_WidthOne(void) + +{ + + + + int height = 5; + + int width = 1; + + int expected = 0; + + + + + + int result = calculate_mines(height, width); + + + + + + UnityAssertEqualNumber((UNITY_INT)((expected)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(253), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_calculate_mines_NormalCase(void) + +{ + + + + int height = 5; + + int width = 5; + + int expected = 6; + + + + + + int result = calculate_mines(height, width); + + + + + + UnityAssertEqualNumber((UNITY_INT)((expected)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(267), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_end_check_AllUncovered_NoMines(void) + +{ + + + + char* minefield[] = { "000", + + "000", + + "000" }; + + char* mines[] = { "000", + + "000", + + "000" }; + + int height = 3; + + int width = 3; + + + + + + int result = end_check(minefield, mines, height, width); + + + + + + UnityAssertEqualNumber((UNITY_INT)((1)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(286), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_create_minefield_ValidDimensions(void) + +{ + + + + int height = 3; + + int width = 4; + + char within = '0'; + + + + + + char** result = create_minefield(height, width, within); + + + + + + do {if ((((result)) != + + ((void *)0) + + )) {} else {UnityFail( (((" Expected Non-NULL"))), (UNITY_UINT)((UNITY_UINT)((UNITY_UINT)(300))));}} while(0); + + for (int i = 0; i < height; i++) { + + do {if ((((result[i])) != + + ((void *)0) + + )) {} else {UnityFail( (((" Expected Non-NULL"))), (UNITY_UINT)((UNITY_UINT)((UNITY_UINT)(302))));}} while(0); + + for (int j = 0; j < width; j++) { + + UnityAssertEqualNumber((UNITY_INT)(UNITY_INT8 )((within)), (UNITY_INT)(UNITY_INT8 )((result[i][j])), ( + + ((void *)0) + + ), (UNITY_UINT)(304), UNITY_DISPLAY_STYLE_CHAR); + + } + + } + + + + for (int i = 0; i < height; i++) { + + free(result[i]); + + } + + free(result); + +} + + + +void test_calculate_mines_HeightOne(void) + +{ + + + + int height = 1; + + int width = 5; + + int expected = 0; + + + + + + int result = calculate_mines(height, width); + + + + + + UnityAssertEqualNumber((UNITY_INT)((expected)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(325), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_create_minefield_NegativeDimensions(void) + +{ + + + + int height = -3; + + int width = 4; + + char within = '0'; + + + + + + char** result = create_minefield(height, width, within); + + + + + + do {if ((((result)) == + + ((void *)0) + + )) {} else {UnityFail( (((" Expected NULL"))), (UNITY_UINT)((UNITY_UINT)((UNITY_UINT)(339))));}} while(0); + +} + + + +void test_calculate_mines_HeightZero(void) + +{ + + + + int height = 0; + + int width = 0; + + int expected = 0; + + + + + + int result = calculate_mines(height, width); + + + + + + UnityAssertEqualNumber((UNITY_INT)((expected)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(353), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_calculate_mines_HeightWidthNumber(void) + +{ + + + + int height = 4; + + int width = 6; + + int expected = 6; + + + + + + int result = calculate_mines(height, width); + + + + + + UnityAssertEqualNumber((UNITY_INT)((expected)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(367), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_calculate_mines_HeightWidthAgan(void) + +{ + + + + int height = 6; + + int width = 6; + + int expected = 9; + + + + + + int result = calculate_mines(height, width); + + + + + + UnityAssertEqualNumber((UNITY_INT)((expected)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(381), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_calculate_mines_HeightWidthRoundUp(void) + +{ + + + + int height = 3; + + int width = 5; + + int expected = 3; + + + + + + int result = calculate_mines(height, width); + + + + + + UnityAssertEqualNumber((UNITY_INT)((expected)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(395), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_calculate_mines_HeightWidthNoRound(void) + +{ + + + + int height = 9; + + int width = 9; + + int expected = 20; + + + + + + int result = calculate_mines(height, width); + + + + + + UnityAssertEqualNumber((UNITY_INT)((expected)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(409), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_calculate_mines_HeightWidthFinal(void) + +{ + + + + int height = 7; + + int width = 7; + + int expected = 12; + + + + + + int result = calculate_mines(height, width); + + + + + + UnityAssertEqualNumber((UNITY_INT)((expected)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(423), UNITY_DISPLAY_STYLE_INT); + +} diff --git a/build/test/dependencies/duellist-spielesammlung-projekt.d b/build/test/dependencies/duellist-spielesammlung-projekt.d new file mode 100644 index 0000000..e5d9f35 --- /dev/null +++ b/build/test/dependencies/duellist-spielesammlung-projekt.d @@ -0,0 +1,3 @@ +build/test/out/c/duellist-spielesammlung-projekt.o: \ + src/main/duellist-spielesammlung-projekt.c \ + src/main/duellist-spielesammlung-projekt.h diff --git a/build/test/out/c/duellist-spielesammlung-projekt.o b/build/test/out/c/duellist-spielesammlung-projekt.o new file mode 100644 index 0000000..92e7243 Binary files /dev/null and b/build/test/out/c/duellist-spielesammlung-projekt.o differ diff --git a/build/test/out/c/test_duellist_spielesammlung_projekt.o b/build/test/out/c/test_duellist_spielesammlung_projekt.o index 7bf0ec4..b07ba5a 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 02e689f..9fe71df 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/out/test_duellist_spielesammlung_projekt.out b/build/test/out/test_duellist_spielesammlung_projekt.out index 8bb26f0..6067fa9 100644 Binary files a/build/test/out/test_duellist_spielesammlung_projekt.out and b/build/test/out/test_duellist_spielesammlung_projekt.out differ diff --git a/build/test/preprocess/files/test_duellist_spielesammlung_projekt.c b/build/test/preprocess/files/test_duellist_spielesammlung_projekt.c index 74c99eb..e0df2e2 100644 --- a/build/test/preprocess/files/test_duellist_spielesammlung_projekt.c +++ b/build/test/preprocess/files/test_duellist_spielesammlung_projekt.c @@ -16,7 +16,7 @@ void tearDown(void) {} -void test_coinflip_player_x_starts(void) { +void test_coinflip_x_starts(void) { @@ -44,7 +44,7 @@ void test_coinflip_player_x_starts(void) { -void test_coinflip_player_o_starts(void) { +void test_coinflip_o_starts(void) { @@ -166,7 +166,7 @@ void test_diagonal_win(void) { -void test_valid_move_and_switch_player(void) { +void test_valid_move_and_switch(void) { @@ -272,7 +272,7 @@ void test_valid_input(void) { -void test_invalid_input_type1(void) { +void test_invalid_input_negative_row(void) { @@ -304,7 +304,7 @@ void test_invalid_input_type1(void) { -void test_invalid_input_type2(void) { +void test_invalid_input_overflow_column(void) { @@ -336,7 +336,7 @@ void test_invalid_input_type2(void) { -void test_getNumberOfMoves_returns_correct_number_of_moves(void) { +void test_NumberOfMoves_returns_correct_number_of_moves(void) { @@ -352,7 +352,7 @@ void test_getNumberOfMoves_returns_correct_number_of_moves(void) { - int moves = getNumberOfMoves(&game); + int moves = NumberOfMoves(&game); @@ -420,7 +420,7 @@ void test_BoardFull_returns_true_when_board_is_full(void) { } -void test_getCurrentPlayer_returns_correct_player(void) { +void test_CurrentPlayer_returns_correct_player(void) { @@ -436,7 +436,7 @@ void test_getCurrentPlayer_returns_correct_player(void) { - Player currentPlayer = getCurrentPlayer(&game); + Player currentPlayer = CurrentPlayer(&game); @@ -507,3 +507,459 @@ void test_FieldEmpty_returns_false_for_nonempty_field(void) { ), (UNITY_UINT)(225), UNITY_DISPLAY_STYLE_INT); } + + + +void test_calculate_mines_HeightWidthOne(void) + +{ + + + + int height = 1; + + int width = 1; + + int expected = 0; + + + + + + int result = calculate_mines(height, width); + + + + + + UnityAssertEqualNumber((UNITY_INT)((expected)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(239), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_calculate_mines_WidthOne(void) + +{ + + + + int height = 5; + + int width = 1; + + int expected = 0; + + + + + + int result = calculate_mines(height, width); + + + + + + UnityAssertEqualNumber((UNITY_INT)((expected)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(253), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_calculate_mines_NormalCase(void) + +{ + + + + int height = 5; + + int width = 5; + + int expected = 6; + + + + + + int result = calculate_mines(height, width); + + + + + + UnityAssertEqualNumber((UNITY_INT)((expected)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(267), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_end_check_AllUncovered_NoMines(void) + +{ + + + + char* minefield[] = { "000", + + "000", + + "000" }; + + char* mines[] = { "000", + + "000", + + "000" }; + + int height = 3; + + int width = 3; + + + + + + int result = end_check(minefield, mines, height, width); + + + + + + UnityAssertEqualNumber((UNITY_INT)((1)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(286), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_create_minefield_ValidDimensions(void) + +{ + + + + int height = 3; + + int width = 4; + + char within = '0'; + + + + + + char** result = create_minefield(height, width, within); + + + + + + do {if ((((result)) != + + ((void *)0) + + )) {} else {UnityFail( (((" Expected Non-NULL"))), (UNITY_UINT)((UNITY_UINT)((UNITY_UINT)(300))));}} while(0); + + for (int i = 0; i < height; i++) { + + do {if ((((result[i])) != + + ((void *)0) + + )) {} else {UnityFail( (((" Expected Non-NULL"))), (UNITY_UINT)((UNITY_UINT)((UNITY_UINT)(302))));}} while(0); + + for (int j = 0; j < width; j++) { + + UnityAssertEqualNumber((UNITY_INT)(UNITY_INT8 )((within)), (UNITY_INT)(UNITY_INT8 )((result[i][j])), ( + + ((void *)0) + + ), (UNITY_UINT)(304), UNITY_DISPLAY_STYLE_CHAR); + + } + + } + + + + for (int i = 0; i < height; i++) { + + free(result[i]); + + } + + free(result); + +} + + + +void test_calculate_mines_HeightOne(void) + +{ + + + + int height = 1; + + int width = 5; + + int expected = 0; + + + + + + int result = calculate_mines(height, width); + + + + + + UnityAssertEqualNumber((UNITY_INT)((expected)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(325), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_create_minefield_NegativeDimensions(void) + +{ + + + + int height = -3; + + int width = 4; + + char within = '0'; + + + + + + char** result = create_minefield(height, width, within); + + + + + + do {if ((((result)) == + + ((void *)0) + + )) {} else {UnityFail( (((" Expected NULL"))), (UNITY_UINT)((UNITY_UINT)((UNITY_UINT)(339))));}} while(0); + +} + + + +void test_calculate_mines_HeightZero(void) + +{ + + + + int height = 0; + + int width = 0; + + int expected = 0; + + + + + + int result = calculate_mines(height, width); + + + + + + UnityAssertEqualNumber((UNITY_INT)((expected)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(353), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_calculate_mines_HeightWidthNumber(void) + +{ + + + + int height = 4; + + int width = 6; + + int expected = 6; + + + + + + int result = calculate_mines(height, width); + + + + + + UnityAssertEqualNumber((UNITY_INT)((expected)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(367), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_calculate_mines_HeightWidthAgan(void) + +{ + + + + int height = 6; + + int width = 6; + + int expected = 9; + + + + + + int result = calculate_mines(height, width); + + + + + + UnityAssertEqualNumber((UNITY_INT)((expected)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(381), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_calculate_mines_HeightWidthRoundUp(void) + +{ + + + + int height = 3; + + int width = 5; + + int expected = 3; + + + + + + int result = calculate_mines(height, width); + + + + + + UnityAssertEqualNumber((UNITY_INT)((expected)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(395), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_calculate_mines_HeightWidthNoRound(void) + +{ + + + + int height = 9; + + int width = 9; + + int expected = 20; + + + + + + int result = calculate_mines(height, width); + + + + + + UnityAssertEqualNumber((UNITY_INT)((expected)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(409), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_calculate_mines_HeightWidthFinal(void) + +{ + + + + int height = 7; + + int width = 7; + + int expected = 12; + + + + + + int result = calculate_mines(height, width); + + + + + + UnityAssertEqualNumber((UNITY_INT)((expected)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(423), UNITY_DISPLAY_STYLE_INT); + +} diff --git a/build/test/results/test_duellist_spielesammlung_projekt.pass b/build/test/results/test_duellist_spielesammlung_projekt.pass new file mode 100644 index 0000000..acce313 --- /dev/null +++ b/build/test/results/test_duellist_spielesammlung_projekt.pass @@ -0,0 +1,130 @@ +--- +:source: + :path: src/test + :file: test_duellist_spielesammlung_projekt.c +:successes: +- :test: test_coinflip_x_starts + :line: 11 + :message: '' + :unity_test_time: 0 +- :test: test_coinflip_o_starts + :line: 23 + :message: '' + :unity_test_time: 0 +- :test: test_vertical_win + :line: 35 + :message: '' + :unity_test_time: 0 +- :test: test_horizontal_win + :line: 49 + :message: '' + :unity_test_time: 0 +- :test: test_diagonal_win + :line: 62 + :message: '' + :unity_test_time: 0 +- :test: test_valid_move_and_switch + :line: 76 + :message: '' + :unity_test_time: 0 +- :test: test_invalid_input + :line: 92 + :message: '' + :unity_test_time: 0 +- :test: test_valid_input + :line: 106 + :message: '' + :unity_test_time: 0 +- :test: test_invalid_input_negative_row + :line: 121 + :message: '' + :unity_test_time: 0 +- :test: test_invalid_input_overflow_column + :line: 135 + :message: '' + :unity_test_time: 0 +- :test: test_NumberOfMoves_returns_correct_number_of_moves + :line: 149 + :message: '' + :unity_test_time: 0 +- :test: test_BoardFull_returns_false_when_board_is_not_full + :line: 163 + :message: '' + :unity_test_time: 0 +- :test: test_BoardFull_returns_true_when_board_is_full + :line: 176 + :message: '' + :unity_test_time: 0 +- :test: test_CurrentPlayer_returns_correct_player + :line: 189 + :message: '' + :unity_test_time: 0 +- :test: test_FieldEmpty_returns_true_for_empty_field + :line: 202 + :message: '' + :unity_test_time: 0 +- :test: test_FieldEmpty_returns_false_for_nonempty_field + :line: 215 + :message: '' + :unity_test_time: 0 +- :test: test_calculate_mines_HeightWidthOne + :line: 228 + :message: '' + :unity_test_time: 0 +- :test: test_calculate_mines_WidthOne + :line: 242 + :message: '' + :unity_test_time: 0 +- :test: test_calculate_mines_NormalCase + :line: 256 + :message: '' + :unity_test_time: 0 +- :test: test_end_check_AllUncovered_NoMines + :line: 270 + :message: '' + :unity_test_time: 0 +- :test: test_create_minefield_ValidDimensions + :line: 289 + :message: '' + :unity_test_time: 0 +- :test: test_calculate_mines_HeightOne + :line: 314 + :message: '' + :unity_test_time: 0 +- :test: test_create_minefield_NegativeDimensions + :line: 328 + :message: '' + :unity_test_time: 0 +- :test: test_calculate_mines_HeightZero + :line: 342 + :message: '' + :unity_test_time: 0 +- :test: test_calculate_mines_HeightWidthNumber + :line: 356 + :message: '' + :unity_test_time: 0 +- :test: test_calculate_mines_HeightWidthAgan + :line: 370 + :message: '' + :unity_test_time: 0 +- :test: test_calculate_mines_HeightWidthRoundUp + :line: 384 + :message: '' + :unity_test_time: 0 +- :test: test_calculate_mines_HeightWidthNoRound + :line: 398 + :message: '' + :unity_test_time: 0 +- :test: test_calculate_mines_HeightWidthFinal + :line: 412 + :message: '' + :unity_test_time: 0 +:failures: [] +:ignores: [] +:counts: + :total: 29 + :passed: 29 + :failed: 0 + :ignored: 0 +:stdout: [] +:time: 0.05077199999959703 diff --git a/build/test/runners/test_duellist_spielesammlung_projekt_runner.c b/build/test/runners/test_duellist_spielesammlung_projekt_runner.c index f4e3d01..3817293 100644 --- a/build/test/runners/test_duellist_spielesammlung_projekt_runner.c +++ b/build/test/runners/test_duellist_spielesammlung_projekt_runner.c @@ -10,22 +10,35 @@ 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_coinflip_x_starts(void); +extern void test_coinflip_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_valid_move_and_switch(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_invalid_input_negative_row(void); +extern void test_invalid_input_overflow_column(void); +extern void test_NumberOfMoves_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_CurrentPlayer_returns_correct_player(void); extern void test_FieldEmpty_returns_true_for_empty_field(void); extern void test_FieldEmpty_returns_false_for_nonempty_field(void); +extern void test_calculate_mines_HeightWidthOne(void); +extern void test_calculate_mines_WidthOne(void); +extern void test_calculate_mines_NormalCase(void); +extern void test_end_check_AllUncovered_NoMines(void); +extern void test_create_minefield_ValidDimensions(void); +extern void test_calculate_mines_HeightOne(void); +extern void test_create_minefield_NegativeDimensions(void); +extern void test_calculate_mines_HeightZero(void); +extern void test_calculate_mines_HeightWidthNumber(void); +extern void test_calculate_mines_HeightWidthAgan(void); +extern void test_calculate_mines_HeightWidthRoundUp(void); +extern void test_calculate_mines_HeightWidthNoRound(void); +extern void test_calculate_mines_HeightWidthFinal(void); /*=======Mock Management=====*/ @@ -90,22 +103,35 @@ static void run_test(UnityTestFunction func, const char* name, UNITY_LINE_TYPE l 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_coinflip_x_starts, "test_coinflip_x_starts", 11); + run_test(test_coinflip_o_starts, "test_coinflip_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_valid_move_and_switch, "test_valid_move_and_switch", 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_invalid_input_negative_row, "test_invalid_input_negative_row", 121); + run_test(test_invalid_input_overflow_column, "test_invalid_input_overflow_column", 135); + run_test(test_NumberOfMoves_returns_correct_number_of_moves, "test_NumberOfMoves_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_CurrentPlayer_returns_correct_player, "test_CurrentPlayer_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); + run_test(test_calculate_mines_HeightWidthOne, "test_calculate_mines_HeightWidthOne", 228); + run_test(test_calculate_mines_WidthOne, "test_calculate_mines_WidthOne", 242); + run_test(test_calculate_mines_NormalCase, "test_calculate_mines_NormalCase", 256); + run_test(test_end_check_AllUncovered_NoMines, "test_end_check_AllUncovered_NoMines", 270); + run_test(test_create_minefield_ValidDimensions, "test_create_minefield_ValidDimensions", 289); + run_test(test_calculate_mines_HeightOne, "test_calculate_mines_HeightOne", 314); + run_test(test_create_minefield_NegativeDimensions, "test_create_minefield_NegativeDimensions", 328); + run_test(test_calculate_mines_HeightZero, "test_calculate_mines_HeightZero", 342); + run_test(test_calculate_mines_HeightWidthNumber, "test_calculate_mines_HeightWidthNumber", 356); + run_test(test_calculate_mines_HeightWidthAgan, "test_calculate_mines_HeightWidthAgan", 370); + run_test(test_calculate_mines_HeightWidthRoundUp, "test_calculate_mines_HeightWidthRoundUp", 384); + run_test(test_calculate_mines_HeightWidthNoRound, "test_calculate_mines_HeightWidthNoRound", 398); + run_test(test_calculate_mines_HeightWidthFinal, "test_calculate_mines_HeightWidthFinal", 412); return UnityEnd(); } diff --git a/src/main/duellist-spielesammlung-projekt.c b/src/main/duellist-spielesammlung-projekt.c index dbe397a..62c5597 100644 --- a/src/main/duellist-spielesammlung-projekt.c +++ b/src/main/duellist-spielesammlung-projekt.c @@ -8,6 +8,8 @@ #define unknown_character 'x' #define mine_character '@' +/*--------------------TicTacTo--------------------*/ + int checkAge(int age) { return age >= MIN_AGE ? 1 : 0; } @@ -138,18 +140,21 @@ GameResult checkGameResult(const TicTacToeGame* game) { return draw ? GAME_DRAW : SUCCESS; } +/*--------------------Minsweeper--------------------*/ -int berechneMinen(int hoehe, int breite) { - int anzahl_minen; - if (hoehe <= 1 || breite <= 1) { +//Nach eingabe zurberechnung der Minen anzahl +int calculate_mines(int height, int width) { + int number_mines; + if (height <= 1 || width <= 1) { return 0; } else { - num_mines = ((height * width) / 4); + number_mines = ((height * width) / 4); } - return num_mines; + return number_mines; } + //Zum erstellen des Spielfeldes char** create_minefield(int height, int width, char within) { char** minefield = (char**)calloc(height, sizeof(char*)); for (int i = 0; i < height; i++) { @@ -163,6 +168,7 @@ char** create_minefield(int height, int width, char within) { return minefield; } +//Zum Verteilen der Minen void distribute_mines(char** mines, int height, int width, int num_mines) { int i, rand_height, rand_width; @@ -180,34 +186,201 @@ void distribute_mines(char** mines, int height, int width, int num_mines) { } } - // Diagonalen Sieg 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; - } +//User das Minenfeld zu zeigen +void show_minefield(char** minefield, int height, int width) { + int i, j; + + printf("\n\n"); + printf(" "); + for (i = 0; i < height; i++) { + printf("%3d", i + 1); + } + printf("\n"); + + printf(" "); + for (i = 0; i < width; i++) { + printf("---"); + } + printf("\n"); + + for (i = 0; i < height; i++) { + printf("%3d|", i + 1); + for (j = 0; j < width; j++) { + printf("%3c", minefield[i][j]); + } + printf(" |%-3d\n", i + 1); + } + printf(" "); + for (i = 0; i < width; i++) { + printf("---"); + } + printf("\n"); + printf(" "); + for (i = 0; i < width; i++) { + printf("%3d", i + 1); + } + printf("\n\n"); +} + +//Ist keine Mine in der nähe wird die freie Fläche erweitert +int field_check(char** minefield, char** mines, int height, int width, int row, int column) { + char counter = 0; + if ((row < 0) || (row >= height) || (column < 0) || (column >= width)) { + printf("Auserhalb des Minenfeldes!\n"); + return -1; + } + + if (mines[row][column] == 1) { + return 0; + } + if ((row + 1 < height) && (mines[row + 1][column] == 1)) { + counter++; + } + if ((row - 1 >= 0) && (mines[row - 1][column] == 1)) { + counter++; + } + if ((column + 1 < width) && (mines[row][column + 1] == 1)) { + counter++; + } + if ((column - 1 >= 0) && (mines[row][column - 1] == 1)) { + counter++; + } + if ((row + 1 < height) && (column - 1 >= 0) && (mines[row + 1][column - 1] == 1)) { + counter++; + } + if ((row - 1 >= 0) && (column + 1 < width) && (mines[row - 1][column + 1] == 1)) { + counter++; + } + if ((row + 1 < height) && (column + 1 < width) && (mines[row + 1][column + 1] == 1)) { + counter++; + } + if ((row - 1 >= 0) && (column - 1 >= 0) && (mines[row - 1][column - 1] == 1)) { + counter++; + } + + minefield[row][column] = 48 + counter; + + if (counter > 0) { + return 1; + } + + if ((row + 1 < height) && (minefield[row + 1][column] == unknown_character) && (mines[row + 1][column] == 0)) { + field_check(minefield, mines, height, width, row + 1, column); + } + + if ((row - 1 >= 0) && (minefield[row - 1][column] == unknown_character) && (mines[row - 1][column] == 0)) { + field_check(minefield, mines, height, width, row - 1, column); + } + + if ((column + 1 < width) && (minefield[row][column + 1] == unknown_character) && (mines[row][column + 1] == 0)) { + field_check(minefield, mines, height, width, row, column + 1); + } + + if ((column - 1 >= 0) && (minefield[row][column - 1] == unknown_character) && (mines[row][column - 1] == 0)) { + field_check(minefield, mines, height, width, row, column - 1); + } + if ((row + 1 < height) && (column - 1 >= 0) && (minefield[row + 1][column - 1] == unknown_character) && (mines[row + 1][column - 1] == 0)) { + field_check(minefield, mines, height, width, row + 1, column - 1); + } + if ((row - 1 >= 0) && (column + 1 < width) && (minefield[row - 1][column + 1] == unknown_character) && (mines[row - 1][column + 1] == 0)) { + field_check(minefield, mines, height, width, row - 1, column + 1); + } + if ((row + 1 < height) && (column + 1 < width) && (minefield[row + 1][column + 1] == unknown_character) && (mines[row + 1][column + 1] == 0)) { + field_check(minefield, mines, height, width, row + 1, column + 1); + } + if ((row - 1 >= 0) && (column - 1 >= 0) && (minefield[row - 1][column - 1] == unknown_character) && (mines[row - 1][column - 1] == 0)) { + field_check(minefield, mines, height, width, row - 1, column - 1); + } + return 1; +} +//Überprüfe ob eine Mine getroffen wurde +int end_check(char** minefield, char** mines, int height, int width) { + int i, j; + for (i = 0; i < height; i++) { + for (j = 0; j < width; j++) { + if ((mines[i][j] == 0) && (minefield[i][j] == unknown_character)) { + return 0; + } + } + } + return 1; +} +//befreie anliegendes Feld +void free_minefield(char** minefield, int height) { + int i; + for (i = 0; i < height; i++) { + free(minefield[i]); + } + free(minefield); + minefield = NULL; +} + +//Start des Spiels int minesweeper() { int height, width, row, column; - printf("Enter the height of the game field:\n"); + printf("Geben Sie die Grösse des spielfeldes ein:\n"); scanf("%d", &height); - printf("Enter the width of the game field:\n"); + printf("Geben Sie breite des Spielfeldes ein:\n"); scanf("%d", &width); + if (height <= 0 || width <= 0 || height > max_height || width > max_width) { - printf("Invalid field dimensions.\n"); + printf("unpassen form gewählt.\n"); return 1; } int num_mines = calculate_mines(height, width); - printf("The game field is >%d< in height and >%d< in width.\n", height, width); - printf("There are %d mines on the game field.\n", num_mines); - // Matrix for the game field + printf("Das spielfeld hat eine groesse von >%d< und eine breite von: >%d<.\n", height, width); + printf("Es gibt %d Minen auf dem Spielfeld.\n", num_mines); + char** minefield = create_minefield(height, width, unknown_character); char** mines = create_minefield(height, width, 0); + distribute_mines(mines, height, width, num_mines); + + while (1) { + printf("Geben 'vertikale horizonatle' ein um zu spielen Bsp vertikal 0 und horizontal: 0\n"); + if (scanf("%d %d", &row, &column) != 2) { + printf("Falsche eingabe!\n"); + return 1; + } + row--; + column--; + + if ((row == -1) && (column == -1)) { + break; + } + if (row >= height || row < 0) { + printf("hoehe zwischen 1 und %d!\n", height); + continue; + } + if (column >= width || column < 0) { + printf("breite zwischen 1 und %d!\n", width); + continue; + } + + if (field_check(minefield, mines, height, width, row, column) == 0) { + show_minefield(mines, height, width); + printf("höhe: %d breite: %d war leider eine mine!\n", row + 1, column + 1); + break; + } + + else if (end_check(minefield, mines, height, width)) { + show_minefield(mines, height, width); + printf("Sie haben es erfolgreich geloesst!\n"); + break; + } + + else { + show_minefield(mines, height, width); + } + } + free_minefield(minefield, height); + free_minefield(mines, height); return 1; } diff --git a/src/main/duellist-spielesammlung-projekt.h b/src/main/duellist-spielesammlung-projekt.h index 2f63a3e..fe4db1d 100644 --- a/src/main/duellist-spielesammlung-projekt.h +++ b/src/main/duellist-spielesammlung-projekt.h @@ -38,18 +38,24 @@ int FieldEmpty(const TicTacToeGame* game, int row, int col); int decideGameType(); Player playRockPaperScissors(); -#endif // DUEELIST_SPIELESAMMLUNG_PROJEKT_ - - - - - - - - - +#include +#include +#include +#define max_height 10 +#define max_width 10 +#define unknown_character 'x' +#define mine_character '@' +int end_check(char** minefield, char** mines, int height, int width); +int field_check(char** minefield, char** mines, int height, int width, int row, int column); +void show_minefield(char** minefield, int height, int width); +void free_minefield(char** minefield, int height); +int calculate_mines(int height, int width); +char** create_minefield(int height, int width, char within); +void distribute_mines(char** mines, int height, int width, int num_mines); +int minesweeper(); +#endif // DUEELIST_SPIELESAMMLUNG_PROJEKT_H \ No newline at end of file diff --git a/src/test/test_duellist_spielesammlung_projekt.c b/src/test/test_duellist_spielesammlung_projekt.c index c1759cd..a0d4547 100644 --- a/src/test/test_duellist_spielesammlung_projekt.c +++ b/src/test/test_duellist_spielesammlung_projekt.c @@ -225,30 +225,201 @@ void test_FieldEmpty_returns_false_for_nonempty_field(void) { TEST_ASSERT_EQUAL(0, result); } -#endif // TEST +void test_calculate_mines_HeightWidthOne(void) +{ + /* arrange */ + int height = 1; + int width = 1; + int expected = 0; + + /* act */ + int result = calculate_mines(height, width); + + /* assert */ + TEST_ASSERT_EQUAL_INT(expected, result); +} +void test_calculate_mines_WidthOne(void) +{ + /* arrange */ + int height = 5; + int width = 1; + int expected = 0; + /* act */ + int result = calculate_mines(height, width); + /* assert */ + TEST_ASSERT_EQUAL_INT(expected, result); +} +void test_calculate_mines_NormalCase(void) +{ + /* arrange */ + int height = 5; + int width = 5; + int expected = 6; + /* act */ + int result = calculate_mines(height, width); + /* assert */ + TEST_ASSERT_EQUAL_INT(expected, result); +} +void test_end_check_AllUncovered_NoMines(void) +{ + /* arrange */ + char* minefield[] = { "000", + "000", + "000" }; + char* mines[] = { "000", + "000", + "000" }; + int height = 3; + int width = 3; + + /* act */ + int result = end_check(minefield, mines, height, width); + + /* assert */ + TEST_ASSERT_EQUAL_INT(1, result); +} +void test_create_minefield_ValidDimensions(void) +{ + /* arrange */ + int height = 3; + int width = 4; + char within = '0'; + + /* act */ + char** result = create_minefield(height, width, within); + + /* assert */ + TEST_ASSERT_NOT_NULL(result); + for (int i = 0; i < height; i++) { + TEST_ASSERT_NOT_NULL(result[i]); + for (int j = 0; j < width; j++) { + TEST_ASSERT_EQUAL_CHAR(within, result[i][j]); + } + } + // Free allocated memory + for (int i = 0; i < height; i++) { + free(result[i]); + } + free(result); +} +void test_calculate_mines_HeightOne(void) +{ + /* arrange */ + int height = 1; + int width = 5; + int expected = 0; + /* act */ + int result = calculate_mines(height, width); + /* assert */ + TEST_ASSERT_EQUAL_INT(expected, result); +} +void test_create_minefield_NegativeDimensions(void) +{ + /* arrange */ + int height = -3; + int width = 4; + char within = '0'; + /* act */ + char** result = create_minefield(height, width, within); + /* assert */ + TEST_ASSERT_NULL(result); +} +void test_calculate_mines_HeightZero(void) +{ + /* arrange */ + int height = 0; + int width = 0; + int expected = 0; + /* act */ + int result = calculate_mines(height, width); + /* assert */ + TEST_ASSERT_EQUAL_INT(expected, result); +} +void test_calculate_mines_HeightWidthNumber(void) +{ + /* arrange */ + int height = 4; + int width = 6; + int expected = 6; + /* act */ + int result = calculate_mines(height, width); + /* assert */ + TEST_ASSERT_EQUAL_INT(expected, result); +} +void test_calculate_mines_HeightWidthAgan(void) +{ + /* arrange */ + int height = 6; + int width = 6; + int expected = 9; + /* act */ + int result = calculate_mines(height, width); + /* assert */ + TEST_ASSERT_EQUAL_INT(expected, result); +} +void test_calculate_mines_HeightWidthRoundUp(void) +{ + /* arrange */ + int height = 3; + int width = 5; + int expected = 3; + /* act */ + int result = calculate_mines(height, width); + /* assert */ + TEST_ASSERT_EQUAL_INT(expected, result); +} + +void test_calculate_mines_HeightWidthNoRound(void) +{ + /* arrange */ + int height = 9; + int width = 9; + int expected = 20; + + /* act */ + int result = calculate_mines(height, width); + + /* assert */ + TEST_ASSERT_EQUAL_INT(expected, result); +} + +void test_calculate_mines_HeightWidthFinal(void) +{ + /* arrange */ + int height = 7; + int width = 7; + int expected = 12; + + /* act */ + int result = calculate_mines(height, width); + + /* assert */ + TEST_ASSERT_EQUAL_INT(expected, result); +} +#endif // TEST diff --git a/team.md b/team.md index 0f81dee..17044f8 100644 --- a/team.md +++ b/team.md @@ -2,3 +2,4 @@ - Daniel M, fdai7745 - Erwin Minaev, fdai7776 - Homan Halimi, fdai7892 +- Areeb Ahmad Bilal, fdai7820