mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-24 13:06:14 +01:00
gqsort: Move test to glib/tests/
Previously tests existed in two places, `$top_srcdir/tests/qsort-test.c` contained a similar test to the one in `$top_srcdir/glib/tests/sort.c` called `test_sort_basic()` The test for checking with zero elements was additional added to `$top_srcdir/glib/tests/sort.c` and `$top_srcdir/tests/qsort-test.c` was deleted. Related to: #1434
This commit is contained in:
parent
64961b5420
commit
279a610018
@ -46,6 +46,30 @@ test_sort_basic (void)
|
||||
g_free (data);
|
||||
}
|
||||
|
||||
static void
|
||||
test_sort_zero_elements (void)
|
||||
{
|
||||
gint *data, *data_copy;
|
||||
gsize i;
|
||||
|
||||
data = g_malloc (100 * sizeof (int));
|
||||
data_copy = g_malloc (100 * sizeof (int));
|
||||
for (i = 0; i < 100; i++)
|
||||
{
|
||||
data[i] = g_random_int ();
|
||||
data_copy[i] = data[i];
|
||||
}
|
||||
|
||||
/* 0 elements is a valid case */
|
||||
g_qsort_with_data (data, 0, sizeof (int), int_compare_data, NULL);
|
||||
|
||||
for (i = 0; i < 100; i++)
|
||||
g_assert_cmpint (data[i], ==, data_copy[i]);
|
||||
|
||||
g_free (data);
|
||||
g_free (data_copy);
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
int val;
|
||||
int i;
|
||||
@ -120,6 +144,7 @@ main (int argc, char *argv[])
|
||||
g_test_init (&argc, &argv, NULL);
|
||||
|
||||
g_test_add_func ("/sort/basic", test_sort_basic);
|
||||
g_test_add_func ("/sort/zero-elements", test_sort_zero_elements);
|
||||
g_test_add_func ("/sort/stable", test_sort_stable);
|
||||
g_test_add_func ("/sort/big", test_sort_big);
|
||||
|
||||
|
@ -30,7 +30,6 @@ tests = {
|
||||
'mapping-test' : {},
|
||||
'onceinit' : {},
|
||||
'asyncqueue-test' : {},
|
||||
'qsort-test' : {},
|
||||
'relation-test' : {},
|
||||
'slice-concurrent' : {},
|
||||
'slice-threadinit' : {
|
||||
|
@ -1,33 +0,0 @@
|
||||
#undef G_DISABLE_ASSERT
|
||||
#undef G_LOG_DOMAIN
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#define SIZE 100000
|
||||
|
||||
guint32 array[SIZE];
|
||||
|
||||
static gint
|
||||
sort (gconstpointer a, gconstpointer b, gpointer user_data)
|
||||
{
|
||||
return *(guint32*)a < *(guint32*)b ? -1 : 1;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < SIZE; i++)
|
||||
array[i] = g_random_int ();
|
||||
|
||||
g_qsort_with_data (array, SIZE, sizeof (guint32), sort, NULL);
|
||||
|
||||
for (i = 0; i < SIZE - 1; i++)
|
||||
g_assert (array[i] <= array[i+1]);
|
||||
|
||||
/* 0 elements is a valid case */
|
||||
g_qsort_with_data (array, 0, sizeof (guint32), sort, NULL);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user