2007-10-19 Nagappan A <anagappan@novell.com>
[mono.git] / eglib / test / list.c
index 46be8c4484a91e4ec3bececedba42c32f71c4aa2..9558781be63b70ebc9fa56c61c74f07bab98798b 100644 (file)
@@ -306,20 +306,22 @@ test_list_insert_before ()
        return OK;
 }
 
-#define N_ELEMS 100
+#define N_ELEMS 101
 
 static int intcompare (gconstpointer p1, gconstpointer p2)
 {
        return GPOINTER_TO_INT (p1) - GPOINTER_TO_INT (p2);
 }
 
-static gboolean verify_sort (GList *list)
+static gboolean verify_sort (GList *list, int len)
 {
-       list = g_list_sort (list, intcompare);
+       int prev;
+
        if (list->prev)
                return FALSE;
 
-       int prev = GPOINTER_TO_INT (list->data);
+       prev = GPOINTER_TO_INT (list->data);
+       len--;
        for (list = list->next; list; list = list->next) {
                int curr = GPOINTER_TO_INT (list->data);
                if (prev > curr)
@@ -328,19 +330,24 @@ static gboolean verify_sort (GList *list)
 
                if (!list->prev || list->prev->next != list)
                        return FALSE;
+
+               if (len == 0)
+                       return FALSE;
+               len--;
        }
-       return TRUE;
+       return len == 0;
 }
 
 RESULT
 test_list_sort ()
 {
-       int i = 0;
+       int i, j, mul;
        GList *list = NULL;
 
        for (i = 0; i < N_ELEMS; ++i)
                list = g_list_prepend (list, GINT_TO_POINTER (i));
-       if (!verify_sort (list))
+       list = g_list_sort (list, intcompare);
+       if (!verify_sort (list, N_ELEMS))
                return FAILED ("decreasing list");
 
        g_list_free (list);
@@ -348,20 +355,33 @@ test_list_sort ()
        list = NULL;
        for (i = 0; i < N_ELEMS; ++i)
                list = g_list_prepend (list, GINT_TO_POINTER (-i));
-       if (!verify_sort (list))
+       list = g_list_sort (list, intcompare);
+       if (!verify_sort (list, N_ELEMS))
                return FAILED ("increasing list");
 
        g_list_free (list);
 
+       list = g_list_prepend (NULL, GINT_TO_POINTER (0));
+       for (i = 1; i < N_ELEMS; ++i) {
+               list = g_list_prepend (list, GINT_TO_POINTER (i));
+               list = g_list_prepend (list, GINT_TO_POINTER (-i));
+       }
+       list = g_list_sort (list, intcompare);
+       if (!verify_sort (list, 2*N_ELEMS-1))
+               return FAILED ("alternating list");
+
+       g_list_free (list);
+
        list = NULL;
-       int mul = 1;
-       for (i = 0; i < N_ELEMS; ++i) {
-               list = g_list_prepend (list, GINT_TO_POINTER (mul * i));
+       mul = 1;
+       for (i = 1; i < N_ELEMS; ++i) {
                mul = -mul;
+               for (j = 0; j < i; ++j)
+                       list = g_list_prepend (list, GINT_TO_POINTER (mul * j));
        }
-
-       if (!verify_sort (list))
-               return FAILED ("alternating list");
+       list = g_list_sort (list, intcompare);
+       if (!verify_sort (list, (N_ELEMS*N_ELEMS - N_ELEMS)/2))
+               return FAILED ("wavering list");
 
        g_list_free (list);