From 82360823017c7513101c9e85b4da0f04c034d83a Mon Sep 17 00:00:00 2001 From: David Moeller Date: Thu, 25 Jan 2024 10:44:08 +0100 Subject: [PATCH] Test moving right --- src/main/c/Snake/snake_start.c | 4 ++-- src/main/c/Snake/snake_start.h | 2 ++ test/Snake/test_collision.c | 4 ++-- test/Snake/test_moving_snake.c | 27 +++++++++++++++++++++++++++ 4 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 test/Snake/test_moving_snake.c diff --git a/src/main/c/Snake/snake_start.c b/src/main/c/Snake/snake_start.c index 70bc96e..12fb3d5 100644 --- a/src/main/c/Snake/snake_start.c +++ b/src/main/c/Snake/snake_start.c @@ -7,7 +7,7 @@ #include "get_character.h" #define TIME_TURN 0.3 - +#pragma region Funktion_heads void main_menu(); void game(); Snake initialize_snake(); @@ -18,7 +18,7 @@ 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 void snake_start(){ system("clear"); diff --git a/src/main/c/Snake/snake_start.h b/src/main/c/Snake/snake_start.h index 9240626..1634146 100644 --- a/src/main/c/Snake/snake_start.h +++ b/src/main/c/Snake/snake_start.h @@ -15,6 +15,8 @@ typedef struct{ 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/test/Snake/test_collision.c b/test/Snake/test_collision.c index b70676d..e5d5a63 100644 --- a/test/Snake/test_collision.c +++ b/test/Snake/test_collision.c @@ -12,7 +12,7 @@ void tearDown(void){} void test_self_collision(void){ /* arrange */ bool result; - Snake snake = {{1, 0}, 5, {6 + 16 * 6, 6 + 16 * 7, 7 + 16 * 7, 7 + 16 * 6, 6 + 16 * 6}}; + 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); @@ -38,7 +38,7 @@ void test_no_collision(void){ void test_wall_collision(void){ /* arrange */ bool result; - Snake snake = {{1, 0}, 4, {0 + 16 * 6, 1 + 16 * 6, 2 + 16 * 6, 3 + 16 * 6}}; + Snake snake = {-1, 4, {0 + 16 * 6, 1 + 16 * 6, 2 + 16 * 6, 3 + 16 * 6}}; /* act */ result = check_if_dead(&snake); diff --git a/test/Snake/test_moving_snake.c b/test/Snake/test_moving_snake.c new file mode 100644 index 0000000..b098f9e --- /dev/null +++ b/test/Snake/test_moving_snake.c @@ -0,0 +1,27 @@ +#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);//head collides with body +} + +#endif // TEST \ No newline at end of file