+
+/* --- variables --- */
+static gint test_nums[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
+static gint more_nums[10] = { 8, 9, 7, 0, 3, 2, 5, 1, 4, 6};
+
+/* --- functions --- */
+static gint
+my_list_compare_one (gconstpointer a, gconstpointer b)
+{
+ gint one = *((const gint*)a);
+ gint two = *((const gint*)b);
+ return one-two;
+}
+
+static gint
+my_list_compare_two (gconstpointer a, gconstpointer b)
+{
+ gint one = *((const gint*)a);
+ gint two = *((const gint*)b);
+ return two-one;
+}
+
+/* static void
+my_list_print (gpointer a, gpointer b)
+{
+ gint three = *((gint*)a);
+ g_print("%d", three);
+}; */
+
+static void
+glist_test (void)
+{
+ GList *list = NULL;
+ guint i;
+
+ for (i = 0; i < 10; i++)
+ list = g_list_append (list, &test_nums[i]);
+ list = g_list_reverse (list);
+
+ for (i = 0; i < 10; i++)
+ {
+ GList *t = g_list_nth (list, i);
+ if (*((gint*) t->data) != (9 - i))
+ g_error ("Regular insert failed");
+ }
+
+ for (i = 0; i < 10; i++)
+ if (g_list_position (list, g_list_nth (list, i)) != i)
+ g_error ("g_list_position does not seem to be the inverse of g_list_nth\n");
+
+ g_list_free (list);
+ list = NULL;
+
+ for (i = 0; i < 10; i++)
+ list = g_list_insert_sorted (list, &more_nums[i], my_list_compare_one);
+
+ /*
+ g_print("\n");
+ g_list_foreach (list, my_list_print, NULL);
+ */
+
+ for (i = 0; i < 10; i++)
+ {
+ GList *t = g_list_nth (list, i);
+ if (*((gint*) t->data) != i)
+ g_error ("Sorted insert failed");
+ }
+
+ g_list_free (list);
+ list = NULL;
+
+ for (i = 0; i < 10; i++)
+ list = g_list_insert_sorted (list, &more_nums[i], my_list_compare_two);
+
+ /*
+ g_print("\n");
+ g_list_foreach (list, my_list_print, NULL);
+ */
+
+ for (i = 0; i < 10; i++)
+ {
+ GList *t = g_list_nth (list, i);
+ if (*((gint*) t->data) != (9 - i))
+ g_error ("Sorted insert failed");
+ }
+
+ g_list_free (list);
+ list = NULL;
+
+ for (i = 0; i < 10; i++)
+ list = g_list_prepend (list, &more_nums[i]);
+
+ list = g_list_sort (list, my_list_compare_two);
+
+ /*
+ g_print("\n");
+ g_list_foreach (list, my_list_print, NULL);
+ */
+
+ for (i = 0; i < 10; i++)
+ {
+ GList *t = g_list_nth (list, i);
+ if (*((gint*) t->data) != (9 - i))
+ g_error ("Merge sort failed");
+ }
+
+ g_list_free (list);
+}
+
+static void
+gslist_test (void)
+{
+ GSList *slist = NULL;
+ guint i;
+
+ for (i = 0; i < 10; i++)
+ slist = g_slist_append (slist, &test_nums[i]);
+ slist = g_slist_reverse (slist);
+
+ for (i = 0; i < 10; i++)
+ {
+ GSList *st = g_slist_nth (slist, i);
+ if (*((gint*) st->data) != (9 - i))
+ g_error ("failed");
+ }
+
+ g_slist_free (slist);
+ slist = NULL;
+
+ for (i = 0; i < 10; i++)
+ slist = g_slist_insert_sorted (slist, &more_nums[i], my_list_compare_one);
+
+ /*
+ g_print("\n");
+ g_slist_foreach (slist, my_list_print, NULL);
+ */
+
+ for (i = 0; i < 10; i++)
+ {
+ GSList *st = g_slist_nth (slist, i);
+ if (*((gint*) st->data) != i)
+ g_error ("Sorted insert failed");
+ }
+
+ g_slist_free (slist);
+ slist = NULL;
+
+ for (i = 0; i < 10; i++)
+ slist = g_slist_insert_sorted (slist, &more_nums[i], my_list_compare_two);
+
+ /*
+ g_print("\n");
+ g_slist_foreach (slist, my_list_print, NULL);
+ */
+
+ for (i = 0; i < 10; i++)
+ {
+ GSList *st = g_slist_nth (slist, i);
+ if (*((gint*) st->data) != (9 - i))
+ g_error("Sorted insert failed");
+ }
+
+ g_slist_free(slist);
+ slist = NULL;
+
+ for (i = 0; i < 10; i++)
+ slist = g_slist_prepend (slist, &more_nums[i]);
+
+ slist = g_slist_sort (slist, my_list_compare_two);
+
+ /*
+ g_print("\n");
+ g_slist_foreach (slist, my_list_print, NULL);
+ */
+
+ for (i = 0; i < 10; i++)
+ {
+ GSList *st = g_slist_nth (slist, i);
+ if (*((gint*) st->data) != (9 - i))
+ g_error("Sorted insert failed");
+ }
+
+ g_slist_free(slist);
+}
+