@@ -345,6 +345,36 @@ void test_list_node_pushback_and_remove(void)
345345 ASSERT_TEST(list_is_empty(list), "Empty list check ");
346346}
347347
348+ /* Test 12: List helpers behavior */
349+ void test_list_pushback_and_remove(void)
350+ {
351+ list_t *list = list_create();
352+
353+ int node1 = 1;
354+ int node2 = 2;
355+
356+ /* Check node push back normally - unlinked and linked */
357+ list_pushback(list, &node1);
358+ ASSERT_TEST(list->length == 1 && *(int *) (list->head->next->data) == 1,
359+ "Data push back into a new list ");
360+
361+ list_pushback(list, &node2);
362+ ASSERT_TEST(
363+ list->length == 2 && *(int *) (list->head->next->next->data) == 2,
364+ "Second data pushback successful ");
365+
366+ /* Remove last node */
367+ list_remove(list, list->head->next);
368+ ASSERT_TEST(list->length == 1 && *(int *) (list->head->next->data) == 2,
369+ "Remove first data ");
370+
371+ /* Remove non-existing node (second time) */
372+ list_remove(list, list->head->next);
373+ ASSERT_TEST(list->length == 0, "Unlinked node pushback success ");
374+
375+ ASSERT_TEST(list_is_empty(list), "Empty list check ");
376+ }
377+
348378void test_runner(void)
349379{
350380 printf("\n=== LibC Test Suite ===\n");
@@ -364,6 +394,7 @@ void test_runner(void)
364394
365395 printf("\n=== List Test Suite ===\n");
366396 test_list_node_pushback_and_remove();
397+ test_list_pushback_and_remove();
367398
368399 printf("\n=== Test Summary ===\n");
369400 printf("Tests run: %d\n", tests_run);
0 commit comments