Browse Source

Test moving right

remotes/origin/David
David Moeller 11 months ago
parent
commit
8236082301
  1. 4
      src/main/c/Snake/snake_start.c
  2. 2
      src/main/c/Snake/snake_start.h
  3. 4
      test/Snake/test_collision.c
  4. 27
      test/Snake/test_moving_snake.c

4
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");

2
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

4
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);

27
test/Snake/test_moving_snake.c

@ -0,0 +1,27 @@
#ifdef TEST
#include "unity.h"
#include <stdbool.h>
#include <memory.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_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
Loading…
Cancel
Save