Browse Source

Test part_of_snake

remotes/origin/David
David Moeller 11 months ago
parent
commit
d285bcc413
  1. 18
      src/main/c/Snake/snake_start.c
  2. 14
      src/main/c/Snake/snake_start.h
  3. 38
      test/Snake/test_part_of_snake.c

18
src/main/c/Snake/snake_start.c

@ -1,21 +1,11 @@
#include <stdio.h> #include <stdio.h>
#include <stdbool.h> #include <stdbool.h>
#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 main_menu();
void game(); void game();
Snake initialize_game();
Snake initialize_snake();
void draw(Snake *snake); void draw(Snake *snake);
int part_of_snake(Snake *snake, unsigned char tile); int part_of_snake(Snake *snake, unsigned char tile);
@ -55,7 +45,7 @@ void main_menu(){
} }
void game(){ void game(){
Snake snake = initialize_game();
Snake snake = initialize_snake();
bool running = true; bool running = true;
while (running) while (running)
{ {
@ -66,7 +56,7 @@ void game(){
getchar(); getchar();
} }
Snake initialize_game(){
Snake initialize_snake(){
Snake snake = {{0, 1}, 3}; Snake snake = {{0, 1}, 3};
for(int i = 0; i < AREA; i++){ for(int i = 0; i < AREA; i++){
snake.segments[i] = 0; snake.segments[i] = 0;

14
src/main/c/Snake/snake_start.h

@ -1,6 +1,20 @@
#ifndef SNAKE_START_H #ifndef SNAKE_START_H
#define 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(); void snake_start();
Snake initialize_snake();
int part_of_snake(Snake *snake, unsigned char tile);
#endif // SNAKE_START_H #endif // SNAKE_START_H

38
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
Loading…
Cancel
Save