diff --git a/cv9/snake.c b/cv9/snake.c index b6eec75..e8a3cf6 100644 --- a/cv9/snake.c +++ b/cv9/snake.c @@ -22,6 +22,29 @@ struct snake* remove_snake(struct snake* snake) { free(snake); return new_head; } +void test_remove_snake_non_empty() { + + struct snake* tail = calloc(1, sizeof(struct snake)); + tail->x = 3; + tail->y = 3; + struct snake* head = calloc(1, sizeof(struct snake)); + head->x = 2; + head->y = 2; + head->next = tail; + + + struct snake* new_head = remove_snake(head); + + + if (new_head != NULL && new_head->x == 3) { + printf("Test passed: new head coordinates are correct.\n"); + } else { + printf("Test failed: new head coordinates are incorrect.\n"); + } + + + free(new_head); +} int is_snake(struct snake* snake, int x, int y) { while (snake != NULL) {