From d285bcc4135350edbcaa31a3674fef23e04ce4f3 Mon Sep 17 00:00:00 2001 From: David Moeller Date: Sun, 21 Jan 2024 13:48:58 +0100 Subject: [PATCH] Test part_of_snake --- src/main/c/Snake/snake_start.c | 18 ++++------------ src/main/c/Snake/snake_start.h | 14 ++++++++++++ test/Snake/test_part_of_snake.c | 38 +++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 14 deletions(-) create mode 100644 test/Snake/test_part_of_snake.c diff --git a/src/main/c/Snake/snake_start.c b/src/main/c/Snake/snake_start.c index efcd08b..86f0204 100644 --- a/src/main/c/Snake/snake_start.c +++ b/src/main/c/Snake/snake_start.c @@ -1,21 +1,11 @@ #include #include - - -#define HEIGHT 15 -#define WIDTH 15 -#define AREA HEIGHT * WIDTH - -typedef struct{ - signed char direction[2]; - char length; - unsigned char segments[AREA]; -}Snake; +#include "snake_start.h" void main_menu(); void game(); -Snake initialize_game(); +Snake initialize_snake(); void draw(Snake *snake); int part_of_snake(Snake *snake, unsigned char tile); @@ -55,7 +45,7 @@ void main_menu(){ } void game(){ - Snake snake = initialize_game(); + Snake snake = initialize_snake(); bool running = true; while (running) { @@ -66,7 +56,7 @@ void game(){ getchar(); } -Snake initialize_game(){ +Snake initialize_snake(){ Snake snake = {{0, 1}, 3}; for(int i = 0; i < AREA; i++){ snake.segments[i] = 0; diff --git a/src/main/c/Snake/snake_start.h b/src/main/c/Snake/snake_start.h index 423f324..87a4e1c 100644 --- a/src/main/c/Snake/snake_start.h +++ b/src/main/c/Snake/snake_start.h @@ -1,6 +1,20 @@ #ifndef SNAKE_START_H #define SNAKE_START_H +#define HEIGHT 15 +#define WIDTH 15 +#define AREA HEIGHT * WIDTH + +typedef struct{ + signed char direction[2]; + char length; + unsigned char segments[AREA]; +}Snake; + + void snake_start(); +Snake initialize_snake(); +int part_of_snake(Snake *snake, unsigned char tile); + #endif // SNAKE_START_H \ 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..5dfad8b --- /dev/null +++ b/test/Snake/test_part_of_snake.c @@ -0,0 +1,38 @@ +#ifdef TEST +#include "unity.h" +#include "../../src/main/c/Snake/snake_start.h" + + +void setUp(void){ + //Wenn Funktion Vorraussetzungen braucht +} +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 +} + +#endif // TEST \ No newline at end of file