diff --git a/.gitlab/.gitlab-webide.yml b/.gitlab/.gitlab-webide.yml new file mode 100644 index 0000000..faf8c97 --- /dev/null +++ b/.gitlab/.gitlab-webide.yml @@ -0,0 +1,9 @@ +terminal: + # This can be any image that has the necessary runtime environment for your project. + image: node:10-alpine + before_script: + - apk update + script: sleep 60 + variables: + RAILS_ENV: "test" + NODE_ENV: "test" diff --git a/build/artifacts/release/project.out b/build/artifacts/release/project.out index 7e9f672..2b21304 100755 Binary files a/build/artifacts/release/project.out and b/build/artifacts/release/project.out differ diff --git a/build/release/dependencies/get_character.d b/build/release/dependencies/get_character.d new file mode 100644 index 0000000..ba996cf --- /dev/null +++ b/build/release/dependencies/get_character.d @@ -0,0 +1 @@ +build/release/out/c/get_character.o: src/main/c/Snake/get_character.c diff --git a/build/release/dependencies/main.d b/build/release/dependencies/main.d index 4dccf23..cab5c66 100644 --- a/build/release/dependencies/main.d +++ b/build/release/dependencies/main.d @@ -1,2 +1,3 @@ build/release/out/c/main.o: src/main/c/main.c \ - src/main/c/Template/game100.h + src/main/c/Snake/snake_start.h \ + src/main/c/Minesweeper/minesweeper_start.h src/main/c/Pong/pong.h diff --git a/build/release/dependencies/minesweeper_start.d b/build/release/dependencies/minesweeper_start.d new file mode 100644 index 0000000..67807f6 --- /dev/null +++ b/build/release/dependencies/minesweeper_start.d @@ -0,0 +1,3 @@ +build/release/out/c/minesweeper_start.o: \ + src/main/c/Minesweeper/minesweeper_start.c \ + src/main/c/Minesweeper/minesweeper_start.h diff --git a/build/release/dependencies/pong.d b/build/release/dependencies/pong.d new file mode 100644 index 0000000..4a40a82 --- /dev/null +++ b/build/release/dependencies/pong.d @@ -0,0 +1 @@ +build/release/out/c/pong.o: src/main/c/Pong/pong.c diff --git a/build/release/dependencies/snake_start.d b/build/release/dependencies/snake_start.d new file mode 100644 index 0000000..974ab7a --- /dev/null +++ b/build/release/dependencies/snake_start.d @@ -0,0 +1,2 @@ +build/release/out/c/snake_start.o: src/main/c/Snake/snake_start.c \ + src/main/c/Snake/snake_start.h src/main/c/Snake/get_character.h diff --git a/build/release/dependencies/tictactoe.d b/build/release/dependencies/tictactoe.d new file mode 100644 index 0000000..3bd3806 --- /dev/null +++ b/build/release/dependencies/tictactoe.d @@ -0,0 +1 @@ +build/release/out/c/tictactoe.o: src/main/c/GameTic_Tac_Toe/tictactoe.c diff --git a/build/release/out/c/get_character.o b/build/release/out/c/get_character.o new file mode 100644 index 0000000..570722e Binary files /dev/null and b/build/release/out/c/get_character.o differ diff --git a/build/release/out/c/main.o b/build/release/out/c/main.o index b7d6436..17adbcd 100644 Binary files a/build/release/out/c/main.o and b/build/release/out/c/main.o differ diff --git a/build/release/out/c/minesweeper_start.o b/build/release/out/c/minesweeper_start.o new file mode 100644 index 0000000..0218308 Binary files /dev/null and b/build/release/out/c/minesweeper_start.o differ diff --git a/build/release/out/c/pong.o b/build/release/out/c/pong.o new file mode 100644 index 0000000..6cbb7e4 Binary files /dev/null and b/build/release/out/c/pong.o differ diff --git a/build/release/out/c/snake_start.o b/build/release/out/c/snake_start.o new file mode 100644 index 0000000..de4954f Binary files /dev/null and b/build/release/out/c/snake_start.o differ diff --git a/build/release/out/c/tictactoe.o b/build/release/out/c/tictactoe.o new file mode 100644 index 0000000..39f5d21 Binary files /dev/null and b/build/release/out/c/tictactoe.o differ diff --git a/build/release/project.out b/build/release/project.out deleted file mode 100755 index 7e9f672..0000000 Binary files a/build/release/project.out and /dev/null differ diff --git a/build/test/cache/defines_dependency.yml b/build/test/cache/defines_dependency.yml index b227090..6dae52a 100644 --- a/build/test/cache/defines_dependency.yml +++ b/build/test/cache/defines_dependency.yml @@ -1,3 +1,13 @@ --- src/main/c/Template/game100.c: - TEST +src/main/c/Snake/snake_start.c: +- TEST +src/main/c/Snake/get_character.c: +- TEST +src/main/c/Minesweeper/minesweeper_start.c: +- TEST +src/main/c/GameTic_Tac_Toe/tictactoe.c: +- TEST +src/main/c/Pong/pong.c: +- TEST diff --git a/build/test/cache/test_bomb_in_array.c b/build/test/cache/test_bomb_in_array.c new file mode 100644 index 0000000..14de752 --- /dev/null +++ b/build/test/cache/test_bomb_in_array.c @@ -0,0 +1,79 @@ +#include "build/temp/../../src/main/c/Minesweeper/minesweeper_start.h" +#include "/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h" + + + + + + +void setUp(void){} + +void tearDown(void){} + + + + + +void test_bomb_in_array(void){ + + + + + + _Bool + + result; + + int array[] = {5, 9, 42, 6, 87, 95, 202, 13, 45 ,78}; + + int bomb = 42; + + int length = 10; + + + + + + result = array_contains_value(array, bomb, length); + + + + + + do {if ((result)) {} else {UnityFail( ((" Expected TRUE Was FALSE")), (UNITY_UINT)((UNITY_UINT)(22)));}} while(0); + +} + + + + + +void test_bomb_not_in_array(void){ + + + + + + _Bool + + result; + + int array[] = {5, 9, 42, 6, 87, 95, 202, 13, 45 ,78}; + + int bomb = 0; + + int length = 10; + + + + + + result = array_contains_value(array, bomb, length); + + + + + + do {if (!(result)) {} else {UnityFail( ((" Expected FALSE Was TRUE")), (UNITY_UINT)((UNITY_UINT)(37)));}} while(0); + +} diff --git a/build/test/cache/test_checkCollision.c b/build/test/cache/test_checkCollision.c new file mode 100644 index 0000000..79e7083 --- /dev/null +++ b/build/test/cache/test_checkCollision.c @@ -0,0 +1,143 @@ +#include "src/main/c/Pong/pong.h" +#include "/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h" + + + + + + + + +typedef struct { + + int x; + + int y; + + int speedX; + + int speedY; + +} Ball; + + + +typedef struct { + + int x; + + int y; + + int width; + + int height; + +} Paddle; + + + +void setUp(void){ + + + +} + + + +void tearDown(void){ + +} + + + +void test_checkCollision(void){ + + Ball ball = {10, 10, 1, 1}; + + Paddle paddle = {50, 10, 5, 10}; + + + + + + ball.x = 0; + + int result1 = checkCollision(ball, paddle.y, paddle.y); + + UnityAssertEqualNumber((UNITY_INT)((1)), (UNITY_INT)((result1)), ( + + ((void *)0) + + ), (UNITY_UINT)(35), UNITY_DISPLAY_STYLE_INT); + + + + ball.x = 40 - 1; + + int result2 = checkCollision(ball, paddle.y, paddle.y); + + UnityAssertEqualNumber((UNITY_INT)((2)), (UNITY_INT)((result2)), ( + + ((void *)0) + + ), (UNITY_UINT)(39), UNITY_DISPLAY_STYLE_INT); + + + + + + ball.x = 5; + + ball.y = 0; + + int result3 = checkCollision(ball, paddle.y, paddle.y); + + UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((result3)), ( + + ((void *)0) + + ), (UNITY_UINT)(45), UNITY_DISPLAY_STYLE_INT); + + + + ball.y = 20 - 1; + + int result4 = checkCollision(ball, paddle.y, paddle.y); + + UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((result4)), ( + + ((void *)0) + + ), (UNITY_UINT)(49), UNITY_DISPLAY_STYLE_INT); + + + + + + ball.x = paddle.x - 1; + + ball.y = paddle.y + 1; + + int result5 = checkCollision(ball, paddle.y, paddle.y); + + UnityAssertEqualNumber((UNITY_INT)((2)), (UNITY_INT)((result5)), ( + + ((void *)0) + + ), (UNITY_UINT)(55), UNITY_DISPLAY_STYLE_INT); + + + + ball.x = paddle.x + 1; + + ball.y = paddle.y + 1; + + int result6 = checkCollision(ball, paddle.y, paddle.y); + + UnityAssertEqualNumber((UNITY_INT)((2)), (UNITY_INT)((result6)), ( + + ((void *)0) + + ), (UNITY_UINT)(60), UNITY_DISPLAY_STYLE_INT); + +} diff --git a/build/test/cache/test_checkGameEnd.c b/build/test/cache/test_checkGameEnd.c new file mode 100644 index 0000000..3c0d662 --- /dev/null +++ b/build/test/cache/test_checkGameEnd.c @@ -0,0 +1,69 @@ +#include "src/main/c/Pong/pong.h" +#include "/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h" + + + + + + + + +void setUp(void){ + + + +} + + + +void tearDown(void){ + +} + + + +void test_checkGameEnd(void){ + + + + int maxScore = 5; + + int score1 = 4, score2 = 2; + + + + + + int result = checkGameEnd(score1, score2, maxScore); + + + + + + UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(23), UNITY_DISPLAY_STYLE_INT); + + + + + + score1 = 5; + + result = checkGameEnd(score1, score2, maxScore); + + UnityAssertEqualNumber((UNITY_INT)((1)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(28), UNITY_DISPLAY_STYLE_INT); + + + + + + + +} diff --git a/build/test/cache/test_clearScreen.c b/build/test/cache/test_clearScreen.c new file mode 100644 index 0000000..74ec6bf --- /dev/null +++ b/build/test/cache/test_clearScreen.c @@ -0,0 +1,73 @@ +#include "src/main/c/Pong/pong.h" +#include "/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h" + + + + + + + + + + +char screen[20][40 +1]; + + + +void setUp(void){ + + + +} + + + +void tearDown(void){ + +} + + + +void test_clearScreen(void){ + + + + int i, j; + + for (i = 0; i < 20; i++) { + + for (j = 0; j < 40; j++) { + + screen[i][j] = ' '; + + } + + screen[i][j] = '\0'; + + } + + + + + + clearScreen(); + + + + + + for (i = 0; i < 20; i++) { + + for (j = 0; j < 40; j++) { + + UnityAssertEqualNumber((UNITY_INT)((' ')), (UNITY_INT)((screen[i][j])), ( + + ((void *)0) + + ), (UNITY_UINT)(33), UNITY_DISPLAY_STYLE_INT); + + } + + } + +} diff --git a/build/test/cache/test_collision.c b/build/test/cache/test_collision.c new file mode 100644 index 0000000..a159403 --- /dev/null +++ b/build/test/cache/test_collision.c @@ -0,0 +1,102 @@ +#include "src/main/c/Snake/get_character.h" +#include "src/main/c/Snake/snake_start.h" +#include "/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h" + + + + + + +void setUp(void){} + +void tearDown(void){} + + + + + +void test_self_collision(void){ + + + + + + _Bool + + result; + + Snake snake = {1, 5, {6 + 16 * 6, 6 + 16 * 7, 7 + 16 * 7, 7 + 16 * 6, 6 + 16 * 6}}; + + + + + + result = check_if_dead(&snake); + + + + + + do {if ((result)) {} else {UnityFail( ((" Expected TRUE Was FALSE")), (UNITY_UINT)((UNITY_UINT)(21)));}} while(0); + +} + + + + + +void test_no_collision(void){ + + + + + + _Bool + + result; + + Snake snake = initialize_snake(); + + + + + + result = check_if_dead(&snake); + + + + + + do {if (!(result)) {} else {UnityFail( ((" Expected FALSE Was TRUE")), (UNITY_UINT)((UNITY_UINT)(34)));}} while(0); + +} + + + + + +void test_wall_collision(void){ + + + + + + _Bool + + result; + + Snake snake = {-1, 4, {0 + 16 * 6, 1 + 16 * 6, 2 + 16 * 6, 3 + 16 * 6}}; + + + + + + result = check_if_dead(&snake); + + + + + + do {if ((result)) {} else {UnityFail( ((" Expected TRUE Was FALSE")), (UNITY_UINT)((UNITY_UINT)(47)));}} while(0); + +} diff --git a/build/test/cache/test_is_Valid_tile.c b/build/test/cache/test_is_Valid_tile.c new file mode 100644 index 0000000..5911aa4 --- /dev/null +++ b/build/test/cache/test_is_Valid_tile.c @@ -0,0 +1,269 @@ +#include "build/temp/../../src/main/c/Minesweeper/minesweeper_start.h" +#include "/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h" + + + + + + +void setUp(void){} + +void tearDown(void){} + + + + + +void test_detect_not_valid_tile_left(void){ + + + + Minesweeper_Board board = initialize_minesweeper(); + + int tile = 0; + + int direction = 2; + + int result; + + + + + + result = is_Valid_tile(&board, tile, direction); + + + + + + UnityAssertEqualNumber((UNITY_INT)((-1)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(21), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_detect_not_valid_tile_up(void){ + + + + Minesweeper_Board board = initialize_minesweeper(); + + int tile = 0; + + int direction = 3; + + int result; + + + + + + result = is_Valid_tile(&board, tile, direction); + + + + + + UnityAssertEqualNumber((UNITY_INT)((-1)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(35), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_detect_not_valid_tile_right(void){ + + + + Minesweeper_Board board = initialize_minesweeper(); + + int tile = board.width * board.height - 1; + + int direction = 5; + + int result; + + + + + + result = is_Valid_tile(&board, tile, direction); + + + + + + UnityAssertEqualNumber((UNITY_INT)((-1)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(49), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_detect_not_valid_tile_down(void){ + + + + Minesweeper_Board board = initialize_minesweeper(); + + int tile = board.width * board.height - 1; + + int direction = 4; + + int result; + + + + + + result = is_Valid_tile(&board, tile, direction); + + + + + + UnityAssertEqualNumber((UNITY_INT)((-1)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(63), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_detect_valid_tile_left(void){ + + + + Minesweeper_Board board = initialize_minesweeper(); + + int tile = board.width * board.height - 1; + + int direction = 2; + + int result; + + + + + + result = is_Valid_tile(&board, tile, direction); + + + + + + UnityAssertEqualNumber((UNITY_INT)((board.width * board.height - 2)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(77), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_detect_valid_tile_up(void){ + + + + Minesweeper_Board board = initialize_minesweeper(); + + int tile = board.width * board.height - 1; + + int direction = 3; + + int result; + + + + + + result = is_Valid_tile(&board, tile, direction); + + + + + + UnityAssertEqualNumber((UNITY_INT)((board.width * (board.height - 1) - 1)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(91), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_detect_valid_tile_right(void){ + + + + Minesweeper_Board board = initialize_minesweeper(); + + int tile = 0; + + int direction = 5; + + int result; + + + + + + result = is_Valid_tile(&board, tile, direction); + + + + + + UnityAssertEqualNumber((UNITY_INT)((1)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(105), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_detect_valid_tile_down(void){ + + + + Minesweeper_Board board = initialize_minesweeper(); + + int tile = 0; + + int direction = 4; + + int result; + + + + + + result = is_Valid_tile(&board, tile, direction); + + + + + + UnityAssertEqualNumber((UNITY_INT)((0 + board.width)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(119), UNITY_DISPLAY_STYLE_INT); + +} diff --git a/build/test/cache/test_moving_snake.c b/build/test/cache/test_moving_snake.c new file mode 100644 index 0000000..b305c52 --- /dev/null +++ b/build/test/cache/test_moving_snake.c @@ -0,0 +1,142 @@ +#include "build/temp/../../src/main/c/Snake/get_character.h" +#include "build/temp/../../src/main/c/Snake/snake_start.h" +#include "/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h" + + + + + + +void setUp(void){} + +void tearDown(void){} + + + + + +void test_moving_right(void){ + + + + + + _Bool + + result; + + Snake snake = {1, 3, {8 + 16 * 6, 7 + 16 * 6, 6 + 16 * 6}}; + + Snake expected = {1, 3, {9 + 16 * 6, 8 + 16 * 6, 7 + 16 * 6}}; + + + + + + move_snake(&snake); + + result = memcmp(&snake, &expected, sizeof(Snake)) == 0; + + + + + + do {if ((result)) {} else {UnityFail( ((" Expected TRUE Was FALSE")), (UNITY_UINT)((UNITY_UINT)(24)));}} while(0); + +} + + + +void test_moving_down(void){ + + + + + + _Bool + + result; + + Snake snake = {16, 3, {8 + 16 * 6, 7 + 16 * 6, 6 + 16 * 6}}; + + Snake expected = {16, 3, {8 + 16 * 7, 8 + 16 * 6, 7 + 16 * 6}}; + + + + + + move_snake(&snake); + + result = memcmp(&snake, &expected, sizeof(Snake)) == 0; + + + + + + do {if ((result)) {} else {UnityFail( ((" Expected TRUE Was FALSE")), (UNITY_UINT)((UNITY_UINT)(38)));}} while(0); + +} + + + +void test_moving_left(void){ + + + + + + _Bool + + result; + + Snake snake = {-1, 3, {8 + 16 * 6, 7 + 16 * 6, 6 + 16 * 6}}; + + Snake expected = {-1, 3, {7 + 16 * 6, 8 + 16 * 6, 7 + 16 * 6}}; + + + + + + move_snake(&snake); + + result = memcmp(&snake, &expected, sizeof(Snake)) == 0; + + + + + + do {if ((result)) {} else {UnityFail( ((" Expected TRUE Was FALSE")), (UNITY_UINT)((UNITY_UINT)(52)));}} while(0); + +} + + + +void test_moving_up(void){ + + + + + + _Bool + + result; + + Snake snake = {-16, 3, {8 + 16 * 6, 7 + 16 * 6, 6 + 16 * 6}}; + + Snake expected = {-16, 3, {8 + 16 * 5, 8 + 16 * 6, 7 + 16 * 6}}; + + + + + + move_snake(&snake); + + result = memcmp(&snake, &expected, sizeof(Snake)) == 0; + + + + + + do {if ((result)) {} else {UnityFail( ((" Expected TRUE Was FALSE")), (UNITY_UINT)((UNITY_UINT)(66)));}} while(0); + +} diff --git a/build/test/cache/test_number_of_bombs.c b/build/test/cache/test_number_of_bombs.c new file mode 100644 index 0000000..9b1981f --- /dev/null +++ b/build/test/cache/test_number_of_bombs.c @@ -0,0 +1,205 @@ +#include "build/temp/../../src/main/c/Minesweeper/minesweeper_start.h" +#include "/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h" + + + + + + +void setUp(void){} + +void tearDown(void){} + + + + + +void test_no_bombs_placed_around_tile(void){ + + + + int result; + + Minesweeper_Board board = initialize_minesweeper(); + + int tile = 0 + board.width * 1; + + + + + + result = number_of_bombs(&board, tile); + + + + + + UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(21), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_searching_for_bombs_on_correct_tiles(void){ + + + + int result; + + Minesweeper_Board board = initialize_minesweeper(); + + int tile = 0 + board.width * 1; + + board.bombs[0] = 0 + board.width * 3; + + board.bombs[1] = 2 + board.width * 1; + + board.bombs[2] = board.width - 1 + board.width * 1; + + board.bombs[3] = 0 + board.width * (board.height - 1); + + + + + + result = number_of_bombs(&board, tile); + + + + + + UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(38), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_2_bombs_around_tile(void){ + + + + int result; + + Minesweeper_Board board = initialize_minesweeper(); + + int tile = 0 + board.width * 1; + + board.bombs[0] = 0 + board.width * 2; + + board.bombs[1] = 1 + board.width * 1; + + board.bombs[2] = board.width - 1 + board.width * 1; + + board.bombs[3] = 0 + board.width * (board.height - 1); + + + + + + result = number_of_bombs(&board, tile); + + + + + + UnityAssertEqualNumber((UNITY_INT)((2)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(55), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_5_bombs_around_tile(void){ + + + + int result; + + Minesweeper_Board board = initialize_minesweeper(); + + int tile = 1 + board.width * 0; + + board.bombs[0] = 0 + board.width * 0; + + board.bombs[1] = 2 + board.width * 0; + + board.bombs[2] = 0 + board.width * 1; + + board.bombs[3] = 1 + board.width * 1; + + board.bombs[4] = 2 + board.width * 1; + + + + + + result = number_of_bombs(&board, tile); + + + + + + UnityAssertEqualNumber((UNITY_INT)((5)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(73), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_8_bombs_around_tile(void){ + + + + int result; + + Minesweeper_Board board = initialize_minesweeper(); + + int tile = 7 + board.width * 7; + + board.bombs[0] = 6 + board.width * 6; + + board.bombs[1] = 7 + board.width * 6; + + board.bombs[2] = 8 + board.width * 6; + + board.bombs[3] = 6 + board.width * 7; + + board.bombs[4] = 8 + board.width * 7; + + board.bombs[5] = 6 + board.width * 8; + + board.bombs[6] = 7 + board.width * 8; + + board.bombs[7] = 8 + board.width * 8; + + + + + + result = number_of_bombs(&board, tile); + + + + + + UnityAssertEqualNumber((UNITY_INT)((8)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(94), UNITY_DISPLAY_STYLE_INT); + +} diff --git a/build/test/cache/test_part_of_snake.c b/build/test/cache/test_part_of_snake.c new file mode 100644 index 0000000..b488cb0 --- /dev/null +++ b/build/test/cache/test_part_of_snake.c @@ -0,0 +1,102 @@ +#include "build/temp/../../src/main/c/Snake/get_character.h" +#include "build/temp/../../src/main/c/Snake/snake_start.h" +#include "/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h" + + + + + + +void setUp(void){} + +void tearDown(void){} + + + + + +void test_find_head(void){ + + + + int result; + + Snake snake = initialize_snake(); + + + + + + result = part_of_snake(&snake, 8 * 16 + 8); + + + + + + UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(20), UNITY_DISPLAY_STYLE_INT); + +} + + + + + +void test_get_correct_index(void){ + + + + int result; + + Snake snake = initialize_snake(); + + + + + + result = part_of_snake(&snake, 8 * 16 + 6); + + + + + + UnityAssertEqualNumber((UNITY_INT)((2)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(33), UNITY_DISPLAY_STYLE_INT); + +} + + + + + +void test_snake_not_on_tile(void){ + + + + int result; + + Snake snake = initialize_snake(); + + + + + + result = part_of_snake(&snake, 6 * 16 + 6); + + + + + + UnityAssertEqualNumber((UNITY_INT)((-1)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(46), UNITY_DISPLAY_STYLE_INT); + +} diff --git a/build/test/cache/test_playerInputMovement.c b/build/test/cache/test_playerInputMovement.c new file mode 100644 index 0000000..d38ca76 --- /dev/null +++ b/build/test/cache/test_playerInputMovement.c @@ -0,0 +1,83 @@ +#include "src/main/c/Pong/pong.h" +#include "/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h" + + + + +typedef struct { + + int x; + + int y; + + int speedX; + + int speedY; + +} Paddle; + + + + + +void setUp(void){ + + + +} + + + +void tearDown(void){ + +} + + + +void test_playerInputMovement(void){ + + + + int paddlePositionY = 10; + + int userInput = -1; + + int expectedY = paddlePositionY - 1; + + + + processPlayerInput(&paddlePositionY, userInput); + + UnityAssertEqualNumber((UNITY_INT)((expectedY)), (UNITY_INT)((paddlePositionY)), ( + + ((void *)0) + + ), (UNITY_UINT)(27), UNITY_DISPLAY_STYLE_INT); + + + + + + userInput = 1; + + expectedY = paddlePositionY + 1; + + + + + + processPlayerInput(&paddlePositionY, userInput); + + UnityAssertEqualNumber((UNITY_INT)((expectedY)), (UNITY_INT)((paddlePositionY)), ( + + ((void *)0) + + ), (UNITY_UINT)(35), UNITY_DISPLAY_STYLE_INT); + + + + + + + +} diff --git a/build/test/cache/test_pong.c b/build/test/cache/test_pong.c new file mode 100644 index 0000000..7e1dfbf --- /dev/null +++ b/build/test/cache/test_pong.c @@ -0,0 +1,51 @@ +#include "src/main/c/Pong/pong.h" +#include "/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h" + + + + + + +void setUp(void){ + + + +} + +void tearDown(void){ + +} + + + + + +void test_input_all_5(void){ + + + + int a = 4, b = 5; + + + + + + resetScore( &a, &b ); + + + + + + UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((a)), ( + + ((void *)0) + + ), (UNITY_UINT)(21), UNITY_DISPLAY_STYLE_INT); + + UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((b)), ( + + ((void *)0) + + ), (UNITY_UINT)(22), UNITY_DISPLAY_STYLE_INT); + +} diff --git a/build/test/cache/test_tictactoe.c b/build/test/cache/test_tictactoe.c new file mode 100644 index 0000000..e69de29 diff --git a/build/test/dependencies/get_character.d b/build/test/dependencies/get_character.d new file mode 100644 index 0000000..8f17ec7 --- /dev/null +++ b/build/test/dependencies/get_character.d @@ -0,0 +1 @@ +build/test/out/c/get_character.o: src/main/c/Snake/get_character.c diff --git a/build/test/dependencies/minesweeper_start.d b/build/test/dependencies/minesweeper_start.d new file mode 100644 index 0000000..fd6546c --- /dev/null +++ b/build/test/dependencies/minesweeper_start.d @@ -0,0 +1,3 @@ +build/test/out/c/minesweeper_start.o: \ + src/main/c/Minesweeper/minesweeper_start.c \ + src/main/c/Minesweeper/minesweeper_start.h diff --git a/build/test/dependencies/pong.d b/build/test/dependencies/pong.d new file mode 100644 index 0000000..9bafeb3 --- /dev/null +++ b/build/test/dependencies/pong.d @@ -0,0 +1 @@ +build/test/out/c/pong.o: src/main/c/Pong/pong.c diff --git a/build/test/dependencies/snake_start.d b/build/test/dependencies/snake_start.d new file mode 100644 index 0000000..6c435ce --- /dev/null +++ b/build/test/dependencies/snake_start.d @@ -0,0 +1,2 @@ +build/test/out/c/snake_start.o: src/main/c/Snake/snake_start.c \ + src/main/c/Snake/snake_start.h src/main/c/Snake/get_character.h diff --git a/build/test/dependencies/test_bomb_in_array.d b/build/test/dependencies/test_bomb_in_array.d new file mode 100644 index 0000000..994afc1 --- /dev/null +++ b/build/test/dependencies/test_bomb_in_array.d @@ -0,0 +1,5 @@ +build/test/out/c/test_bomb_in_array.o: \ + test/Minesweeper/test_bomb_in_array.c \ + /var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h \ + /var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity_internals.h \ + test/Minesweeper/../../src/main/c/Minesweeper/minesweeper_start.h diff --git a/build/test/dependencies/test_bomb_in_array_runner.d b/build/test/dependencies/test_bomb_in_array_runner.d new file mode 100644 index 0000000..53b6683 --- /dev/null +++ b/build/test/dependencies/test_bomb_in_array_runner.d @@ -0,0 +1,4 @@ +build/test/out/c/test_bomb_in_array_runner.o: \ + build/test/runners/test_bomb_in_array_runner.c \ + /var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h \ + /var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity_internals.h diff --git a/build/test/dependencies/test_checkCollision.d b/build/test/dependencies/test_checkCollision.d new file mode 100644 index 0000000..598f40e --- /dev/null +++ b/build/test/dependencies/test_checkCollision.d @@ -0,0 +1,4 @@ +build/test/out/c/test_checkCollision.o: test/Pong/test_checkCollision.c \ + /var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h \ + /var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity_internals.h \ + src/main/c/Pong/pong.h diff --git a/build/test/dependencies/test_checkCollision_runner.d b/build/test/dependencies/test_checkCollision_runner.d new file mode 100644 index 0000000..8caa0f9 --- /dev/null +++ b/build/test/dependencies/test_checkCollision_runner.d @@ -0,0 +1,4 @@ +build/test/out/c/test_checkCollision_runner.o: \ + build/test/runners/test_checkCollision_runner.c \ + /var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h \ + /var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity_internals.h diff --git a/build/test/dependencies/test_checkGameEnd.d b/build/test/dependencies/test_checkGameEnd.d new file mode 100644 index 0000000..0d4bf78 --- /dev/null +++ b/build/test/dependencies/test_checkGameEnd.d @@ -0,0 +1,4 @@ +build/test/out/c/test_checkGameEnd.o: test/Pong/test_checkGameEnd.c \ + /var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h \ + /var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity_internals.h \ + src/main/c/Pong/pong.h diff --git a/build/test/dependencies/test_checkGameEnd_runner.d b/build/test/dependencies/test_checkGameEnd_runner.d new file mode 100644 index 0000000..74bebf4 --- /dev/null +++ b/build/test/dependencies/test_checkGameEnd_runner.d @@ -0,0 +1,4 @@ +build/test/out/c/test_checkGameEnd_runner.o: \ + build/test/runners/test_checkGameEnd_runner.c \ + /var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h \ + /var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity_internals.h diff --git a/build/test/dependencies/test_clearScreen.d b/build/test/dependencies/test_clearScreen.d new file mode 100644 index 0000000..7f5431c --- /dev/null +++ b/build/test/dependencies/test_clearScreen.d @@ -0,0 +1,4 @@ +build/test/out/c/test_clearScreen.o: test/Pong/test_clearScreen.c \ + /var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h \ + /var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity_internals.h \ + src/main/c/Pong/pong.h diff --git a/build/test/dependencies/test_clearScreen_runner.d b/build/test/dependencies/test_clearScreen_runner.d new file mode 100644 index 0000000..0f74b3c --- /dev/null +++ b/build/test/dependencies/test_clearScreen_runner.d @@ -0,0 +1,4 @@ +build/test/out/c/test_clearScreen_runner.o: \ + build/test/runners/test_clearScreen_runner.c \ + /var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h \ + /var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity_internals.h diff --git a/build/test/dependencies/test_collision.d b/build/test/dependencies/test_collision.d new file mode 100644 index 0000000..ad5e8d5 --- /dev/null +++ b/build/test/dependencies/test_collision.d @@ -0,0 +1,4 @@ +build/test/out/c/test_collision.o: test/Snake/test_collision.c \ + /var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h \ + /var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity_internals.h \ + src/main/c/Snake/snake_start.h src/main/c/Snake/get_character.h diff --git a/build/test/dependencies/test_collision_runner.d b/build/test/dependencies/test_collision_runner.d new file mode 100644 index 0000000..279686d --- /dev/null +++ b/build/test/dependencies/test_collision_runner.d @@ -0,0 +1,4 @@ +build/test/out/c/test_collision_runner.o: \ + build/test/runners/test_collision_runner.c \ + /var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h \ + /var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity_internals.h diff --git a/build/test/dependencies/test_is_Valid_tile.d b/build/test/dependencies/test_is_Valid_tile.d new file mode 100644 index 0000000..3c1a8bf --- /dev/null +++ b/build/test/dependencies/test_is_Valid_tile.d @@ -0,0 +1,5 @@ +build/test/out/c/test_is_Valid_tile.o: \ + test/Minesweeper/test_is_Valid_tile.c \ + /var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h \ + /var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity_internals.h \ + test/Minesweeper/../../src/main/c/Minesweeper/minesweeper_start.h diff --git a/build/test/dependencies/test_is_Valid_tile_runner.d b/build/test/dependencies/test_is_Valid_tile_runner.d new file mode 100644 index 0000000..fbecf92 --- /dev/null +++ b/build/test/dependencies/test_is_Valid_tile_runner.d @@ -0,0 +1,4 @@ +build/test/out/c/test_is_Valid_tile_runner.o: \ + build/test/runners/test_is_Valid_tile_runner.c \ + /var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h \ + /var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity_internals.h diff --git a/build/test/dependencies/test_moving_snake.d b/build/test/dependencies/test_moving_snake.d new file mode 100644 index 0000000..0b892ff --- /dev/null +++ b/build/test/dependencies/test_moving_snake.d @@ -0,0 +1,5 @@ +build/test/out/c/test_moving_snake.o: test/Snake/test_moving_snake.c \ + /var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h \ + /var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity_internals.h \ + test/Snake/../../src/main/c/Snake/snake_start.h \ + test/Snake/../../src/main/c/Snake/get_character.h diff --git a/build/test/dependencies/test_moving_snake_runner.d b/build/test/dependencies/test_moving_snake_runner.d new file mode 100644 index 0000000..ce8f9f0 --- /dev/null +++ b/build/test/dependencies/test_moving_snake_runner.d @@ -0,0 +1,4 @@ +build/test/out/c/test_moving_snake_runner.o: \ + build/test/runners/test_moving_snake_runner.c \ + /var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h \ + /var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity_internals.h diff --git a/build/test/dependencies/test_number_of_bombs.d b/build/test/dependencies/test_number_of_bombs.d new file mode 100644 index 0000000..f46f914 --- /dev/null +++ b/build/test/dependencies/test_number_of_bombs.d @@ -0,0 +1,5 @@ +build/test/out/c/test_number_of_bombs.o: \ + test/Minesweeper/test_number_of_bombs.c \ + /var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h \ + /var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity_internals.h \ + test/Minesweeper/../../src/main/c/Minesweeper/minesweeper_start.h diff --git a/build/test/dependencies/test_number_of_bombs_runner.d b/build/test/dependencies/test_number_of_bombs_runner.d new file mode 100644 index 0000000..d910d9b --- /dev/null +++ b/build/test/dependencies/test_number_of_bombs_runner.d @@ -0,0 +1,4 @@ +build/test/out/c/test_number_of_bombs_runner.o: \ + build/test/runners/test_number_of_bombs_runner.c \ + /var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h \ + /var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity_internals.h diff --git a/build/test/dependencies/test_part_of_snake.d b/build/test/dependencies/test_part_of_snake.d new file mode 100644 index 0000000..6dec8fd --- /dev/null +++ b/build/test/dependencies/test_part_of_snake.d @@ -0,0 +1,5 @@ +build/test/out/c/test_part_of_snake.o: test/Snake/test_part_of_snake.c \ + /var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h \ + /var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity_internals.h \ + test/Snake/../../src/main/c/Snake/snake_start.h \ + test/Snake/../../src/main/c/Snake/get_character.h diff --git a/build/test/dependencies/test_part_of_snake_runner.d b/build/test/dependencies/test_part_of_snake_runner.d new file mode 100644 index 0000000..3f37e86 --- /dev/null +++ b/build/test/dependencies/test_part_of_snake_runner.d @@ -0,0 +1,4 @@ +build/test/out/c/test_part_of_snake_runner.o: \ + build/test/runners/test_part_of_snake_runner.c \ + /var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h \ + /var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity_internals.h diff --git a/build/test/dependencies/test_playerInputMovement.d b/build/test/dependencies/test_playerInputMovement.d new file mode 100644 index 0000000..a22d018 --- /dev/null +++ b/build/test/dependencies/test_playerInputMovement.d @@ -0,0 +1,5 @@ +build/test/out/c/test_playerInputMovement.o: \ + test/Pong/test_playerInputMovement.c \ + /var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h \ + /var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity_internals.h \ + src/main/c/Pong/pong.h diff --git a/build/test/dependencies/test_playerInputMovement_runner.d b/build/test/dependencies/test_playerInputMovement_runner.d new file mode 100644 index 0000000..c2f9cb9 --- /dev/null +++ b/build/test/dependencies/test_playerInputMovement_runner.d @@ -0,0 +1,4 @@ +build/test/out/c/test_playerInputMovement_runner.o: \ + build/test/runners/test_playerInputMovement_runner.c \ + /var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h \ + /var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity_internals.h diff --git a/build/test/dependencies/test_pong.d b/build/test/dependencies/test_pong.d new file mode 100644 index 0000000..de38849 --- /dev/null +++ b/build/test/dependencies/test_pong.d @@ -0,0 +1,4 @@ +build/test/out/c/test_pong.o: test/Pong/test_pong.c \ + /var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h \ + /var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity_internals.h \ + src/main/c/Pong/pong.h diff --git a/build/test/dependencies/test_pong_runner.d b/build/test/dependencies/test_pong_runner.d new file mode 100644 index 0000000..ae30bd9 --- /dev/null +++ b/build/test/dependencies/test_pong_runner.d @@ -0,0 +1,4 @@ +build/test/out/c/test_pong_runner.o: \ + build/test/runners/test_pong_runner.c \ + /var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h \ + /var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity_internals.h diff --git a/build/test/dependencies/test_tictactoe.d b/build/test/dependencies/test_tictactoe.d new file mode 100644 index 0000000..f4ff40e --- /dev/null +++ b/build/test/dependencies/test_tictactoe.d @@ -0,0 +1 @@ +build/test/out/c/test_tictactoe.o: test/test_tictactoe.c diff --git a/build/test/dependencies/test_tictactoe_runner.d b/build/test/dependencies/test_tictactoe_runner.d new file mode 100644 index 0000000..fa84889 --- /dev/null +++ b/build/test/dependencies/test_tictactoe_runner.d @@ -0,0 +1,4 @@ +build/test/out/c/test_tictactoe_runner.o: \ + build/test/runners/test_tictactoe_runner.c \ + /var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h \ + /var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity_internals.h diff --git a/build/test/out/c/get_character.o b/build/test/out/c/get_character.o new file mode 100644 index 0000000..1b8ddf9 Binary files /dev/null and b/build/test/out/c/get_character.o differ diff --git a/build/test/out/c/minesweeper_start.o b/build/test/out/c/minesweeper_start.o new file mode 100644 index 0000000..10c6f27 Binary files /dev/null and b/build/test/out/c/minesweeper_start.o differ diff --git a/build/test/out/c/pong.o b/build/test/out/c/pong.o new file mode 100644 index 0000000..7ed8663 Binary files /dev/null and b/build/test/out/c/pong.o differ diff --git a/build/test/out/c/snake_start.o b/build/test/out/c/snake_start.o new file mode 100644 index 0000000..cba1813 Binary files /dev/null and b/build/test/out/c/snake_start.o differ diff --git a/build/test/out/c/test_bomb_in_array.o b/build/test/out/c/test_bomb_in_array.o new file mode 100644 index 0000000..651d6c6 Binary files /dev/null and b/build/test/out/c/test_bomb_in_array.o differ diff --git a/build/test/out/c/test_bomb_in_array_runner.o b/build/test/out/c/test_bomb_in_array_runner.o new file mode 100644 index 0000000..1d1a534 Binary files /dev/null and b/build/test/out/c/test_bomb_in_array_runner.o differ diff --git a/build/test/out/c/test_checkCollision.o b/build/test/out/c/test_checkCollision.o new file mode 100644 index 0000000..dd26e7b Binary files /dev/null and b/build/test/out/c/test_checkCollision.o differ diff --git a/build/test/out/c/test_checkCollision_runner.o b/build/test/out/c/test_checkCollision_runner.o new file mode 100644 index 0000000..747c52e Binary files /dev/null and b/build/test/out/c/test_checkCollision_runner.o differ diff --git a/build/test/out/c/test_checkGameEnd.o b/build/test/out/c/test_checkGameEnd.o new file mode 100644 index 0000000..1a23238 Binary files /dev/null and b/build/test/out/c/test_checkGameEnd.o differ diff --git a/build/test/out/c/test_checkGameEnd_runner.o b/build/test/out/c/test_checkGameEnd_runner.o new file mode 100644 index 0000000..caad412 Binary files /dev/null and b/build/test/out/c/test_checkGameEnd_runner.o differ diff --git a/build/test/out/c/test_clearScreen.o b/build/test/out/c/test_clearScreen.o new file mode 100644 index 0000000..53e83a8 Binary files /dev/null and b/build/test/out/c/test_clearScreen.o differ diff --git a/build/test/out/c/test_clearScreen_runner.o b/build/test/out/c/test_clearScreen_runner.o new file mode 100644 index 0000000..a4e758e Binary files /dev/null and b/build/test/out/c/test_clearScreen_runner.o differ diff --git a/build/test/out/c/test_collision.o b/build/test/out/c/test_collision.o new file mode 100644 index 0000000..542f42a Binary files /dev/null and b/build/test/out/c/test_collision.o differ diff --git a/build/test/out/c/test_collision_runner.o b/build/test/out/c/test_collision_runner.o new file mode 100644 index 0000000..56e133c Binary files /dev/null and b/build/test/out/c/test_collision_runner.o differ diff --git a/build/test/out/c/test_is_Valid_tile.o b/build/test/out/c/test_is_Valid_tile.o new file mode 100644 index 0000000..ac4d5d3 Binary files /dev/null and b/build/test/out/c/test_is_Valid_tile.o differ diff --git a/build/test/out/c/test_is_Valid_tile_runner.o b/build/test/out/c/test_is_Valid_tile_runner.o new file mode 100644 index 0000000..84ab5b4 Binary files /dev/null and b/build/test/out/c/test_is_Valid_tile_runner.o differ diff --git a/build/test/out/c/test_moving_snake.o b/build/test/out/c/test_moving_snake.o new file mode 100644 index 0000000..829d7f1 Binary files /dev/null and b/build/test/out/c/test_moving_snake.o differ diff --git a/build/test/out/c/test_moving_snake_runner.o b/build/test/out/c/test_moving_snake_runner.o new file mode 100644 index 0000000..06ec999 Binary files /dev/null and b/build/test/out/c/test_moving_snake_runner.o differ diff --git a/build/test/out/c/test_number_of_bombs.o b/build/test/out/c/test_number_of_bombs.o new file mode 100644 index 0000000..1d66c5f Binary files /dev/null and b/build/test/out/c/test_number_of_bombs.o differ diff --git a/build/test/out/c/test_number_of_bombs_runner.o b/build/test/out/c/test_number_of_bombs_runner.o new file mode 100644 index 0000000..d3a3c43 Binary files /dev/null and b/build/test/out/c/test_number_of_bombs_runner.o differ diff --git a/build/test/out/c/test_part_of_snake.o b/build/test/out/c/test_part_of_snake.o new file mode 100644 index 0000000..934775c Binary files /dev/null and b/build/test/out/c/test_part_of_snake.o differ diff --git a/build/test/out/c/test_part_of_snake_runner.o b/build/test/out/c/test_part_of_snake_runner.o new file mode 100644 index 0000000..021fd43 Binary files /dev/null and b/build/test/out/c/test_part_of_snake_runner.o differ diff --git a/build/test/out/c/test_playerInputMovement.o b/build/test/out/c/test_playerInputMovement.o new file mode 100644 index 0000000..0c89b5e Binary files /dev/null and b/build/test/out/c/test_playerInputMovement.o differ diff --git a/build/test/out/c/test_playerInputMovement_runner.o b/build/test/out/c/test_playerInputMovement_runner.o new file mode 100644 index 0000000..870cc10 Binary files /dev/null and b/build/test/out/c/test_playerInputMovement_runner.o differ diff --git a/build/test/out/c/test_pong.o b/build/test/out/c/test_pong.o new file mode 100644 index 0000000..a6be32c Binary files /dev/null and b/build/test/out/c/test_pong.o differ diff --git a/build/test/out/c/test_pong_runner.o b/build/test/out/c/test_pong_runner.o new file mode 100644 index 0000000..77ffebf Binary files /dev/null and b/build/test/out/c/test_pong_runner.o differ diff --git a/build/test/out/c/test_tictactoe.o b/build/test/out/c/test_tictactoe.o new file mode 100644 index 0000000..a704cef Binary files /dev/null and b/build/test/out/c/test_tictactoe.o differ diff --git a/build/test/out/c/test_tictactoe_runner.o b/build/test/out/c/test_tictactoe_runner.o new file mode 100644 index 0000000..eff4dfd Binary files /dev/null and b/build/test/out/c/test_tictactoe_runner.o differ diff --git a/build/test/out/test_bomb_in_array.out b/build/test/out/test_bomb_in_array.out new file mode 100755 index 0000000..a2618c0 Binary files /dev/null and b/build/test/out/test_bomb_in_array.out differ diff --git a/build/test/out/test_checkCollision.out b/build/test/out/test_checkCollision.out new file mode 100755 index 0000000..4a9b6f9 Binary files /dev/null and b/build/test/out/test_checkCollision.out differ diff --git a/build/test/out/test_checkGameEnd.out b/build/test/out/test_checkGameEnd.out new file mode 100755 index 0000000..476ee5f Binary files /dev/null and b/build/test/out/test_checkGameEnd.out differ diff --git a/build/test/out/test_clearScreen.out b/build/test/out/test_clearScreen.out new file mode 100755 index 0000000..2429c48 Binary files /dev/null and b/build/test/out/test_clearScreen.out differ diff --git a/build/test/out/test_collision.out b/build/test/out/test_collision.out new file mode 100755 index 0000000..022a79c Binary files /dev/null and b/build/test/out/test_collision.out differ diff --git a/build/test/out/test_is_Valid_tile.out b/build/test/out/test_is_Valid_tile.out new file mode 100755 index 0000000..4105934 Binary files /dev/null and b/build/test/out/test_is_Valid_tile.out differ diff --git a/build/test/out/test_moving_snake.out b/build/test/out/test_moving_snake.out new file mode 100755 index 0000000..e3f2dcf Binary files /dev/null and b/build/test/out/test_moving_snake.out differ diff --git a/build/test/out/test_number_of_bombs.out b/build/test/out/test_number_of_bombs.out new file mode 100755 index 0000000..7ae6181 Binary files /dev/null and b/build/test/out/test_number_of_bombs.out differ diff --git a/build/test/out/test_part_of_snake.out b/build/test/out/test_part_of_snake.out new file mode 100755 index 0000000..87a8574 Binary files /dev/null and b/build/test/out/test_part_of_snake.out differ diff --git a/build/test/out/test_playerInputMovement.out b/build/test/out/test_playerInputMovement.out new file mode 100755 index 0000000..3b9604e Binary files /dev/null and b/build/test/out/test_playerInputMovement.out differ diff --git a/build/test/out/test_pong.out b/build/test/out/test_pong.out new file mode 100755 index 0000000..a2c366e Binary files /dev/null and b/build/test/out/test_pong.out differ diff --git a/build/test/out/test_tictactoe.out b/build/test/out/test_tictactoe.out new file mode 100755 index 0000000..3718d07 Binary files /dev/null and b/build/test/out/test_tictactoe.out differ diff --git a/build/test/preprocess/files/test_bomb_in_array.c b/build/test/preprocess/files/test_bomb_in_array.c new file mode 100644 index 0000000..14de752 --- /dev/null +++ b/build/test/preprocess/files/test_bomb_in_array.c @@ -0,0 +1,79 @@ +#include "build/temp/../../src/main/c/Minesweeper/minesweeper_start.h" +#include "/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h" + + + + + + +void setUp(void){} + +void tearDown(void){} + + + + + +void test_bomb_in_array(void){ + + + + + + _Bool + + result; + + int array[] = {5, 9, 42, 6, 87, 95, 202, 13, 45 ,78}; + + int bomb = 42; + + int length = 10; + + + + + + result = array_contains_value(array, bomb, length); + + + + + + do {if ((result)) {} else {UnityFail( ((" Expected TRUE Was FALSE")), (UNITY_UINT)((UNITY_UINT)(22)));}} while(0); + +} + + + + + +void test_bomb_not_in_array(void){ + + + + + + _Bool + + result; + + int array[] = {5, 9, 42, 6, 87, 95, 202, 13, 45 ,78}; + + int bomb = 0; + + int length = 10; + + + + + + result = array_contains_value(array, bomb, length); + + + + + + do {if (!(result)) {} else {UnityFail( ((" Expected FALSE Was TRUE")), (UNITY_UINT)((UNITY_UINT)(37)));}} while(0); + +} diff --git a/build/test/preprocess/files/test_checkCollision.c b/build/test/preprocess/files/test_checkCollision.c new file mode 100644 index 0000000..79e7083 --- /dev/null +++ b/build/test/preprocess/files/test_checkCollision.c @@ -0,0 +1,143 @@ +#include "src/main/c/Pong/pong.h" +#include "/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h" + + + + + + + + +typedef struct { + + int x; + + int y; + + int speedX; + + int speedY; + +} Ball; + + + +typedef struct { + + int x; + + int y; + + int width; + + int height; + +} Paddle; + + + +void setUp(void){ + + + +} + + + +void tearDown(void){ + +} + + + +void test_checkCollision(void){ + + Ball ball = {10, 10, 1, 1}; + + Paddle paddle = {50, 10, 5, 10}; + + + + + + ball.x = 0; + + int result1 = checkCollision(ball, paddle.y, paddle.y); + + UnityAssertEqualNumber((UNITY_INT)((1)), (UNITY_INT)((result1)), ( + + ((void *)0) + + ), (UNITY_UINT)(35), UNITY_DISPLAY_STYLE_INT); + + + + ball.x = 40 - 1; + + int result2 = checkCollision(ball, paddle.y, paddle.y); + + UnityAssertEqualNumber((UNITY_INT)((2)), (UNITY_INT)((result2)), ( + + ((void *)0) + + ), (UNITY_UINT)(39), UNITY_DISPLAY_STYLE_INT); + + + + + + ball.x = 5; + + ball.y = 0; + + int result3 = checkCollision(ball, paddle.y, paddle.y); + + UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((result3)), ( + + ((void *)0) + + ), (UNITY_UINT)(45), UNITY_DISPLAY_STYLE_INT); + + + + ball.y = 20 - 1; + + int result4 = checkCollision(ball, paddle.y, paddle.y); + + UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((result4)), ( + + ((void *)0) + + ), (UNITY_UINT)(49), UNITY_DISPLAY_STYLE_INT); + + + + + + ball.x = paddle.x - 1; + + ball.y = paddle.y + 1; + + int result5 = checkCollision(ball, paddle.y, paddle.y); + + UnityAssertEqualNumber((UNITY_INT)((2)), (UNITY_INT)((result5)), ( + + ((void *)0) + + ), (UNITY_UINT)(55), UNITY_DISPLAY_STYLE_INT); + + + + ball.x = paddle.x + 1; + + ball.y = paddle.y + 1; + + int result6 = checkCollision(ball, paddle.y, paddle.y); + + UnityAssertEqualNumber((UNITY_INT)((2)), (UNITY_INT)((result6)), ( + + ((void *)0) + + ), (UNITY_UINT)(60), UNITY_DISPLAY_STYLE_INT); + +} diff --git a/build/test/preprocess/files/test_checkGameEnd.c b/build/test/preprocess/files/test_checkGameEnd.c new file mode 100644 index 0000000..3c0d662 --- /dev/null +++ b/build/test/preprocess/files/test_checkGameEnd.c @@ -0,0 +1,69 @@ +#include "src/main/c/Pong/pong.h" +#include "/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h" + + + + + + + + +void setUp(void){ + + + +} + + + +void tearDown(void){ + +} + + + +void test_checkGameEnd(void){ + + + + int maxScore = 5; + + int score1 = 4, score2 = 2; + + + + + + int result = checkGameEnd(score1, score2, maxScore); + + + + + + UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(23), UNITY_DISPLAY_STYLE_INT); + + + + + + score1 = 5; + + result = checkGameEnd(score1, score2, maxScore); + + UnityAssertEqualNumber((UNITY_INT)((1)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(28), UNITY_DISPLAY_STYLE_INT); + + + + + + + +} diff --git a/build/test/preprocess/files/test_clearScreen.c b/build/test/preprocess/files/test_clearScreen.c new file mode 100644 index 0000000..74ec6bf --- /dev/null +++ b/build/test/preprocess/files/test_clearScreen.c @@ -0,0 +1,73 @@ +#include "src/main/c/Pong/pong.h" +#include "/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h" + + + + + + + + + + +char screen[20][40 +1]; + + + +void setUp(void){ + + + +} + + + +void tearDown(void){ + +} + + + +void test_clearScreen(void){ + + + + int i, j; + + for (i = 0; i < 20; i++) { + + for (j = 0; j < 40; j++) { + + screen[i][j] = ' '; + + } + + screen[i][j] = '\0'; + + } + + + + + + clearScreen(); + + + + + + for (i = 0; i < 20; i++) { + + for (j = 0; j < 40; j++) { + + UnityAssertEqualNumber((UNITY_INT)((' ')), (UNITY_INT)((screen[i][j])), ( + + ((void *)0) + + ), (UNITY_UINT)(33), UNITY_DISPLAY_STYLE_INT); + + } + + } + +} diff --git a/build/test/preprocess/files/test_collision.c b/build/test/preprocess/files/test_collision.c new file mode 100644 index 0000000..a159403 --- /dev/null +++ b/build/test/preprocess/files/test_collision.c @@ -0,0 +1,102 @@ +#include "src/main/c/Snake/get_character.h" +#include "src/main/c/Snake/snake_start.h" +#include "/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h" + + + + + + +void setUp(void){} + +void tearDown(void){} + + + + + +void test_self_collision(void){ + + + + + + _Bool + + result; + + Snake snake = {1, 5, {6 + 16 * 6, 6 + 16 * 7, 7 + 16 * 7, 7 + 16 * 6, 6 + 16 * 6}}; + + + + + + result = check_if_dead(&snake); + + + + + + do {if ((result)) {} else {UnityFail( ((" Expected TRUE Was FALSE")), (UNITY_UINT)((UNITY_UINT)(21)));}} while(0); + +} + + + + + +void test_no_collision(void){ + + + + + + _Bool + + result; + + Snake snake = initialize_snake(); + + + + + + result = check_if_dead(&snake); + + + + + + do {if (!(result)) {} else {UnityFail( ((" Expected FALSE Was TRUE")), (UNITY_UINT)((UNITY_UINT)(34)));}} while(0); + +} + + + + + +void test_wall_collision(void){ + + + + + + _Bool + + result; + + Snake snake = {-1, 4, {0 + 16 * 6, 1 + 16 * 6, 2 + 16 * 6, 3 + 16 * 6}}; + + + + + + result = check_if_dead(&snake); + + + + + + do {if ((result)) {} else {UnityFail( ((" Expected TRUE Was FALSE")), (UNITY_UINT)((UNITY_UINT)(47)));}} while(0); + +} diff --git a/build/test/preprocess/files/test_is_Valid_tile.c b/build/test/preprocess/files/test_is_Valid_tile.c new file mode 100644 index 0000000..5911aa4 --- /dev/null +++ b/build/test/preprocess/files/test_is_Valid_tile.c @@ -0,0 +1,269 @@ +#include "build/temp/../../src/main/c/Minesweeper/minesweeper_start.h" +#include "/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h" + + + + + + +void setUp(void){} + +void tearDown(void){} + + + + + +void test_detect_not_valid_tile_left(void){ + + + + Minesweeper_Board board = initialize_minesweeper(); + + int tile = 0; + + int direction = 2; + + int result; + + + + + + result = is_Valid_tile(&board, tile, direction); + + + + + + UnityAssertEqualNumber((UNITY_INT)((-1)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(21), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_detect_not_valid_tile_up(void){ + + + + Minesweeper_Board board = initialize_minesweeper(); + + int tile = 0; + + int direction = 3; + + int result; + + + + + + result = is_Valid_tile(&board, tile, direction); + + + + + + UnityAssertEqualNumber((UNITY_INT)((-1)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(35), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_detect_not_valid_tile_right(void){ + + + + Minesweeper_Board board = initialize_minesweeper(); + + int tile = board.width * board.height - 1; + + int direction = 5; + + int result; + + + + + + result = is_Valid_tile(&board, tile, direction); + + + + + + UnityAssertEqualNumber((UNITY_INT)((-1)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(49), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_detect_not_valid_tile_down(void){ + + + + Minesweeper_Board board = initialize_minesweeper(); + + int tile = board.width * board.height - 1; + + int direction = 4; + + int result; + + + + + + result = is_Valid_tile(&board, tile, direction); + + + + + + UnityAssertEqualNumber((UNITY_INT)((-1)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(63), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_detect_valid_tile_left(void){ + + + + Minesweeper_Board board = initialize_minesweeper(); + + int tile = board.width * board.height - 1; + + int direction = 2; + + int result; + + + + + + result = is_Valid_tile(&board, tile, direction); + + + + + + UnityAssertEqualNumber((UNITY_INT)((board.width * board.height - 2)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(77), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_detect_valid_tile_up(void){ + + + + Minesweeper_Board board = initialize_minesweeper(); + + int tile = board.width * board.height - 1; + + int direction = 3; + + int result; + + + + + + result = is_Valid_tile(&board, tile, direction); + + + + + + UnityAssertEqualNumber((UNITY_INT)((board.width * (board.height - 1) - 1)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(91), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_detect_valid_tile_right(void){ + + + + Minesweeper_Board board = initialize_minesweeper(); + + int tile = 0; + + int direction = 5; + + int result; + + + + + + result = is_Valid_tile(&board, tile, direction); + + + + + + UnityAssertEqualNumber((UNITY_INT)((1)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(105), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_detect_valid_tile_down(void){ + + + + Minesweeper_Board board = initialize_minesweeper(); + + int tile = 0; + + int direction = 4; + + int result; + + + + + + result = is_Valid_tile(&board, tile, direction); + + + + + + UnityAssertEqualNumber((UNITY_INT)((0 + board.width)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(119), UNITY_DISPLAY_STYLE_INT); + +} diff --git a/build/test/preprocess/files/test_moving_snake.c b/build/test/preprocess/files/test_moving_snake.c new file mode 100644 index 0000000..b305c52 --- /dev/null +++ b/build/test/preprocess/files/test_moving_snake.c @@ -0,0 +1,142 @@ +#include "build/temp/../../src/main/c/Snake/get_character.h" +#include "build/temp/../../src/main/c/Snake/snake_start.h" +#include "/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h" + + + + + + +void setUp(void){} + +void tearDown(void){} + + + + + +void test_moving_right(void){ + + + + + + _Bool + + result; + + Snake snake = {1, 3, {8 + 16 * 6, 7 + 16 * 6, 6 + 16 * 6}}; + + Snake expected = {1, 3, {9 + 16 * 6, 8 + 16 * 6, 7 + 16 * 6}}; + + + + + + move_snake(&snake); + + result = memcmp(&snake, &expected, sizeof(Snake)) == 0; + + + + + + do {if ((result)) {} else {UnityFail( ((" Expected TRUE Was FALSE")), (UNITY_UINT)((UNITY_UINT)(24)));}} while(0); + +} + + + +void test_moving_down(void){ + + + + + + _Bool + + result; + + Snake snake = {16, 3, {8 + 16 * 6, 7 + 16 * 6, 6 + 16 * 6}}; + + Snake expected = {16, 3, {8 + 16 * 7, 8 + 16 * 6, 7 + 16 * 6}}; + + + + + + move_snake(&snake); + + result = memcmp(&snake, &expected, sizeof(Snake)) == 0; + + + + + + do {if ((result)) {} else {UnityFail( ((" Expected TRUE Was FALSE")), (UNITY_UINT)((UNITY_UINT)(38)));}} while(0); + +} + + + +void test_moving_left(void){ + + + + + + _Bool + + result; + + Snake snake = {-1, 3, {8 + 16 * 6, 7 + 16 * 6, 6 + 16 * 6}}; + + Snake expected = {-1, 3, {7 + 16 * 6, 8 + 16 * 6, 7 + 16 * 6}}; + + + + + + move_snake(&snake); + + result = memcmp(&snake, &expected, sizeof(Snake)) == 0; + + + + + + do {if ((result)) {} else {UnityFail( ((" Expected TRUE Was FALSE")), (UNITY_UINT)((UNITY_UINT)(52)));}} while(0); + +} + + + +void test_moving_up(void){ + + + + + + _Bool + + result; + + Snake snake = {-16, 3, {8 + 16 * 6, 7 + 16 * 6, 6 + 16 * 6}}; + + Snake expected = {-16, 3, {8 + 16 * 5, 8 + 16 * 6, 7 + 16 * 6}}; + + + + + + move_snake(&snake); + + result = memcmp(&snake, &expected, sizeof(Snake)) == 0; + + + + + + do {if ((result)) {} else {UnityFail( ((" Expected TRUE Was FALSE")), (UNITY_UINT)((UNITY_UINT)(66)));}} while(0); + +} diff --git a/build/test/preprocess/files/test_number_of_bombs.c b/build/test/preprocess/files/test_number_of_bombs.c new file mode 100644 index 0000000..9b1981f --- /dev/null +++ b/build/test/preprocess/files/test_number_of_bombs.c @@ -0,0 +1,205 @@ +#include "build/temp/../../src/main/c/Minesweeper/minesweeper_start.h" +#include "/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h" + + + + + + +void setUp(void){} + +void tearDown(void){} + + + + + +void test_no_bombs_placed_around_tile(void){ + + + + int result; + + Minesweeper_Board board = initialize_minesweeper(); + + int tile = 0 + board.width * 1; + + + + + + result = number_of_bombs(&board, tile); + + + + + + UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(21), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_searching_for_bombs_on_correct_tiles(void){ + + + + int result; + + Minesweeper_Board board = initialize_minesweeper(); + + int tile = 0 + board.width * 1; + + board.bombs[0] = 0 + board.width * 3; + + board.bombs[1] = 2 + board.width * 1; + + board.bombs[2] = board.width - 1 + board.width * 1; + + board.bombs[3] = 0 + board.width * (board.height - 1); + + + + + + result = number_of_bombs(&board, tile); + + + + + + UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(38), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_2_bombs_around_tile(void){ + + + + int result; + + Minesweeper_Board board = initialize_minesweeper(); + + int tile = 0 + board.width * 1; + + board.bombs[0] = 0 + board.width * 2; + + board.bombs[1] = 1 + board.width * 1; + + board.bombs[2] = board.width - 1 + board.width * 1; + + board.bombs[3] = 0 + board.width * (board.height - 1); + + + + + + result = number_of_bombs(&board, tile); + + + + + + UnityAssertEqualNumber((UNITY_INT)((2)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(55), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_5_bombs_around_tile(void){ + + + + int result; + + Minesweeper_Board board = initialize_minesweeper(); + + int tile = 1 + board.width * 0; + + board.bombs[0] = 0 + board.width * 0; + + board.bombs[1] = 2 + board.width * 0; + + board.bombs[2] = 0 + board.width * 1; + + board.bombs[3] = 1 + board.width * 1; + + board.bombs[4] = 2 + board.width * 1; + + + + + + result = number_of_bombs(&board, tile); + + + + + + UnityAssertEqualNumber((UNITY_INT)((5)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(73), UNITY_DISPLAY_STYLE_INT); + +} + + + +void test_8_bombs_around_tile(void){ + + + + int result; + + Minesweeper_Board board = initialize_minesweeper(); + + int tile = 7 + board.width * 7; + + board.bombs[0] = 6 + board.width * 6; + + board.bombs[1] = 7 + board.width * 6; + + board.bombs[2] = 8 + board.width * 6; + + board.bombs[3] = 6 + board.width * 7; + + board.bombs[4] = 8 + board.width * 7; + + board.bombs[5] = 6 + board.width * 8; + + board.bombs[6] = 7 + board.width * 8; + + board.bombs[7] = 8 + board.width * 8; + + + + + + result = number_of_bombs(&board, tile); + + + + + + UnityAssertEqualNumber((UNITY_INT)((8)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(94), UNITY_DISPLAY_STYLE_INT); + +} diff --git a/build/test/preprocess/files/test_part_of_snake.c b/build/test/preprocess/files/test_part_of_snake.c new file mode 100644 index 0000000..b488cb0 --- /dev/null +++ b/build/test/preprocess/files/test_part_of_snake.c @@ -0,0 +1,102 @@ +#include "build/temp/../../src/main/c/Snake/get_character.h" +#include "build/temp/../../src/main/c/Snake/snake_start.h" +#include "/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h" + + + + + + +void setUp(void){} + +void tearDown(void){} + + + + + +void test_find_head(void){ + + + + int result; + + Snake snake = initialize_snake(); + + + + + + result = part_of_snake(&snake, 8 * 16 + 8); + + + + + + UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(20), UNITY_DISPLAY_STYLE_INT); + +} + + + + + +void test_get_correct_index(void){ + + + + int result; + + Snake snake = initialize_snake(); + + + + + + result = part_of_snake(&snake, 8 * 16 + 6); + + + + + + UnityAssertEqualNumber((UNITY_INT)((2)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(33), UNITY_DISPLAY_STYLE_INT); + +} + + + + + +void test_snake_not_on_tile(void){ + + + + int result; + + Snake snake = initialize_snake(); + + + + + + result = part_of_snake(&snake, 6 * 16 + 6); + + + + + + UnityAssertEqualNumber((UNITY_INT)((-1)), (UNITY_INT)((result)), ( + + ((void *)0) + + ), (UNITY_UINT)(46), UNITY_DISPLAY_STYLE_INT); + +} diff --git a/build/test/preprocess/files/test_playerInputMovement.c b/build/test/preprocess/files/test_playerInputMovement.c new file mode 100644 index 0000000..d38ca76 --- /dev/null +++ b/build/test/preprocess/files/test_playerInputMovement.c @@ -0,0 +1,83 @@ +#include "src/main/c/Pong/pong.h" +#include "/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h" + + + + +typedef struct { + + int x; + + int y; + + int speedX; + + int speedY; + +} Paddle; + + + + + +void setUp(void){ + + + +} + + + +void tearDown(void){ + +} + + + +void test_playerInputMovement(void){ + + + + int paddlePositionY = 10; + + int userInput = -1; + + int expectedY = paddlePositionY - 1; + + + + processPlayerInput(&paddlePositionY, userInput); + + UnityAssertEqualNumber((UNITY_INT)((expectedY)), (UNITY_INT)((paddlePositionY)), ( + + ((void *)0) + + ), (UNITY_UINT)(27), UNITY_DISPLAY_STYLE_INT); + + + + + + userInput = 1; + + expectedY = paddlePositionY + 1; + + + + + + processPlayerInput(&paddlePositionY, userInput); + + UnityAssertEqualNumber((UNITY_INT)((expectedY)), (UNITY_INT)((paddlePositionY)), ( + + ((void *)0) + + ), (UNITY_UINT)(35), UNITY_DISPLAY_STYLE_INT); + + + + + + + +} diff --git a/build/test/preprocess/files/test_pong.c b/build/test/preprocess/files/test_pong.c new file mode 100644 index 0000000..7e1dfbf --- /dev/null +++ b/build/test/preprocess/files/test_pong.c @@ -0,0 +1,51 @@ +#include "src/main/c/Pong/pong.h" +#include "/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h" + + + + + + +void setUp(void){ + + + +} + +void tearDown(void){ + +} + + + + + +void test_input_all_5(void){ + + + + int a = 4, b = 5; + + + + + + resetScore( &a, &b ); + + + + + + UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((a)), ( + + ((void *)0) + + ), (UNITY_UINT)(21), UNITY_DISPLAY_STYLE_INT); + + UnityAssertEqualNumber((UNITY_INT)((0)), (UNITY_INT)((b)), ( + + ((void *)0) + + ), (UNITY_UINT)(22), UNITY_DISPLAY_STYLE_INT); + +} diff --git a/build/test/preprocess/files/test_tictactoe.c b/build/test/preprocess/files/test_tictactoe.c new file mode 100644 index 0000000..e69de29 diff --git a/build/test/preprocess/includes/test_bomb_in_array.c b/build/test/preprocess/includes/test_bomb_in_array.c new file mode 100644 index 0000000..5630e0a --- /dev/null +++ b/build/test/preprocess/includes/test_bomb_in_array.c @@ -0,0 +1,3 @@ +--- +- "/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h" +- build/temp/../../src/main/c/Minesweeper/minesweeper_start.h diff --git a/build/test/preprocess/includes/test_checkCollision.c b/build/test/preprocess/includes/test_checkCollision.c new file mode 100644 index 0000000..2b3a590 --- /dev/null +++ b/build/test/preprocess/includes/test_checkCollision.c @@ -0,0 +1,3 @@ +--- +- "/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h" +- src/main/c/Pong/pong.h diff --git a/build/test/preprocess/includes/test_checkGameEnd.c b/build/test/preprocess/includes/test_checkGameEnd.c new file mode 100644 index 0000000..2b3a590 --- /dev/null +++ b/build/test/preprocess/includes/test_checkGameEnd.c @@ -0,0 +1,3 @@ +--- +- "/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h" +- src/main/c/Pong/pong.h diff --git a/build/test/preprocess/includes/test_clearScreen.c b/build/test/preprocess/includes/test_clearScreen.c new file mode 100644 index 0000000..2b3a590 --- /dev/null +++ b/build/test/preprocess/includes/test_clearScreen.c @@ -0,0 +1,3 @@ +--- +- "/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h" +- src/main/c/Pong/pong.h diff --git a/build/test/preprocess/includes/test_collision.c b/build/test/preprocess/includes/test_collision.c new file mode 100644 index 0000000..a508f7d --- /dev/null +++ b/build/test/preprocess/includes/test_collision.c @@ -0,0 +1,4 @@ +--- +- "/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h" +- src/main/c/Snake/snake_start.h +- src/main/c/Snake/get_character.h diff --git a/build/test/preprocess/includes/test_is_Valid_tile.c b/build/test/preprocess/includes/test_is_Valid_tile.c new file mode 100644 index 0000000..5630e0a --- /dev/null +++ b/build/test/preprocess/includes/test_is_Valid_tile.c @@ -0,0 +1,3 @@ +--- +- "/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h" +- build/temp/../../src/main/c/Minesweeper/minesweeper_start.h diff --git a/build/test/preprocess/includes/test_moving_snake.c b/build/test/preprocess/includes/test_moving_snake.c new file mode 100644 index 0000000..879a735 --- /dev/null +++ b/build/test/preprocess/includes/test_moving_snake.c @@ -0,0 +1,4 @@ +--- +- "/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h" +- build/temp/../../src/main/c/Snake/snake_start.h +- build/temp/../../src/main/c/Snake/get_character.h diff --git a/build/test/preprocess/includes/test_number_of_bombs.c b/build/test/preprocess/includes/test_number_of_bombs.c new file mode 100644 index 0000000..5630e0a --- /dev/null +++ b/build/test/preprocess/includes/test_number_of_bombs.c @@ -0,0 +1,3 @@ +--- +- "/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h" +- build/temp/../../src/main/c/Minesweeper/minesweeper_start.h diff --git a/build/test/preprocess/includes/test_part_of_snake.c b/build/test/preprocess/includes/test_part_of_snake.c new file mode 100644 index 0000000..879a735 --- /dev/null +++ b/build/test/preprocess/includes/test_part_of_snake.c @@ -0,0 +1,4 @@ +--- +- "/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h" +- build/temp/../../src/main/c/Snake/snake_start.h +- build/temp/../../src/main/c/Snake/get_character.h diff --git a/build/test/preprocess/includes/test_playerInputMovement.c b/build/test/preprocess/includes/test_playerInputMovement.c new file mode 100644 index 0000000..2b3a590 --- /dev/null +++ b/build/test/preprocess/includes/test_playerInputMovement.c @@ -0,0 +1,3 @@ +--- +- "/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h" +- src/main/c/Pong/pong.h diff --git a/build/test/preprocess/includes/test_pong.c b/build/test/preprocess/includes/test_pong.c new file mode 100644 index 0000000..2b3a590 --- /dev/null +++ b/build/test/preprocess/includes/test_pong.c @@ -0,0 +1,3 @@ +--- +- "/var/lib/gems/2.7.0/gems/ceedling-0.31.1/vendor/unity/src/unity.h" +- src/main/c/Pong/pong.h diff --git a/build/test/preprocess/includes/test_tictactoe.c b/build/test/preprocess/includes/test_tictactoe.c new file mode 100644 index 0000000..dcd024e --- /dev/null +++ b/build/test/preprocess/includes/test_tictactoe.c @@ -0,0 +1 @@ +--- [] diff --git a/build/test/results/test_bomb_in_array.pass b/build/test/results/test_bomb_in_array.pass new file mode 100644 index 0000000..7c25b4d --- /dev/null +++ b/build/test/results/test_bomb_in_array.pass @@ -0,0 +1,22 @@ +--- +:source: + :path: test/Minesweeper + :file: test_bomb_in_array.c +:successes: +- :test: test_bomb_in_array + :line: 11 + :message: '' + :unity_test_time: 0 +- :test: test_bomb_not_in_array + :line: 26 + :message: '' + :unity_test_time: 0 +:failures: [] +:ignores: [] +:counts: + :total: 2 + :passed: 2 + :failed: 0 + :ignored: 0 +:stdout: [] +:time: 0.001660895999521017 diff --git a/build/test/results/test_checkCollision.pass b/build/test/results/test_checkCollision.pass new file mode 100644 index 0000000..8d6367c --- /dev/null +++ b/build/test/results/test_checkCollision.pass @@ -0,0 +1,18 @@ +--- +:source: + :path: test/Pong + :file: test_checkCollision.c +:successes: +- :test: test_checkCollision + :line: 28 + :message: '' + :unity_test_time: 0 +:failures: [] +:ignores: [] +:counts: + :total: 1 + :passed: 1 + :failed: 0 + :ignored: 0 +:stdout: [] +:time: 0.0022849989982205443 diff --git a/build/test/results/test_checkGameEnd.pass b/build/test/results/test_checkGameEnd.pass new file mode 100644 index 0000000..9faf7ce --- /dev/null +++ b/build/test/results/test_checkGameEnd.pass @@ -0,0 +1,18 @@ +--- +:source: + :path: test/Pong + :file: test_checkGameEnd.c +:successes: +- :test: test_checkGameEnd + :line: 14 + :message: '' + :unity_test_time: 0 +:failures: [] +:ignores: [] +:counts: + :total: 1 + :passed: 1 + :failed: 0 + :ignored: 0 +:stdout: [] +:time: 0.0017912769981194288 diff --git a/build/test/results/test_clearScreen.pass b/build/test/results/test_clearScreen.pass new file mode 100644 index 0000000..6ce9220 --- /dev/null +++ b/build/test/results/test_clearScreen.pass @@ -0,0 +1,19 @@ +--- +:source: + :path: test/Pong + :file: test_clearScreen.c +:successes: +- :test: test_clearScreen + :line: 17 + :message: '' + :unity_test_time: 0 +:failures: [] +:ignores: [] +:counts: + :total: 1 + :passed: 1 + :failed: 0 + :ignored: 0 +:stdout: +- "\e[H\e[2J\e[3J" +:time: 0.003976027997850906 diff --git a/build/test/results/test_collision.pass b/build/test/results/test_collision.pass new file mode 100644 index 0000000..2fad159 --- /dev/null +++ b/build/test/results/test_collision.pass @@ -0,0 +1,26 @@ +--- +:source: + :path: test/Snake + :file: test_collision.c +:successes: +- :test: test_self_collision + :line: 12 + :message: '' + :unity_test_time: 0 +- :test: test_no_collision + :line: 25 + :message: '' + :unity_test_time: 0 +- :test: test_wall_collision + :line: 38 + :message: '' + :unity_test_time: 0 +:failures: [] +:ignores: [] +:counts: + :total: 3 + :passed: 3 + :failed: 0 + :ignored: 0 +:stdout: [] +:time: 0.0017233269973075949 diff --git a/build/test/results/test_is_Valid_tile.pass b/build/test/results/test_is_Valid_tile.pass new file mode 100644 index 0000000..2d4eef4 --- /dev/null +++ b/build/test/results/test_is_Valid_tile.pass @@ -0,0 +1,46 @@ +--- +:source: + :path: test/Minesweeper + :file: test_is_Valid_tile.c +:successes: +- :test: test_detect_not_valid_tile_left + :line: 10 + :message: '' + :unity_test_time: 0 +- :test: test_detect_not_valid_tile_up + :line: 24 + :message: '' + :unity_test_time: 0 +- :test: test_detect_not_valid_tile_right + :line: 38 + :message: '' + :unity_test_time: 0 +- :test: test_detect_not_valid_tile_down + :line: 52 + :message: '' + :unity_test_time: 0 +- :test: test_detect_valid_tile_left + :line: 66 + :message: '' + :unity_test_time: 0 +- :test: test_detect_valid_tile_up + :line: 80 + :message: '' + :unity_test_time: 0 +- :test: test_detect_valid_tile_right + :line: 94 + :message: '' + :unity_test_time: 0 +- :test: test_detect_valid_tile_down + :line: 108 + :message: '' + :unity_test_time: 0 +:failures: [] +:ignores: [] +:counts: + :total: 8 + :passed: 8 + :failed: 0 + :ignored: 0 +:stdout: [] +:time: 0.0016319420028594323 diff --git a/build/test/results/test_moving_snake.pass b/build/test/results/test_moving_snake.pass new file mode 100644 index 0000000..ca30b84 --- /dev/null +++ b/build/test/results/test_moving_snake.pass @@ -0,0 +1,30 @@ +--- +:source: + :path: test/Snake + :file: test_moving_snake.c +:successes: +- :test: test_moving_right + :line: 13 + :message: '' + :unity_test_time: 0 +- :test: test_moving_down + :line: 27 + :message: '' + :unity_test_time: 0 +- :test: test_moving_left + :line: 41 + :message: '' + :unity_test_time: 0 +- :test: test_moving_up + :line: 55 + :message: '' + :unity_test_time: 0 +:failures: [] +:ignores: [] +:counts: + :total: 4 + :passed: 4 + :failed: 0 + :ignored: 0 +:stdout: [] +:time: 0.0028836580022471026 diff --git a/build/test/results/test_number_of_bombs.pass b/build/test/results/test_number_of_bombs.pass new file mode 100644 index 0000000..2294956 --- /dev/null +++ b/build/test/results/test_number_of_bombs.pass @@ -0,0 +1,34 @@ +--- +:source: + :path: test/Minesweeper + :file: test_number_of_bombs.c +:successes: +- :test: test_no_bombs_placed_around_tile + :line: 11 + :message: '' + :unity_test_time: 0 +- :test: test_searching_for_bombs_on_correct_tiles + :line: 24 + :message: '' + :unity_test_time: 0 +- :test: test_2_bombs_around_tile + :line: 41 + :message: '' + :unity_test_time: 0 +- :test: test_5_bombs_around_tile + :line: 58 + :message: '' + :unity_test_time: 0 +- :test: test_8_bombs_around_tile + :line: 76 + :message: '' + :unity_test_time: 0 +:failures: [] +:ignores: [] +:counts: + :total: 5 + :passed: 5 + :failed: 0 + :ignored: 0 +:stdout: [] +:time: 0.0025690569964353926 diff --git a/build/test/results/test_part_of_snake.pass b/build/test/results/test_part_of_snake.pass new file mode 100644 index 0000000..9226901 --- /dev/null +++ b/build/test/results/test_part_of_snake.pass @@ -0,0 +1,26 @@ +--- +:source: + :path: test/Snake + :file: test_part_of_snake.c +:successes: +- :test: test_find_head + :line: 11 + :message: '' + :unity_test_time: 0 +- :test: test_get_correct_index + :line: 24 + :message: '' + :unity_test_time: 0 +- :test: test_snake_not_on_tile + :line: 37 + :message: '' + :unity_test_time: 0 +:failures: [] +:ignores: [] +:counts: + :total: 3 + :passed: 3 + :failed: 0 + :ignored: 0 +:stdout: [] +:time: 0.002005319998716004 diff --git a/build/test/results/test_playerInputMovement.pass b/build/test/results/test_playerInputMovement.pass new file mode 100644 index 0000000..ba39949 --- /dev/null +++ b/build/test/results/test_playerInputMovement.pass @@ -0,0 +1,18 @@ +--- +:source: + :path: test/Pong + :file: test_playerInputMovement.c +:successes: +- :test: test_playerInputMovement + :line: 20 + :message: '' + :unity_test_time: 0 +:failures: [] +:ignores: [] +:counts: + :total: 1 + :passed: 1 + :failed: 0 + :ignored: 0 +:stdout: [] +:time: 0.0013923250007792376 diff --git a/build/test/results/test_pong.pass b/build/test/results/test_pong.pass new file mode 100644 index 0000000..baea06b --- /dev/null +++ b/build/test/results/test_pong.pass @@ -0,0 +1,18 @@ +--- +:source: + :path: test/Pong + :file: test_pong.c +:successes: +- :test: test_input_all_5 + :line: 13 + :message: '' + :unity_test_time: 0 +:failures: [] +:ignores: [] +:counts: + :total: 1 + :passed: 1 + :failed: 0 + :ignored: 0 +:stdout: [] +:time: 0.0018394770013401285 diff --git a/build/test/results/test_template.pass b/build/test/results/test_template.pass index ac2a353..44f5caa 100644 --- a/build/test/results/test_template.pass +++ b/build/test/results/test_template.pass @@ -19,4 +19,4 @@ :failed: 0 :ignored: 0 :stdout: [] -:time: 0.002492974977940321 +:time: 0.001957057000254281 diff --git a/build/test/results/test_tictactoe.pass b/build/test/results/test_tictactoe.pass new file mode 100644 index 0000000..010d758 --- /dev/null +++ b/build/test/results/test_tictactoe.pass @@ -0,0 +1,14 @@ +--- +:source: + :path: test + :file: test_tictactoe.c +:successes: [] +:failures: [] +:ignores: [] +:counts: + :total: 0 + :passed: 0 + :failed: 0 + :ignored: 0 +:stdout: [] +:time: 0.0019282139983261004 diff --git a/build/test/runners/test_bomb_in_array_runner.c b/build/test/runners/test_bomb_in_array_runner.c new file mode 100644 index 0000000..b3dbc90 --- /dev/null +++ b/build/test/runners/test_bomb_in_array_runner.c @@ -0,0 +1,83 @@ +/* AUTOGENERATED FILE. DO NOT EDIT. */ + +/*=======Automagically Detected Files To Include=====*/ +#include "unity.h" + +int GlobalExpectCount; +int GlobalVerifyOrder; +char* GlobalOrderError; + +/*=======External Functions This Runner Calls=====*/ +extern void setUp(void); +extern void tearDown(void); +extern void test_bomb_in_array(void); +extern void test_bomb_not_in_array(void); + + +/*=======Mock Management=====*/ +static void CMock_Init(void) +{ + GlobalExpectCount = 0; + GlobalVerifyOrder = 0; + GlobalOrderError = NULL; +} +static void CMock_Verify(void) +{ +} +static void CMock_Destroy(void) +{ +} + +/*=======Test Reset Options=====*/ +void resetTest(void); +void resetTest(void) +{ + tearDown(); + CMock_Verify(); + CMock_Destroy(); + CMock_Init(); + setUp(); +} +void verifyTest(void); +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_bomb_in_array.c"); + run_test(test_bomb_in_array, "test_bomb_in_array", 11); + run_test(test_bomb_not_in_array, "test_bomb_not_in_array", 26); + + return UnityEnd(); +} diff --git a/build/test/runners/test_checkCollision_runner.c b/build/test/runners/test_checkCollision_runner.c new file mode 100644 index 0000000..0bed50f --- /dev/null +++ b/build/test/runners/test_checkCollision_runner.c @@ -0,0 +1,81 @@ +/* AUTOGENERATED FILE. DO NOT EDIT. */ + +/*=======Automagically Detected Files To Include=====*/ +#include "unity.h" + +int GlobalExpectCount; +int GlobalVerifyOrder; +char* GlobalOrderError; + +/*=======External Functions This Runner Calls=====*/ +extern void setUp(void); +extern void tearDown(void); +extern void test_checkCollision(void); + + +/*=======Mock Management=====*/ +static void CMock_Init(void) +{ + GlobalExpectCount = 0; + GlobalVerifyOrder = 0; + GlobalOrderError = NULL; +} +static void CMock_Verify(void) +{ +} +static void CMock_Destroy(void) +{ +} + +/*=======Test Reset Options=====*/ +void resetTest(void); +void resetTest(void) +{ + tearDown(); + CMock_Verify(); + CMock_Destroy(); + CMock_Init(); + setUp(); +} +void verifyTest(void); +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_checkCollision.c"); + run_test(test_checkCollision, "test_checkCollision", 28); + + return UnityEnd(); +} diff --git a/build/test/runners/test_checkGameEnd_runner.c b/build/test/runners/test_checkGameEnd_runner.c new file mode 100644 index 0000000..d83fa82 --- /dev/null +++ b/build/test/runners/test_checkGameEnd_runner.c @@ -0,0 +1,81 @@ +/* AUTOGENERATED FILE. DO NOT EDIT. */ + +/*=======Automagically Detected Files To Include=====*/ +#include "unity.h" + +int GlobalExpectCount; +int GlobalVerifyOrder; +char* GlobalOrderError; + +/*=======External Functions This Runner Calls=====*/ +extern void setUp(void); +extern void tearDown(void); +extern void test_checkGameEnd(void); + + +/*=======Mock Management=====*/ +static void CMock_Init(void) +{ + GlobalExpectCount = 0; + GlobalVerifyOrder = 0; + GlobalOrderError = NULL; +} +static void CMock_Verify(void) +{ +} +static void CMock_Destroy(void) +{ +} + +/*=======Test Reset Options=====*/ +void resetTest(void); +void resetTest(void) +{ + tearDown(); + CMock_Verify(); + CMock_Destroy(); + CMock_Init(); + setUp(); +} +void verifyTest(void); +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_checkGameEnd.c"); + run_test(test_checkGameEnd, "test_checkGameEnd", 14); + + return UnityEnd(); +} diff --git a/build/test/runners/test_clearScreen_runner.c b/build/test/runners/test_clearScreen_runner.c new file mode 100644 index 0000000..9c1799e --- /dev/null +++ b/build/test/runners/test_clearScreen_runner.c @@ -0,0 +1,81 @@ +/* AUTOGENERATED FILE. DO NOT EDIT. */ + +/*=======Automagically Detected Files To Include=====*/ +#include "unity.h" + +int GlobalExpectCount; +int GlobalVerifyOrder; +char* GlobalOrderError; + +/*=======External Functions This Runner Calls=====*/ +extern void setUp(void); +extern void tearDown(void); +extern void test_clearScreen(void); + + +/*=======Mock Management=====*/ +static void CMock_Init(void) +{ + GlobalExpectCount = 0; + GlobalVerifyOrder = 0; + GlobalOrderError = NULL; +} +static void CMock_Verify(void) +{ +} +static void CMock_Destroy(void) +{ +} + +/*=======Test Reset Options=====*/ +void resetTest(void); +void resetTest(void) +{ + tearDown(); + CMock_Verify(); + CMock_Destroy(); + CMock_Init(); + setUp(); +} +void verifyTest(void); +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_clearScreen.c"); + run_test(test_clearScreen, "test_clearScreen", 17); + + return UnityEnd(); +} diff --git a/build/test/runners/test_collision_runner.c b/build/test/runners/test_collision_runner.c new file mode 100644 index 0000000..d726b30 --- /dev/null +++ b/build/test/runners/test_collision_runner.c @@ -0,0 +1,85 @@ +/* AUTOGENERATED FILE. DO NOT EDIT. */ + +/*=======Automagically Detected Files To Include=====*/ +#include "unity.h" + +int GlobalExpectCount; +int GlobalVerifyOrder; +char* GlobalOrderError; + +/*=======External Functions This Runner Calls=====*/ +extern void setUp(void); +extern void tearDown(void); +extern void test_self_collision(void); +extern void test_no_collision(void); +extern void test_wall_collision(void); + + +/*=======Mock Management=====*/ +static void CMock_Init(void) +{ + GlobalExpectCount = 0; + GlobalVerifyOrder = 0; + GlobalOrderError = NULL; +} +static void CMock_Verify(void) +{ +} +static void CMock_Destroy(void) +{ +} + +/*=======Test Reset Options=====*/ +void resetTest(void); +void resetTest(void) +{ + tearDown(); + CMock_Verify(); + CMock_Destroy(); + CMock_Init(); + setUp(); +} +void verifyTest(void); +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_collision.c"); + run_test(test_self_collision, "test_self_collision", 12); + run_test(test_no_collision, "test_no_collision", 25); + run_test(test_wall_collision, "test_wall_collision", 38); + + return UnityEnd(); +} diff --git a/build/test/runners/test_is_Valid_tile_runner.c b/build/test/runners/test_is_Valid_tile_runner.c new file mode 100644 index 0000000..25de69d --- /dev/null +++ b/build/test/runners/test_is_Valid_tile_runner.c @@ -0,0 +1,95 @@ +/* AUTOGENERATED FILE. DO NOT EDIT. */ + +/*=======Automagically Detected Files To Include=====*/ +#include "unity.h" + +int GlobalExpectCount; +int GlobalVerifyOrder; +char* GlobalOrderError; + +/*=======External Functions This Runner Calls=====*/ +extern void setUp(void); +extern void tearDown(void); +extern void test_detect_not_valid_tile_left(void); +extern void test_detect_not_valid_tile_up(void); +extern void test_detect_not_valid_tile_right(void); +extern void test_detect_not_valid_tile_down(void); +extern void test_detect_valid_tile_left(void); +extern void test_detect_valid_tile_up(void); +extern void test_detect_valid_tile_right(void); +extern void test_detect_valid_tile_down(void); + + +/*=======Mock Management=====*/ +static void CMock_Init(void) +{ + GlobalExpectCount = 0; + GlobalVerifyOrder = 0; + GlobalOrderError = NULL; +} +static void CMock_Verify(void) +{ +} +static void CMock_Destroy(void) +{ +} + +/*=======Test Reset Options=====*/ +void resetTest(void); +void resetTest(void) +{ + tearDown(); + CMock_Verify(); + CMock_Destroy(); + CMock_Init(); + setUp(); +} +void verifyTest(void); +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_is_Valid_tile.c"); + run_test(test_detect_not_valid_tile_left, "test_detect_not_valid_tile_left", 10); + run_test(test_detect_not_valid_tile_up, "test_detect_not_valid_tile_up", 24); + run_test(test_detect_not_valid_tile_right, "test_detect_not_valid_tile_right", 38); + run_test(test_detect_not_valid_tile_down, "test_detect_not_valid_tile_down", 52); + run_test(test_detect_valid_tile_left, "test_detect_valid_tile_left", 66); + run_test(test_detect_valid_tile_up, "test_detect_valid_tile_up", 80); + run_test(test_detect_valid_tile_right, "test_detect_valid_tile_right", 94); + run_test(test_detect_valid_tile_down, "test_detect_valid_tile_down", 108); + + return UnityEnd(); +} diff --git a/build/test/runners/test_moving_snake_runner.c b/build/test/runners/test_moving_snake_runner.c new file mode 100644 index 0000000..8f786fb --- /dev/null +++ b/build/test/runners/test_moving_snake_runner.c @@ -0,0 +1,87 @@ +/* AUTOGENERATED FILE. DO NOT EDIT. */ + +/*=======Automagically Detected Files To Include=====*/ +#include "unity.h" + +int GlobalExpectCount; +int GlobalVerifyOrder; +char* GlobalOrderError; + +/*=======External Functions This Runner Calls=====*/ +extern void setUp(void); +extern void tearDown(void); +extern void test_moving_right(void); +extern void test_moving_down(void); +extern void test_moving_left(void); +extern void test_moving_up(void); + + +/*=======Mock Management=====*/ +static void CMock_Init(void) +{ + GlobalExpectCount = 0; + GlobalVerifyOrder = 0; + GlobalOrderError = NULL; +} +static void CMock_Verify(void) +{ +} +static void CMock_Destroy(void) +{ +} + +/*=======Test Reset Options=====*/ +void resetTest(void); +void resetTest(void) +{ + tearDown(); + CMock_Verify(); + CMock_Destroy(); + CMock_Init(); + setUp(); +} +void verifyTest(void); +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_moving_snake.c"); + run_test(test_moving_right, "test_moving_right", 13); + run_test(test_moving_down, "test_moving_down", 27); + run_test(test_moving_left, "test_moving_left", 41); + run_test(test_moving_up, "test_moving_up", 55); + + return UnityEnd(); +} diff --git a/build/test/runners/test_number_of_bombs_runner.c b/build/test/runners/test_number_of_bombs_runner.c new file mode 100644 index 0000000..e6e4376 --- /dev/null +++ b/build/test/runners/test_number_of_bombs_runner.c @@ -0,0 +1,89 @@ +/* AUTOGENERATED FILE. DO NOT EDIT. */ + +/*=======Automagically Detected Files To Include=====*/ +#include "unity.h" + +int GlobalExpectCount; +int GlobalVerifyOrder; +char* GlobalOrderError; + +/*=======External Functions This Runner Calls=====*/ +extern void setUp(void); +extern void tearDown(void); +extern void test_no_bombs_placed_around_tile(void); +extern void test_searching_for_bombs_on_correct_tiles(void); +extern void test_2_bombs_around_tile(void); +extern void test_5_bombs_around_tile(void); +extern void test_8_bombs_around_tile(void); + + +/*=======Mock Management=====*/ +static void CMock_Init(void) +{ + GlobalExpectCount = 0; + GlobalVerifyOrder = 0; + GlobalOrderError = NULL; +} +static void CMock_Verify(void) +{ +} +static void CMock_Destroy(void) +{ +} + +/*=======Test Reset Options=====*/ +void resetTest(void); +void resetTest(void) +{ + tearDown(); + CMock_Verify(); + CMock_Destroy(); + CMock_Init(); + setUp(); +} +void verifyTest(void); +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_number_of_bombs.c"); + run_test(test_no_bombs_placed_around_tile, "test_no_bombs_placed_around_tile", 11); + run_test(test_searching_for_bombs_on_correct_tiles, "test_searching_for_bombs_on_correct_tiles", 24); + run_test(test_2_bombs_around_tile, "test_2_bombs_around_tile", 41); + run_test(test_5_bombs_around_tile, "test_5_bombs_around_tile", 58); + run_test(test_8_bombs_around_tile, "test_8_bombs_around_tile", 76); + + return UnityEnd(); +} diff --git a/build/test/runners/test_part_of_snake_runner.c b/build/test/runners/test_part_of_snake_runner.c new file mode 100644 index 0000000..0f7e680 --- /dev/null +++ b/build/test/runners/test_part_of_snake_runner.c @@ -0,0 +1,85 @@ +/* AUTOGENERATED FILE. DO NOT EDIT. */ + +/*=======Automagically Detected Files To Include=====*/ +#include "unity.h" + +int GlobalExpectCount; +int GlobalVerifyOrder; +char* GlobalOrderError; + +/*=======External Functions This Runner Calls=====*/ +extern void setUp(void); +extern void tearDown(void); +extern void test_find_head(void); +extern void test_get_correct_index(void); +extern void test_snake_not_on_tile(void); + + +/*=======Mock Management=====*/ +static void CMock_Init(void) +{ + GlobalExpectCount = 0; + GlobalVerifyOrder = 0; + GlobalOrderError = NULL; +} +static void CMock_Verify(void) +{ +} +static void CMock_Destroy(void) +{ +} + +/*=======Test Reset Options=====*/ +void resetTest(void); +void resetTest(void) +{ + tearDown(); + CMock_Verify(); + CMock_Destroy(); + CMock_Init(); + setUp(); +} +void verifyTest(void); +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_part_of_snake.c"); + run_test(test_find_head, "test_find_head", 11); + run_test(test_get_correct_index, "test_get_correct_index", 24); + run_test(test_snake_not_on_tile, "test_snake_not_on_tile", 37); + + return UnityEnd(); +} diff --git a/build/test/runners/test_playerInputMovement_runner.c b/build/test/runners/test_playerInputMovement_runner.c new file mode 100644 index 0000000..6fde093 --- /dev/null +++ b/build/test/runners/test_playerInputMovement_runner.c @@ -0,0 +1,81 @@ +/* AUTOGENERATED FILE. DO NOT EDIT. */ + +/*=======Automagically Detected Files To Include=====*/ +#include "unity.h" + +int GlobalExpectCount; +int GlobalVerifyOrder; +char* GlobalOrderError; + +/*=======External Functions This Runner Calls=====*/ +extern void setUp(void); +extern void tearDown(void); +extern void test_playerInputMovement(void); + + +/*=======Mock Management=====*/ +static void CMock_Init(void) +{ + GlobalExpectCount = 0; + GlobalVerifyOrder = 0; + GlobalOrderError = NULL; +} +static void CMock_Verify(void) +{ +} +static void CMock_Destroy(void) +{ +} + +/*=======Test Reset Options=====*/ +void resetTest(void); +void resetTest(void) +{ + tearDown(); + CMock_Verify(); + CMock_Destroy(); + CMock_Init(); + setUp(); +} +void verifyTest(void); +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_playerInputMovement.c"); + run_test(test_playerInputMovement, "test_playerInputMovement", 20); + + return UnityEnd(); +} diff --git a/build/test/runners/test_pong_runner.c b/build/test/runners/test_pong_runner.c new file mode 100644 index 0000000..93a6451 --- /dev/null +++ b/build/test/runners/test_pong_runner.c @@ -0,0 +1,81 @@ +/* AUTOGENERATED FILE. DO NOT EDIT. */ + +/*=======Automagically Detected Files To Include=====*/ +#include "unity.h" + +int GlobalExpectCount; +int GlobalVerifyOrder; +char* GlobalOrderError; + +/*=======External Functions This Runner Calls=====*/ +extern void setUp(void); +extern void tearDown(void); +extern void test_input_all_5(void); + + +/*=======Mock Management=====*/ +static void CMock_Init(void) +{ + GlobalExpectCount = 0; + GlobalVerifyOrder = 0; + GlobalOrderError = NULL; +} +static void CMock_Verify(void) +{ +} +static void CMock_Destroy(void) +{ +} + +/*=======Test Reset Options=====*/ +void resetTest(void); +void resetTest(void) +{ + tearDown(); + CMock_Verify(); + CMock_Destroy(); + CMock_Init(); + setUp(); +} +void verifyTest(void); +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_pong.c"); + run_test(test_input_all_5, "test_input_all_5", 13); + + return UnityEnd(); +} diff --git a/build/test/runners/test_tictactoe_runner.c b/build/test/runners/test_tictactoe_runner.c new file mode 100644 index 0000000..161ff95 --- /dev/null +++ b/build/test/runners/test_tictactoe_runner.c @@ -0,0 +1,57 @@ +/* AUTOGENERATED FILE. DO NOT EDIT. */ + +/*=======Automagically Detected Files To Include=====*/ +#include "unity.h" + +int GlobalExpectCount; +int GlobalVerifyOrder; +char* GlobalOrderError; + +/*=======External Functions This Runner Calls=====*/ +extern void setUp(void); +extern void tearDown(void); + + +/*=======Mock Management=====*/ +static void CMock_Init(void) +{ + GlobalExpectCount = 0; + GlobalVerifyOrder = 0; + GlobalOrderError = NULL; +} +static void CMock_Verify(void) +{ +} +static void CMock_Destroy(void) +{ +} + +/*=======Setup (stub)=====*/ +void setUp(void) {} + +/*=======Teardown (stub)=====*/ +void tearDown(void) {} + +/*=======Test Reset Options=====*/ +void resetTest(void); +void resetTest(void) +{ + tearDown(); + CMock_Verify(); + CMock_Destroy(); + CMock_Init(); + setUp(); +} +void verifyTest(void); +void verifyTest(void) +{ + CMock_Verify(); +} + +/*=======MAIN=====*/ +int main(void) +{ + UnityBegin("test_tictactoe.c"); + + return UnityEnd(); +} diff --git a/src/main/c/GameTic_Tac_Toe/.gitkeep b/src/main/c/GameTic_Tac_Toe/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/main/c/GameTic_Tac_Toe/tictactoe.c b/src/main/c/GameTic_Tac_Toe/tictactoe.c new file mode 100644 index 0000000..0e5a452 --- /dev/null +++ b/src/main/c/GameTic_Tac_Toe/tictactoe.c @@ -0,0 +1,136 @@ +#include +#include "tictactoe.h" + +char board[3][3] = {{'1', '2', '3'}, + {'4', '5', '6'}, + {'7', '8', '9'}}; +char currentPlayer = 'X'; +const char PLAYER_X = 'X'; +const char PLAYER_O = 'O'; + +void reset_board(){ + for(int i = 0; i < BOARD_SIZE; i++){ + for(int j = 0; j < BOARD_SIZE; j++){ + board[i][j] = i * BOARD_SIZE + j + 49; + } + } +} + +// Funktionen zur Anzeige des Spielbretts +void displayBoard() { + printf("Tic-Tac-Toe\n"); + for (int i = 0; i < BOARD_SIZE; i++) { + for (int j = 0; j < BOARD_SIZE; j++) { + printf("%c", board[i][j]); + if (j < BOARD_SIZE - 1) printf(" | "); + } + printf("\n"); + if (i < BOARD_SIZE - 1) { + for (int k = 0; k < BOARD_SIZE * 4 - 1; k++) { + printf("-"); + } + printf("\n"); + } + } +} + +int get_move(){ + int choice; + printf("Spieler %c, waehle eine Zahl (1-9): ", (currentPlayer == PLAYER_X) ? 'X' : 'O'); + scanf("%d", &choice); + return choice; +} + +char checkLine(char a, char b, char c) { + if (a == b && b == c) return a; + return ' '; +} + +// Funktion zur Überprüfung des Gewinners +char checkWinner() { + // Überprüfe horizontale und vertikale Linien + for (int i = 0; i < BOARD_SIZE; i++) { + char horizontalWinner = checkLine(board[i][0], board[i][1], board[i][2]); + char verticalWinner = checkLine(board[0][i], board[1][i], board[2][i]); + + if (horizontalWinner != ' ') return horizontalWinner; + if (verticalWinner != ' ') return verticalWinner; + } + // Überprüfe diagonale Linien + char diagonal1Winner = checkLine(board[0][0], board[1][1], board[2][2]); + char diagonal2Winner = checkLine(board[0][2], board[1][1], board[2][0]); + + if (diagonal1Winner != ' ') return diagonal1Winner; + if (diagonal2Winner != ' ') return diagonal2Winner; + + // Kein Gewinner + return ' '; +} + +// Funktion zur Überprüfung, ob das Spiel unentschieden ist +int isBoardFull() { + for (int i = 0; i < BOARD_SIZE; i++) { + for (int j = 0; j < BOARD_SIZE; j++) { + if (board[i][j] != 'X' && board[i][j] != 'O') { + return 0; + } + } + } + return 1; +} + +// Funktion zum Zug eines Spielers +char switchPlayer(char currentPlayer) { + return (currentPlayer == PLAYER_X) ? PLAYER_O : PLAYER_X; +} + +int isValidMove(int choice) { + int row = (choice - 1) / BOARD_SIZE; + int col = (choice - 1) % BOARD_SIZE; + + return (choice >= 1 && choice <= BOARD_SIZE * BOARD_SIZE && board[row][col] != 'X' && board[row][col] != 'O'); +} + +void makeMove(int choice) { + + // Konvertiere die Zahl in Zeilen- und Spaltenindex + if (isValidMove(choice)) { + int row = (choice - 1) / BOARD_SIZE; + int col = (choice - 1) % BOARD_SIZE; + board[row][col] = (currentPlayer == PLAYER_X) ? 'X' : 'O'; + currentPlayer = switchPlayer(currentPlayer); + + } else { + printf("Ungueltiger Zug! Bitte waehle erneut.\n"); + makeMove(get_move()); // Rekursiver Aufruf, bis ein gültiger Zug gemacht wird + } +} + +int isGameOver() { + char winner = checkWinner(); + return (winner == PLAYER_X || winner == PLAYER_O || isBoardFull()); +} + + +void printGameResult(char winner) { + if (winner == PLAYER_X || winner == PLAYER_O) { + printf("Spieler %c gewinnt!\n", (winner == PLAYER_X) ? 'X' : 'O'); + } else { + printf("Unentschieden!\n"); + } +} + +void playGame() { + while (!isGameOver()) { + displayBoard(); + makeMove(get_move()); + } + + displayBoard(); + char winner = checkWinner(); + printGameResult(winner); +} + +void start_tictactoe(){ + playGame(); +} diff --git a/src/main/c/GameTic_Tac_Toe/tictactoe.h b/src/main/c/GameTic_Tac_Toe/tictactoe.h new file mode 100644 index 0000000..d007eb4 --- /dev/null +++ b/src/main/c/GameTic_Tac_Toe/tictactoe.h @@ -0,0 +1,14 @@ +#ifndef TICTACTOE_H +#define TICTACTOE_H + +#define BOARD_SIZE 3 + +int isValidMove(int choice); +char checkLine(char a, char b, char c); +void start_tictactoe(); +char checkWinner(); +void makeMove(int choice); +void displayBoard(); +void reset_board(); + +#endif diff --git a/src/main/c/Minesweeper/minesweeper_start.c b/src/main/c/Minesweeper/minesweeper_start.c new file mode 100644 index 0000000..a0f0d58 --- /dev/null +++ b/src/main/c/Minesweeper/minesweeper_start.c @@ -0,0 +1,272 @@ +#include +#include +#include +#include +#include "minesweeper_start.h" + +#pragma region defines +#define BLOCK '#' +#define FLAG 'x' +#define EMPTY ' ' +#define SMALL 10 +#define MIDDLE 15 +#define LARGE 20 +#define EASY 7 +#define NORMAL 5 +#define HARD 3 +#define OFFSET_NUM_CHARS 48 +#define OPEN_TILE 0 +#define FLAG_TILE 1 +#define QUIT_GAME 2 +#define ERROR -1 +#pragma endregion + +#pragma region Funktion_heads +void main_menu_minesweeper(); +void game_minesweeper(); +void options_minesweeper(); +Minesweeper_Board initialize_minesweeper(); +void place_bombs(Minesweeper_Board *board); +bool array_contains_value(int *array, int value, int length); +void draw_minesweeper(Minesweeper_Board *board); +int open_tile(Minesweeper_Board *board, int tile); +int number_of_bombs(Minesweeper_Board *board, int tile); +void open_empty_space(Minesweeper_Board *board, int tile, int index); +int is_Valid_tile(Minesweeper_Board *board, int tile, int i); +#pragma endregion + +#pragma region Global +unsigned int width = MIDDLE; +unsigned int height = MIDDLE; +int num_bombs = MIDDLE * MIDDLE / NORMAL; +#pragma endregion //Global + +void minesweeper_start(){ + system("clear"); + main_menu_minesweeper(); +} + +void main_menu_minesweeper(){ + bool running = true; + while (running){ + int option = 0; + + system("clear"); + printf("Waehlen Sie eine Option:\n"); + printf("\t1.Start\n"); + printf("\t2.Options\n"); + printf("\t3.Exit\n"); + + scanf("%d", &option); + getchar(); + + system("clear"); + + switch (option){ + case 1: + game_minesweeper(); + break; + case 2: + options_minesweeper(); + break; + case 3: + running = false; + break; + + default: + break; + } + } +} + +void game_minesweeper(){ + bool running = true; + int x, y, t; + Minesweeper_Board board = initialize_minesweeper(); + + place_bombs(&board); + + while (running){ + system("clear"); + draw_minesweeper(&board); + + printf("Next turn (x, y, t(0 = open, 1 = flag)): "); + scanf("%d %d %d", &x, &y, &t); + getchar(); + if(x < board.width && x > -1 && y < board.height && y > -1){ + x = x + y * board.width; + if(t == OPEN_TILE){ + int bombs = open_tile(&board, x); + if(bombs == ERROR){printf("You Lose!"); getchar(); break;} + else if(bombs == 0){ + open_empty_space(&board, x, 0); + for(int i = 0; i < board.width * board.height; i++){board.marked[i] = ERROR;} + } + else{board.tiles[x] = bombs + OFFSET_NUM_CHARS;} + } + if(t == FLAG_TILE){board.tiles[x] = board.tiles[x] == FLAG ? BLOCK : board.tiles[x] == BLOCK ? FLAG : board.tiles[x];} + } + if (t == QUIT_GAME){break;} + + int test = 1; + for (int i = 0; i < board.height * board.width; i++){if(board.tiles[i] == BLOCK){test = 0; break;}} + if(test){printf("You Win!"); getchar(); break;} + + } +} + +void options_minesweeper(){ + bool running = true; + while (running){ + int option = 0; + + system("clear"); + printf("Waehlen Sie eine Option:\n"); + printf("\t1.Schwierigkeit\t\t%s\n", num_bombs < 2 * width * height / (NORMAL + EASY) ? "Einfach" : num_bombs < 2 * width * height / (NORMAL + HARD) ? "Normal" : "Schwer"); + printf("\t2.Groesse\t\t%s\n", width * height < MIDDLE * SMALL ? "Klein" : width * height < MIDDLE * LARGE ? "Mittel" : "Gross"); + printf("\t3.Custom\n"); + printf("\t4.Exit\n"); + + scanf("%d", &option); + getchar(); + + switch (option){ + case 1: + printf("Bitte neue Schwierigkeit eingeben (1 - 3): "); + scanf("%d", &num_bombs); + getchar(); + num_bombs = num_bombs == 1 ? EASY : num_bombs == 2 ? NORMAL : HARD; + num_bombs = width * height / num_bombs; + break; + case 2: + num_bombs = num_bombs < width * height / NORMAL ? EASY : num_bombs == width * height / NORMAL ? NORMAL : HARD; + printf("Bitte neue Groesse eingeben (1 - 3): "); + scanf("%d", &width); + getchar(); + width = width == 1 ? SMALL : width == 2 ? MIDDLE : LARGE; + height = width; + num_bombs = width * height / num_bombs; + break; + case 3: + printf("Bitte Breite des Spielfeld eingeben: "); + scanf("%d", &width); + getchar(); + printf("Bitte Hoehe des Spielfeld eingeben: "); + scanf("%d", &height); + getchar(); + printf("Bitte Anzahl der Bomben eingeben: "); + scanf("%d", &num_bombs); + getchar(); + break; + case 4: + running = false; + break; + + default: + break; + } + } +} + +Minesweeper_Board initialize_minesweeper(){ + Minesweeper_Board board; + board.width = width; + board.height = height; + board.tiles = (int*) malloc(width * height * sizeof(int)); + for(int i = 0; i < width * height; i++){board.tiles[i] = BLOCK;} + board.marked = (int*) malloc(width * height * sizeof(int)); + for(int i = 0; i < width * height; i++){board.marked[i] = ERROR;} + board.num_bombs = num_bombs; + board.bombs = (int*) malloc(board.num_bombs * sizeof(int)); + for(int i = 0; i < num_bombs; i++){board.bombs[i] = ERROR;} + return board; +} + +void place_bombs(Minesweeper_Board *board){ + srand(time(NULL)); + int r; + for(int i = 0; i < board->num_bombs; i++){ + while (1){ + r = rand() % (board->width * board->height); + if(!array_contains_value(board->bombs, r, board->num_bombs)){break;} + } + board->bombs[i] = r; + } +} + +bool array_contains_value(int *array, int value, int length){ + for(int i = 0; i < length; i++){ + if(array[i] == value){return true;} + } + return false; +} + +void draw_minesweeper(Minesweeper_Board *board){ + int s = 0; + for(int i = 0; i < board->height * board->width; i++){s += board->tiles[i] == FLAG ? 1 : 0;} + printf("Score: %d\n", s); + printf(" "); + for(int i = 0; i < board->width; i++){printf("%d", i / 10);} + printf("\n "); + for(int i = 0; i < board->width; i++){printf("%d", i % 10);} + printf("\n +"); + for(int i = 0; i < board->width; i++){printf("-");} + printf("+\n"); + for(int i = 0; i < board->height; i++){ + printf("%d", i / 10); + printf("%d|", i % 10); + for(int j = 0; j < board->width; j++){printf("%c", board->tiles[i * width + j]);} + printf("|%d", i / 10); + printf("%d\n", i % 10); + } + printf(" +"); + for(int i = 0; i < board->width; i++){printf("-");} + printf("+\n "); + for(int i = 0; i < board->width; i++){printf("%d", i / 10);} + printf("\n "); + for(int i = 0; i < board->width; i++){printf("%d", i % 10);} + printf("\n"); +} + +int open_tile(Minesweeper_Board *board, int tile){ + if(array_contains_value(board->bombs, tile, board->num_bombs)){return ERROR;} + return number_of_bombs(board, tile); +} + +int number_of_bombs(Minesweeper_Board *board, int tile){ + int sum = 0; + for(int i = 0; i < 8; i++){ + int check_tile = is_Valid_tile(board, tile, i); + if(check_tile == ERROR){continue;} + if(array_contains_value(board->bombs, check_tile, board->num_bombs)){sum++;} + } + return sum; +} + +void open_empty_space(Minesweeper_Board *board, int tile, int index){ + board->tiles[tile] = EMPTY; + board->marked[index] = tile; + for(int i = 0; i < 8; i++){ + int check_tile = is_Valid_tile(board, tile, i); + if(check_tile == ERROR){continue;} + int sum = open_tile(board, check_tile); + if(sum != 0){board->tiles[check_tile] = sum + OFFSET_NUM_CHARS;} + else if(!array_contains_value(board->marked, check_tile, board->height * board->width)){open_empty_space(board, check_tile, index + 1);} + } +} + +//0 = up-left, 1 = down-left, 2 = mid-left, 3 = up-mid, 4 = down-mid, 5 = mid-right, 6 = up-right, 7 = down-right +int is_Valid_tile(Minesweeper_Board *board, int tile, int direction){ + int check_tile = tile; + + if(direction < 3){if(tile % board->width == 0){return ERROR;} + else{check_tile -= 1;}} + if(direction > 4){if(tile % board->width + 1 == board->width){return ERROR;} + else{check_tile += 1;}} + if(direction % 3 == 0){if(tile / board->width == 0){return ERROR;} + else{check_tile -= board->width;}} + if(direction % 3 == 1){if(tile / board->width + 1 == height){return ERROR;} + else{check_tile += board->width;}} + + return check_tile; +} \ No newline at end of file diff --git a/src/main/c/Minesweeper/minesweeper_start.h b/src/main/c/Minesweeper/minesweeper_start.h new file mode 100644 index 0000000..750003e --- /dev/null +++ b/src/main/c/Minesweeper/minesweeper_start.h @@ -0,0 +1,20 @@ +#ifndef MINESWEEPER_START_H +#define MINESWEEPER_START_H +#include + +typedef struct Minesweeper_Board{ + unsigned int width; + unsigned int height; + int *tiles; + int *marked; + int num_bombs; + int *bombs; +}Minesweeper_Board; + +void minesweeper_start(); +Minesweeper_Board initialize_minesweeper(); +bool array_contains_value(int *array, int bomb, int length); +int number_of_bombs(Minesweeper_Board *board, int tile); +int is_Valid_tile(Minesweeper_Board *board, int tile, int direction); + +#endif // MINESWEEPER_START_H \ No newline at end of file diff --git a/src/main/c/Pong/.gitkeep b/src/main/c/Pong/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/main/c/Pong/pong.c b/src/main/c/Pong/pong.c new file mode 100644 index 0000000..190f4c8 --- /dev/null +++ b/src/main/c/Pong/pong.c @@ -0,0 +1,231 @@ +#include +#include +#include +#include +#include +#include + +#define WIDTH 40 //Breite Spielfeld +#define HEIGHT 20 //Höhe Spielfeld +#define PADDLE_LENGTH 4 +#define PADDLE "\033[1;31m#\033[0m" +#define BALL "\033[1;31mO\033[0m" + +//Ballstruktur +typedef struct { + int x; + int y; + int speedX; + int speedY; +} Ball; + +// Bildschirm löschen nach Veränderung Position +void clearScreen() { + system("clear"); +} + +void drawField(int paddle1PositionY, int paddle2PositionY, Ball ball, int score1, int score2, int isPaused) { + clearScreen(); + + for (int i = 0; i <= HEIGHT; i++){ + for (int j = 0; j <= WIDTH; j++){ + if (i == 0 || i == HEIGHT){ + printf("-"); + } else if ((j == 0 || j == WIDTH) && (i < paddle1PositionY || i >= paddle1PositionY + PADDLE_LENGTH) && (i < paddle2PositionY || i >= paddle2PositionY + PADDLE_LENGTH)) { + printf("|"); + } else if (i >= paddle1PositionY && i < paddle1PositionY + PADDLE_LENGTH && j == WIDTH) { + printf("%s", PADDLE); + } else if (i >= paddle2PositionY && i < paddle2PositionY + PADDLE_LENGTH && j == 0) { + printf("%s", PADDLE); + } else if (i == ball.y && j == ball.x) { + printf("%s", BALL); + } else { + printf(" "); + } + } + printf("\n"); + } + + printf("Spieler 1: %d\tSpieler 2: %d\n", score1, score2); + if (isPaused) { + printf("Spiel pausiert. Drücken Sie 'p', um fortzufahren.\n"); + } else { + printf("Drücken Sie 'p', um das Spiel zu pausieren.\n"); + } + printf("Drücken Sie 'q', um das Spiel zu beenden.\n"); +} + +int kbhit(void){ + struct termios oldt, newt; + int ch, oldf; + + tcgetattr(STDIN_FILENO, &oldt); + newt = oldt; + newt.c_lflag &= ~(ICANON | ECHO); + tcsetattr(STDIN_FILENO, TCSANOW, &newt); + oldf = fcntl(STDIN_FILENO, F_GETFL, 0); + fcntl(STDIN_FILENO, F_SETFL, oldf | O_NONBLOCK); + + ch = getchar(); + + tcsetattr(STDIN_FILENO, TCSANOW, &oldt); + fcntl(STDIN_FILENO, F_SETFL, oldf); + + if (ch != EOF) { + ungetc(ch, stdin); + return 1; + } +return 0; +} + +int getch(void) { + int ch; + + while ((ch = getchar()) == '\n'); + + return ch; +} + +//Aktualisierung Ballposition +void updateBallPosition(Ball *ball) { + ball->x += ball->speedX; + ball->y += ball->speedY; +} + +//Verbesserung Kollision mit Schlägern&Wänden +int checkCollision(Ball ball, int paddle1PositionY, int paddle2PositionY) { + // Kollision mit Schlägern und Wänden + if (ball.y <= 0 || ball.y >= HEIGHT - 1){ + ball.speedY = -ball.speedY; + } + if (ball.x == 1 && (ball.y >= paddle2PositionY && ball.y < paddle2PositionY + PADDLE_LENGTH)){ + ball.speedX = -ball.speedX; + } + + if (ball.x == WIDTH - 1 && (ball.y >= paddle1PositionY && ball.y < paddle1PositionY + PADDLE_LENGTH)){ + ball.speedX = -ball.speedX; + } + + //Punkte zählen + if (ball.x <= 0){ + return 1; // Spieler 2 gewinnt Punkt + } + + if (ball.x >= WIDTH - 1){ + return 2; // Spieler 1 gewinnt Punkt + } + + return 0; // kein Punkt +} + +//Reset +void resetScore(int *score1, int *score2) { + *score1 = 0; + *score2 = 0; +} + +int checkGameEnd(int score1, int score2, int maxScore) { + if (score1 >= maxScore || score2 >= maxScore) { + return 1; // Das Spiel endet + } else { + return 0; // Das Spiel endet nicht + } +} + +void processPlayerInput(int *paddlePositionY, int userInput) { + if (userInput == -1) { + // Bewegt den Schläger nach oben, solange der obere Rand nicht erreicht ist + if (*paddlePositionY > 0) { + *paddlePositionY -=1; + } + } else if (userInput == 1) { + // Bewegt den Schläger nach unten, solange der untere Rand nicht erreicht ist + if (*paddlePositionY < HEIGHT - PADDLE_LENGTH) { + *paddlePositionY += 1; + } + } +} + +int pong(){ + int paddle1PositionY = HEIGHT / 2 - PADDLE_LENGTH / 2; + int paddle2PositionY = HEIGHT / 2 - PADDLE_LENGTH / 2; + Ball ball = {WIDTH / 2, HEIGHT / 2, 1, 1}; //Startposition&Geschwindigkeit Ball + int score1 = 0; + int score2 = 0; + int maxScore = 5; + int isPaused = 0; + + while (score1 < maxScore && score2 < maxScore) { + //Steuerung für Schläger 1 + if (!isPaused && kbhit()){ + char input = getch(); + if (input == 'w' && paddle1PositionY > 1) + { + paddle1PositionY--; + } else if (input == 's' && paddle1PositionY < HEIGHT - PADDLE_LENGTH - 1) { + paddle1PositionY++; + } else if (input == 'p') { + isPaused = !isPaused; + } else if (input == 'q') { + clearScreen(); + printf("Spiel beendet.\n"); + return 0; + } + } + +//Steuerung für Schläger 2 + if (!isPaused && kbhit()){ + char input = getch(); + if (input == 'i' && paddle2PositionY > 1){ + paddle2PositionY--; + } else if (input == 'k' && paddle2PositionY < HEIGHT - PADDLE_LENGTH - 1){ + paddle2PositionY++; + } else if (input == 'p') { + isPaused = !isPaused; + } else if (input == 'q') { + clearScreen(); + printf("Spiel beendet.\n"); + return 0; + } + } + + //Wenn Pauseiert + if (isPaused) { + drawField(paddle1PositionY, paddle2PositionY, ball, score1, score2, 1); + continue; + } + + //Bewegung Ball + updateBallPosition(&ball); + int result = checkCollision(ball, paddle1PositionY, paddle2PositionY); + + //Aktualisiert Spielstand und Ballposition + if (result == 1) { + score2++; + ball.x = WIDTH / 2; + ball.y = HEIGHT / 2; + ball.speedX = -ball.speedX; + } else if (result == 2) { + score1++; + ball.x = WIDTH / 2; + ball.y = HEIGHT / 2; + ball.speedX = -ball.speedX; + } + + resetScore(&score1, &score2); //Zurücksetzen Spielstand + + drawField(paddle1PositionY, paddle2PositionY, ball, score1, score2, 0); + usleep(100000); //Verlangsamen Schleife/Spiel + } + + clearScreen(); + if (score1 == maxScore) { + printf("Spieler 1 gewinnt!\n"); + } else { + printf("Spieler 2 gewinnt!\n"); + } + + return 0; +} + + diff --git a/src/main/c/Pong/pong.h b/src/main/c/Pong/pong.h new file mode 100644 index 0000000..4e6cfdd --- /dev/null +++ b/src/main/c/Pong/pong.h @@ -0,0 +1,9 @@ +#ifndef PONG_H +#define PONG_H + +int pong(); + +void resetScore(int *score1, int *score2); + +#endif + diff --git a/src/main/c/Snake/get_character.c b/src/main/c/Snake/get_character.c new file mode 100644 index 0000000..9c180ef --- /dev/null +++ b/src/main/c/Snake/get_character.c @@ -0,0 +1,58 @@ +#include +#include +#include +#include +#include +#include + +struct termios orig_termios; + +void reset_terminal_mode(){ + tcsetattr(0, TCSANOW, &orig_termios); +} + +void set_conio_terminal_mode(){ + struct termios new_termios; + + /* take two copies - one for now, one for later */ + tcgetattr(0, &orig_termios); + memcpy(&new_termios, &orig_termios, sizeof(new_termios)); + + /* register cleanup handler, and set the new terminal mode */ + atexit(reset_terminal_mode); + cfmakeraw(&new_termios); + tcsetattr(0, TCSANOW, &new_termios); +} + +int kbhit(){ + struct timeval tv = { 0L, 0L }; + fd_set fds; + FD_ZERO(&fds); + FD_SET(0, &fds); + return select(1, &fds, NULL, NULL, &tv) > 0; +} + +int getch(){ + int r; + unsigned char c; + if ((r = read(0, &c, sizeof(c))) < 0) { + return r; + } else { + return c; + } +} + +char get_character(double limit){ + set_conio_terminal_mode(); + + clock_t t = clock(); + char c = 0; + + while ((double)(clock() - t) / CLOCKS_PER_SEC < limit){ + if(kbhit()){c = getch();} + } + + reset_terminal_mode(); + + return c; +} \ No newline at end of file diff --git a/src/main/c/Snake/get_character.h b/src/main/c/Snake/get_character.h new file mode 100644 index 0000000..a955266 --- /dev/null +++ b/src/main/c/Snake/get_character.h @@ -0,0 +1,6 @@ +#ifndef GET_CHARACTER_H +#define GET_CHARACTER_H + +char get_character(double limit); + +#endif // GET_CHARACTER_H \ No newline at end of file diff --git a/src/main/c/Snake/snake_start.c b/src/main/c/Snake/snake_start.c new file mode 100644 index 0000000..ac8690f --- /dev/null +++ b/src/main/c/Snake/snake_start.c @@ -0,0 +1,209 @@ +#include +#include +#include +#include +#include +#include "snake_start.h" +#include "get_character.h" + +#pragma region defines +#define WIDTH 15 +#define HEIGHT 15 +#define TURN 0.5 +#define START_LENGTH 3 +#define START_DIRECTION 1 +#define START_TILE 8 * 16 + 8 +#pragma endregion + +#pragma region Funktion_heads +void main_menu_snake(); +void game_snake(); +void options_snake(); +Snake initialize_snake(); +void get_next_move(double limit, Snake *snake, bool *running); +void move_snake(Snake *snake); +void draw_snake(Snake *snake, unsigned char fruit); +int part_of_snake(Snake *snake, unsigned char tile); +bool check_if_dead(Snake *snake); +unsigned char spawn_fruit(Snake *snake); +unsigned char eating_fruit(Snake *snake); +#pragma endregion + +#pragma region Global +double TIME_TURN = 0.5; +#pragma endregion //Global + +void snake_start(){ + system("clear"); + main_menu_snake(); +} + +void main_menu_snake(){ + bool running = true; + while (running){ + int option = 0; + + system("clear"); + printf("Waehlen Sie eine Option:\n"); + printf("\t1.Start\n"); + printf("\t2.Options\n"); + printf("\t3.Exit\n"); + + scanf("%d", &option); + getchar(); + + system("clear"); + + switch (option){ + case 1: + game_snake(); + break; + case 2: + options_snake(); + break; + case 3: + running = false; + break; + + default: + break; + } + } +} + +void game_snake(){ + Snake snake = initialize_snake(); + bool running = true; + clock_t t = clock(); + unsigned char fruit = spawn_fruit(&snake); + + while (running){ + system("clear"); + draw_snake(&snake, fruit); + if(check_if_dead(&snake)){printf("You Lose!"); getchar(); break;} + t = clock() - t; + get_next_move(TIME_TURN - (double)t / CLOCKS_PER_SEC, &snake, &running); + t = clock(); + move_snake(&snake); + if(part_of_snake(&snake, fruit) == 0){fruit = eating_fruit(&snake);} + if(snake.length == WIDTH * HEIGHT){printf("You Win!"); running = false; getchar();} + } +} + +void options_snake(){ + int difficulty = 1; + system("clear"); + printf("Please select a difficulty(1 - 10): "); + scanf("%d", &difficulty); + TIME_TURN = TURN / difficulty; +} + +Snake initialize_snake(){ + Snake snake; + snake.direction = START_DIRECTION; + snake.length = START_LENGTH; + for(int i = 0; i < START_LENGTH; i++){ + snake.segments[i] = START_TILE - START_DIRECTION * i; + } + return snake; +} + +void get_next_move(double limit, Snake *snake, bool *running){ + char c; + + c = get_character(limit); + + switch (c){ + case 'w': + case 'A': + snake->direction = -16; + break; + case 'a': + case 'D': + snake->direction = -1; + break; + case 's': + case 'B': + snake->direction = 16; + break; + case 'd': + case 'C': + snake->direction = 1; + break; + case 'q': + *running = false; + + default: + break; + } +} + +void move_snake(Snake *snake){ + for(int i = snake->length - 1; i > 0; i--){ + snake->segments[i] = snake->segments[i - 1]; + } + snake->segments[0] += snake->direction; +} + +void draw_snake(Snake *snake, unsigned char fruit){ + printf("Score:%d Speed:%f\n", snake->length - START_LENGTH, TIME_TURN); + printf("+"); + for(int i = 0; i < WIDTH; i++){printf("-");} + printf("+\n"); + for(int i = 1; i <= HEIGHT; i++){ + printf("|"); + for(int j = 1; j <= WIDTH; j++){ + int index = part_of_snake(snake, i * 16 + j); + if(index == 0){ + switch(snake->direction){ + case -16: printf("A");break; + case -1: printf("<");break; + case 1: printf(">");break; + case 16: printf("V");break; + default: break;}} + else if(index > 0){printf("O");} + else if(i * 16 + j == fruit){printf("X");} + else{printf(" ");} + } + printf("|\n"); + } + printf("+"); + for(int i = 0; i < WIDTH; i++){printf("-");} + printf("+\n"); + printf("(Press q to Quit)\n"); +} + +//returns index of segments which is identical to tile; -1 if not found +int part_of_snake(Snake *snake, unsigned char tile){ + for(int i = snake->length - 1; i >= 0; i--){ + if(snake->segments[i] == tile){ + return i; + } + } + return -1; +} + +bool check_if_dead(Snake *snake){ + //Self + if(part_of_snake(snake, snake->segments[0])){return true;} + + //Wall + if(snake->segments[0] % 16 == 0 || (snake->segments[0] / 16) % 16 == 0){return true;} + + return false; +} + +unsigned char spawn_fruit(Snake *snake){ + srand(time(NULL)); + int r = 0; + while (part_of_snake(snake, r) != -1 || r % 16 == 0 || (r / 16) % 16 == 0){ + r = rand() % 256; + printf("%d\n", r); + } + return r; +} + +unsigned char eating_fruit(Snake *snake){ + snake->length++; + return spawn_fruit(snake); +} \ No newline at end of file diff --git a/src/main/c/Snake/snake_start.h b/src/main/c/Snake/snake_start.h new file mode 100644 index 0000000..b985421 --- /dev/null +++ b/src/main/c/Snake/snake_start.h @@ -0,0 +1,20 @@ +#ifndef SNAKE_START_H +#define SNAKE_START_H + +#include + +typedef struct Snake{ + signed char direction; + char length; + unsigned char segments[225]; +}Snake; + + +void snake_start(); +Snake initialize_snake(); +int part_of_snake(Snake *snake, unsigned char tile); +void move_snake(Snake *snake); +bool check_if_dead(Snake *snake); + + +#endif // SNAKE_START_H \ No newline at end of file diff --git a/src/main/c/main.c b/src/main/c/main.c index bbaaa50..4f8b2c5 100644 --- a/src/main/c/main.c +++ b/src/main/c/main.c @@ -2,10 +2,12 @@ #include #include + +#include "GameTic_Tac_Toe/tictactoe.h" #include "Snake/snake_start.h" #include "Minesweeper/minesweeper_start.h" #include "Pong/pong.h" -#include "playHangman.h" +#include "Hangman/playHangman.h" int main(){ bool running = true; @@ -16,40 +18,40 @@ int main(){ system("clear"); printf("Waehlen Sie eine Option:\n"); - printf("\t1.Hangman1 starten\n"); + printf("\t1.Hangman starten\n"); printf("\t2.Pong starten\n"); printf("\t3.Snake starten\n"); - printf("\t4.Spiel4 starten\n"); + printf("\t4.tic_tac_toe starten\n"); printf("\t7.Minesweeper starten\n"); printf("\t10.Exit\n"); - + scanf("%d", &option); getchar(); switch (option){ - case 1: - playHangman(selectRandomWord()); - break; - case 2: - pong(); - break; - case 3: - snake_start(); - break; - case 4: - //start_game4(); - break; - case 7: - minesweeper_start(); - break; - case 10: - system("clear"); - running = false; - break; - - default: - break; + case 1: + playHangman(selectRandomWord()); + break; + case 2: + pong(); + break; + case 3: + snake_start(); + break; + case 4: + start_tictactoe(); + break; + case 7: + minesweeper_start(); + break; + case 10: + system("clear"); + running = false; + break; + + default: + break; } } - return 0; + return 0; } diff --git a/src/main/c/main.h b/src/main/c/main.h index 71870e0..013f02f 100644 --- a/src/main/c/main.h +++ b/src/main/c/main.h @@ -3,4 +3,4 @@ int main(); -#endif // MAIN_H \ No newline at end of file +#endif // MAIN_H diff --git a/team.md b/team.md index bdce5f5..1c481f3 100644 --- a/team.md +++ b/team.md @@ -1,4 +1,6 @@ - David Moeller, fdai8032 - Julia Selig, fdai8040 - Ariana Ginju, fdai7775 +- fdai7775, fdai7775 - Saba Fazlali, fdai7875 +- Nina Gärtner, fdai7729 diff --git a/test/Minesweeper/test_bomb_in_array.c b/test/Minesweeper/test_bomb_in_array.c new file mode 100644 index 0000000..7073857 --- /dev/null +++ b/test/Minesweeper/test_bomb_in_array.c @@ -0,0 +1,40 @@ +#ifdef TEST +#include "unity.h" +#include +#include "../../src/main/c/Minesweeper/minesweeper_start.h" + + +void setUp(void){} +void tearDown(void){} + + +void test_bomb_in_array(void){ + /* arrange */ + bool result; + int array[] = {5, 9, 42, 6, 87, 95, 202, 13, 45 ,78}; + int bomb = 42; + int length = 10; + + /* act */ + result = array_contains_value(array, bomb, length); + + /* assert */ + TEST_ASSERT_TRUE(result); +} + + +void test_bomb_not_in_array(void){ + /* arrange */ + bool result; + int array[] = {5, 9, 42, 6, 87, 95, 202, 13, 45 ,78}; + int bomb = 0; + int length = 10; + + /* act */ + result = array_contains_value(array, bomb, length); + + /* assert */ + TEST_ASSERT_FALSE(result); +} + +#endif // TEST \ No newline at end of file diff --git a/test/Minesweeper/test_is_Valid_tile.c b/test/Minesweeper/test_is_Valid_tile.c new file mode 100644 index 0000000..13e8980 --- /dev/null +++ b/test/Minesweeper/test_is_Valid_tile.c @@ -0,0 +1,122 @@ +#ifdef TEST +#include "unity.h" +#include "../../src/main/c/Minesweeper/minesweeper_start.h" + + +void setUp(void){} +void tearDown(void){} + + +void test_detect_not_valid_tile_left(void){ + /* arrange */ + Minesweeper_Board board = initialize_minesweeper(); + int tile = 0; + int direction = 2; + int result; + + /* act */ + result = is_Valid_tile(&board, tile, direction); + + /* assert */ + TEST_ASSERT_EQUAL_INT(-1, result);//not valid tile +} + +void test_detect_not_valid_tile_up(void){ + /* arrange */ + Minesweeper_Board board = initialize_minesweeper(); + int tile = 0; + int direction = 3; + int result; + + /* act */ + result = is_Valid_tile(&board, tile, direction); + + /* assert */ + TEST_ASSERT_EQUAL_INT(-1, result);//not valid tile +} + +void test_detect_not_valid_tile_right(void){ + /* arrange */ + Minesweeper_Board board = initialize_minesweeper(); + int tile = board.width * board.height - 1; + int direction = 5; + int result; + + /* act */ + result = is_Valid_tile(&board, tile, direction); + + /* assert */ + TEST_ASSERT_EQUAL_INT(-1, result);//not valid tile +} + +void test_detect_not_valid_tile_down(void){ + /* arrange */ + Minesweeper_Board board = initialize_minesweeper(); + int tile = board.width * board.height - 1; + int direction = 4; + int result; + + /* act */ + result = is_Valid_tile(&board, tile, direction); + + /* assert */ + TEST_ASSERT_EQUAL_INT(-1, result);//not valid tile +} + +void test_detect_valid_tile_left(void){ + /* arrange */ + Minesweeper_Board board = initialize_minesweeper(); + int tile = board.width * board.height - 1; + int direction = 2; + int result; + + /* act */ + result = is_Valid_tile(&board, tile, direction); + + /* assert */ + TEST_ASSERT_EQUAL_INT(board.width * board.height - 2, result);//not valid tile +} + +void test_detect_valid_tile_up(void){ + /* arrange */ + Minesweeper_Board board = initialize_minesweeper(); + int tile = board.width * board.height - 1; + int direction = 3; + int result; + + /* act */ + result = is_Valid_tile(&board, tile, direction); + + /* assert */ + TEST_ASSERT_EQUAL_INT(board.width * (board.height - 1) - 1, result);//not valid tile +} + +void test_detect_valid_tile_right(void){ + /* arrange */ + Minesweeper_Board board = initialize_minesweeper(); + int tile = 0; + int direction = 5; + int result; + + /* act */ + result = is_Valid_tile(&board, tile, direction); + + /* assert */ + TEST_ASSERT_EQUAL_INT(1, result);//not valid tile +} + +void test_detect_valid_tile_down(void){ + /* arrange */ + Minesweeper_Board board = initialize_minesweeper(); + int tile = 0; + int direction = 4; + int result; + + /* act */ + result = is_Valid_tile(&board, tile, direction); + + /* assert */ + TEST_ASSERT_EQUAL_INT(0 + board.width, result);//not valid tile +} + +#endif // TEST \ No newline at end of file diff --git a/test/Minesweeper/test_number_of_bombs.c b/test/Minesweeper/test_number_of_bombs.c new file mode 100644 index 0000000..6a0dd4f --- /dev/null +++ b/test/Minesweeper/test_number_of_bombs.c @@ -0,0 +1,97 @@ +#ifdef TEST +#include "unity.h" +#include +#include "../../src/main/c/Minesweeper/minesweeper_start.h" + + +void setUp(void){} +void tearDown(void){} + + +void test_no_bombs_placed_around_tile(void){ + /* arrange */ + int result; + Minesweeper_Board board = initialize_minesweeper(); + int tile = 0 + board.width * 1; + + /* act */ + result = number_of_bombs(&board, tile); + + /* assert */ + TEST_ASSERT_EQUAL_INT(0, result);//no bombs placed +} + +void test_searching_for_bombs_on_correct_tiles(void){ + /* arrange */ + int result; + Minesweeper_Board board = initialize_minesweeper(); + int tile = 0 + board.width * 1; + board.bombs[0] = 0 + board.width * 3; + board.bombs[1] = 2 + board.width * 1; + board.bombs[2] = board.width - 1 + board.width * 1; + board.bombs[3] = 0 + board.width * (board.height - 1); + + /* act */ + result = number_of_bombs(&board, tile); + + /* assert */ + TEST_ASSERT_EQUAL_INT(0, result);//no bombs placed around tile +} + +void test_2_bombs_around_tile(void){ + /* arrange */ + int result; + Minesweeper_Board board = initialize_minesweeper(); + int tile = 0 + board.width * 1; + board.bombs[0] = 0 + board.width * 2; + board.bombs[1] = 1 + board.width * 1; + board.bombs[2] = board.width - 1 + board.width * 1; + board.bombs[3] = 0 + board.width * (board.height - 1); + + /* act */ + result = number_of_bombs(&board, tile); + + /* assert */ + TEST_ASSERT_EQUAL_INT(2, result);//2 bombs placed around tile +} + +void test_5_bombs_around_tile(void){ + /* arrange */ + int result; + Minesweeper_Board board = initialize_minesweeper(); + int tile = 1 + board.width * 0; + board.bombs[0] = 0 + board.width * 0; + board.bombs[1] = 2 + board.width * 0; + board.bombs[2] = 0 + board.width * 1; + board.bombs[3] = 1 + board.width * 1; + board.bombs[4] = 2 + board.width * 1; + + /* act */ + result = number_of_bombs(&board, tile); + + /* assert */ + TEST_ASSERT_EQUAL_INT(5, result);//5 bombs placed around tile +} + +void test_8_bombs_around_tile(void){ + /* arrange */ + int result; + Minesweeper_Board board = initialize_minesweeper(); + int tile = 7 + board.width * 7; + board.bombs[0] = 6 + board.width * 6; + board.bombs[1] = 7 + board.width * 6; + board.bombs[2] = 8 + board.width * 6; + board.bombs[3] = 6 + board.width * 7; + board.bombs[4] = 8 + board.width * 7; + board.bombs[5] = 6 + board.width * 8; + board.bombs[6] = 7 + board.width * 8; + board.bombs[7] = 8 + board.width * 8; + + /* act */ + result = number_of_bombs(&board, tile); + + /* assert */ + TEST_ASSERT_EQUAL_INT(8, result);//2 bombs placed around tile +} + +#endif // TEST \ No newline at end of file diff --git a/test/Pong/.gitkeep b/test/Pong/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/test/Pong/test_checkCollision.c b/test/Pong/test_checkCollision.c new file mode 100644 index 0000000..16be1ca --- /dev/null +++ b/test/Pong/test_checkCollision.c @@ -0,0 +1,63 @@ +#ifdef TEST +#include "unity.h" +#include "pong.h" +#define WIDTH 40 //Breite Spielfeld +#define HEIGHT 20 //Höhe Spielfeld + +typedef struct { + int x; + int y; + int speedX; + int speedY; +} Ball; + +typedef struct { + int x; + int y; + int width; + int height; +} Paddle; + +void setUp(void){ + //Wenn Funktion Vorraussetzungen braucht +} + +void tearDown(void){ +} + +void test_checkCollision(void){ + Ball ball = {10, 10, 1, 1}; + Paddle paddle = {50, 10, 5, 10}; + + // Test Ball trifft rechte und linke Wand + ball.x = 0; + int result1 = checkCollision(ball, paddle.y, paddle.y); + TEST_ASSERT_EQUAL_INT(1, result1); + + ball.x = WIDTH - 1; + int result2 = checkCollision(ball, paddle.y, paddle.y); + TEST_ASSERT_EQUAL_INT(2, result2); + + // Test Ball trifft obere und untere Wand + ball.x = 5; + ball.y = 0; + int result3 = checkCollision(ball, paddle.y, paddle.y); + TEST_ASSERT_EQUAL_INT(0, result3); + + ball.y = HEIGHT - 1; + int result4 = checkCollision(ball, paddle.y, paddle.y); + TEST_ASSERT_EQUAL_INT(0, result4); + + // Test wenn Ball Paddle trifft + ball.x = paddle.x - 1; + ball.y = paddle.y + 1; + int result5 = checkCollision(ball, paddle.y, paddle.y); + TEST_ASSERT_EQUAL_INT(2, result5); + + ball.x = paddle.x + 1; + ball.y = paddle.y + 1; + int result6 = checkCollision(ball, paddle.y, paddle.y); + TEST_ASSERT_EQUAL_INT(2, result6); +} + +#endif // TEST diff --git a/test/Pong/test_checkGameEnd.c b/test/Pong/test_checkGameEnd.c new file mode 100644 index 0000000..4f9144d --- /dev/null +++ b/test/Pong/test_checkGameEnd.c @@ -0,0 +1,34 @@ +#ifdef TEST +#include "unity.h" +#include "pong.h" + +// Prüfen Spiellogik für Beenden des Spiels + +void setUp(void){ + //Wenn Funktion Vorraussetzungen braucht +} + +void tearDown(void){ +} + +void test_checkGameEnd(void){ + /* arrange */ + int maxScore = 5; + int score1 = 4, score2 = 2; + + /* act */ + int result = checkGameEnd(score1, score2, maxScore); + + /* assert */ + TEST_ASSERT_EQUAL_INT(0, result); // Das Spiel sollte noch nicht enden + + /* Spieler 1 erreicht den Maximalscore */ + score1 = 5; + result = checkGameEnd(score1, score2, maxScore); + TEST_ASSERT_EQUAL_INT(1, result); // Das Spiel sollte enden, da Spieler 1 den Maximalscore erreicht hat + + /* Weitere Tests mit anderen Spiellogikfällen und Endspielbedingungen können hinzugefügt werden */ + +} + +#endif // TEST diff --git a/test/Pong/test_clearScreen.c b/test/Pong/test_clearScreen.c new file mode 100644 index 0000000..f2701a1 --- /dev/null +++ b/test/Pong/test_clearScreen.c @@ -0,0 +1,38 @@ +#ifdef TEST +#include "unity.h" +#include "pong.h" + +#define TEST_SCREEN_WIDTH 40 +#define TEST_SCREEN_HEIGHT 20 + +char screen[TEST_SCREEN_HEIGHT][TEST_SCREEN_WIDTH+1]; + +void setUp(void){ + //Wenn Funktion Vorraussetzungen braucht +} + +void tearDown(void){ +} + +void test_clearScreen(void){ + /* arrange */ + int i, j; + for (i = 0; i < TEST_SCREEN_HEIGHT; i++) { + for (j = 0; j < TEST_SCREEN_WIDTH; j++) { + screen[i][j] = ' '; + } + screen[i][j] = '\0'; + } + + /* act */ + clearScreen(); + + /* assert */ + for (i = 0; i < TEST_SCREEN_HEIGHT; i++) { + for (j = 0; j < TEST_SCREEN_WIDTH; j++) { + TEST_ASSERT_EQUAL_INT(' ', screen[i][j]); + } + } +} + +#endif // TEST diff --git a/test/Pong/test_playerInputMovement.c b/test/Pong/test_playerInputMovement.c new file mode 100644 index 0000000..e8ebbdd --- /dev/null +++ b/test/Pong/test_playerInputMovement.c @@ -0,0 +1,42 @@ +#ifdef TEST +#include "unity.h" +#include "pong.h" + +typedef struct { + int x; + int y; + int speedX; + int speedY; +} Paddle; +// sicherstellen korrekte Funktion Steuerung für Schläger + +void setUp(void){ + //Wenn Funktion Vorraussetzungen braucht +} + +void tearDown(void){ +} + +void test_playerInputMovement(void){ + /* Test 1: Bewegung nach oben */ + int paddlePositionY = 10; + int userInput = -1; // Benutzereingabe für Bewegung nach oben + int expectedY = paddlePositionY - 1; + + processPlayerInput(&paddlePositionY, userInput); + TEST_ASSERT_EQUAL_INT(expectedY, paddlePositionY); + + /* Test 2: Bewegung nach unten */ + userInput = 1; + expectedY = paddlePositionY + 1; + // Benutzereingabe für Bewegung nach unten + + processPlayerInput(&paddlePositionY, userInput); + TEST_ASSERT_EQUAL_INT(expectedY, paddlePositionY); + + /* Weitere Tests mit anderen Bewegungsrichtungen und Grenzfällen können hinzugefügt werden */ + +} + + +#endif // TEST diff --git a/test/Pong/test_pong.c b/test/Pong/test_pong.c new file mode 100644 index 0000000..0b12481 --- /dev/null +++ b/test/Pong/test_pong.c @@ -0,0 +1,27 @@ +#ifdef TEST +#include "unity.h" +#include "pong.h" + + +void setUp(void){ + //Wenn Funktion Vorraussetzungen braucht +} +void tearDown(void){ +} + + +void test_input_all_5(void){ + /* arrange */ + int a = 4, b = 5; + + /* act */ + resetScore( &a, &b ); + + /* assert */ + TEST_ASSERT_EQUAL_INT(0, a); + TEST_ASSERT_EQUAL_INT(0, b); +} + + + +#endif // TEST diff --git a/test/Snake/test_collision.c b/test/Snake/test_collision.c new file mode 100644 index 0000000..df400b0 --- /dev/null +++ b/test/Snake/test_collision.c @@ -0,0 +1,50 @@ +#ifdef TEST +#include "unity.h" +#include +#include "snake_start.h" +#include "get_character.h" + + +void setUp(void){} +void tearDown(void){} + + +void test_self_collision(void){ + /* arrange */ + bool result; + Snake snake = {1, 5, {6 + 16 * 6, 6 + 16 * 7, 7 + 16 * 7, 7 + 16 * 6, 6 + 16 * 6}}; + + /* act */ + result = check_if_dead(&snake); + + /* assert */ + TEST_ASSERT_TRUE(result);//head collides with body +} + + +void test_no_collision(void){ + /* arrange */ + bool result; + Snake snake = initialize_snake(); + + /* act */ + result = check_if_dead(&snake); + + /* assert */ + TEST_ASSERT_FALSE(result);//head collides with body +} + + +void test_wall_collision(void){ + /* arrange */ + bool result; + Snake snake = {-1, 4, {0 + 16 * 6, 1 + 16 * 6, 2 + 16 * 6, 3 + 16 * 6}}; + + /* act */ + result = check_if_dead(&snake); + + /* assert */ + TEST_ASSERT_TRUE(result);//head collides with body +} + +#endif // TEST \ No newline at end of file diff --git a/test/Snake/test_moving_snake.c b/test/Snake/test_moving_snake.c new file mode 100644 index 0000000..115d55f --- /dev/null +++ b/test/Snake/test_moving_snake.c @@ -0,0 +1,69 @@ +#ifdef TEST +#include "unity.h" +#include +#include +#include "../../src/main/c/Snake/snake_start.h" +#include "../../src/main/c/Snake/get_character.h" + + +void setUp(void){} +void tearDown(void){} + + +void test_moving_right(void){ + /* arrange */ + bool result; + Snake snake = {1, 3, {8 + 16 * 6, 7 + 16 * 6, 6 + 16 * 6}}; + Snake expected = {1, 3, {9 + 16 * 6, 8 + 16 * 6, 7 + 16 * 6}}; + + /* act */ + move_snake(&snake); + result = memcmp(&snake, &expected, sizeof(Snake)) == 0; + + /* assert */ + TEST_ASSERT_TRUE(result); +} + +void test_moving_down(void){ + /* arrange */ + bool result; + Snake snake = {16, 3, {8 + 16 * 6, 7 + 16 * 6, 6 + 16 * 6}}; + Snake expected = {16, 3, {8 + 16 * 7, 8 + 16 * 6, 7 + 16 * 6}}; + + /* act */ + move_snake(&snake); + result = memcmp(&snake, &expected, sizeof(Snake)) == 0; + + /* assert */ + TEST_ASSERT_TRUE(result); +} + +void test_moving_left(void){ + /* arrange */ + bool result; + Snake snake = {-1, 3, {8 + 16 * 6, 7 + 16 * 6, 6 + 16 * 6}}; + Snake expected = {-1, 3, {7 + 16 * 6, 8 + 16 * 6, 7 + 16 * 6}}; + + /* act */ + move_snake(&snake); + result = memcmp(&snake, &expected, sizeof(Snake)) == 0; + + /* assert */ + TEST_ASSERT_TRUE(result); +} + +void test_moving_up(void){ + /* arrange */ + bool result; + Snake snake = {-16, 3, {8 + 16 * 6, 7 + 16 * 6, 6 + 16 * 6}}; + Snake expected = {-16, 3, {8 + 16 * 5, 8 + 16 * 6, 7 + 16 * 6}}; + + /* act */ + move_snake(&snake); + result = memcmp(&snake, &expected, sizeof(Snake)) == 0; + + /* assert */ + TEST_ASSERT_TRUE(result); +} + +#endif // TEST \ No newline at end of file diff --git a/test/Snake/test_part_of_snake.c b/test/Snake/test_part_of_snake.c new file mode 100644 index 0000000..95ce3bd --- /dev/null +++ b/test/Snake/test_part_of_snake.c @@ -0,0 +1,49 @@ +#ifdef TEST +#include "unity.h" +#include "../../src/main/c/Snake/snake_start.h" +#include "../../src/main/c/Snake/get_character.h" + + +void setUp(void){} +void tearDown(void){} + + +void test_find_head(void){ + /* arrange */ + int result; + Snake snake = initialize_snake(); + + /* act */ + result = part_of_snake(&snake, 8 * 16 + 8); + + /* assert */ + TEST_ASSERT_EQUAL_INT(0, result);//head is at 8/8 +} + + +void test_get_correct_index(void){ + /* arrange */ + int result; + Snake snake = initialize_snake(); + + /* act */ + result = part_of_snake(&snake, 8 * 16 + 6); + + /* assert */ + TEST_ASSERT_EQUAL_INT(2, result);//2. part ist at 6/8 +} + + +void test_snake_not_on_tile(void){ + /* arrange */ + int result; + Snake snake = initialize_snake(); + + /* act */ + result = part_of_snake(&snake, 6 * 16 + 6); + + /* assert */ + TEST_ASSERT_EQUAL_INT(-1, result);//-1 snake is not on 6/6 +} + +#endif // TEST \ No newline at end of file diff --git a/test/test_template.c b/test/test_template.c index a1b9ed4..4aba361 100644 --- a/test/test_template.c +++ b/test/test_template.c @@ -33,4 +33,4 @@ void test_ignore_rest_from_division(void){ TEST_ASSERT_EQUAL_INT(5, result);//5 / 6 + 5 = 5 } -#endif // TEST \ No newline at end of file +#endif // TEST diff --git a/test/test_tictactoe.c b/test/test_tictactoe.c new file mode 100644 index 0000000..887aad7 --- /dev/null +++ b/test/test_tictactoe.c @@ -0,0 +1,88 @@ + +#ifdef TEST +#include "unity.h" +#include "tictactoe.h" + + +void setUp(void){ + //Wenn Funktion Vorraussetzungen braucht +} +void tearDown(void){ + reset_board(); + displayBoard(); +} + + +void test_if_not_identical(void){ + /* arrange */ + char result; + char a = 'a', b = 'b', c = 'c'; + + result = checkLine(a, b, c); + + /* assert */ + TEST_ASSERT_EQUAL_CHAR(' ', result); +} + + +void test_if_identical(void){ + /* arrange */ + char result; + char a = 'a', b = 'a', c = 'a'; + + result = checkLine(a, b, c); + + /* assert */ + TEST_ASSERT_EQUAL_CHAR(a, result); +} + +void test_isValidMove_gueltigerZug(void) { + /* arrangieren */ + int result; + int choice = 5; + + /* handeln */ + result = isValidMove(choice); + + /* überprüfen */ + TEST_ASSERT_EQUAL_INT(1, result); +} + + +void test_checkWinner_vertikalerGewinner(void) { + /* arrangieren */ + char result; + + // Setze die Daten für einen vertikalen Gewinne + makeMove(1); + makeMove(2); + makeMove(4); + makeMove(3); + makeMove(7); + + /* handeln */ + result = checkWinner(); + + /* überprüfen */ + TEST_ASSERT_EQUAL_CHAR('O', result); +} + +void test_checkWinner_horizontalerGewinner(void) { + /* arrangieren */ + char result; + + //makeMove(1); + //makeMove(4); + //makeMove(2); + //makeMove(5); + //makeMove(3); + + /* handeln */ + result = checkWinner(); + + /* überprüfen */ + TEST_ASSERT_EQUAL_CHAR('X', result); + reset_board(); +} + +#endif // TEST