From f1eb22c9018ba3dab5a684dd98cd64591e93e701 Mon Sep 17 00:00:00 2001 From: Mykyta Sadchenko Date: Thu, 18 Apr 2024 08:16:00 +0200 Subject: [PATCH] j --- cv9/snake.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) 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) {