j
This commit is contained in:
		
							parent
							
								
									047b46a41b
								
							
						
					
					
						commit
						f1eb22c901
					
				
							
								
								
									
										23
									
								
								cv9/snake.c
									
									
									
									
									
								
							
							
						
						
									
										23
									
								
								cv9/snake.c
									
									
									
									
									
								
							| @ -22,6 +22,29 @@ struct snake* remove_snake(struct snake* snake) { | |||||||
|     free(snake); |     free(snake); | ||||||
|     return new_head; |     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) { | int is_snake(struct snake* snake, int x, int y) { | ||||||
|     while (snake != NULL) { |     while (snake != NULL) { | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user