forked from enlightenment/efl
tests: improve eina_test_list_shuffle
reduce iteratons by a hundredfold, remove verifying of rand() seed, check whether shuffle actually shuffles fix T6833 Reviewed-by: Stefan Schmidt <stefan@osg.samsung.com>
This commit is contained in:
parent
8ca6102f62
commit
11d695cfcd
|
@ -389,61 +389,36 @@ EFL_START_TEST(eina_test_list_split)
|
|||
}
|
||||
EFL_END_TEST
|
||||
|
||||
static int uicmp(const void *d1, const void *d2)
|
||||
{
|
||||
const unsigned int *a = d1;
|
||||
const unsigned int *b = d2;
|
||||
|
||||
if(*a == *b) return 0;
|
||||
if(*a > *b) return 1;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
#define SHUFFLE_SZ 100
|
||||
#define SHUFFLE_N 100000
|
||||
#define SHUFFLE_N 5
|
||||
EFL_START_TEST(eina_test_list_shuffle)
|
||||
{
|
||||
double d;
|
||||
unsigned int *p;
|
||||
unsigned int i, j;
|
||||
unsigned int i;
|
||||
unsigned int n[SHUFFLE_SZ];
|
||||
unsigned int rand_count[SHUFFLE_SZ];
|
||||
Eina_List *list = NULL;
|
||||
Eina_List *item = NULL;
|
||||
Eina_List *copy, *cl;
|
||||
|
||||
|
||||
for(i = 0; i < SHUFFLE_SZ; i++)
|
||||
{
|
||||
n[i] = i;
|
||||
rand_count[i] = 0;
|
||||
list = eina_list_append(list, &n[i]);
|
||||
}
|
||||
copy = eina_list_clone(list);
|
||||
|
||||
for(i = 0; i < SHUFFLE_N; i++)
|
||||
{
|
||||
list = eina_list_shuffle(list, NULL);
|
||||
p = eina_list_nth(list, SHUFFLE_SZ/2);
|
||||
rand_count[*p]++;
|
||||
|
||||
j = 0;
|
||||
list = eina_list_sort(list, 0, (Eina_Compare_Cb)&uicmp);
|
||||
cl = eina_list_data_get(copy);
|
||||
EINA_LIST_FOREACH(list, item, p)
|
||||
{
|
||||
if (*p != j++)
|
||||
fail_if(*p != j++);
|
||||
if (eina_list_data_get(cl) != p) break;
|
||||
cl = eina_list_next(cl);
|
||||
}
|
||||
if (j != SHUFFLE_SZ)
|
||||
fail_if(j != SHUFFLE_SZ);
|
||||
ck_assert_ptr_nonnull(item);
|
||||
}
|
||||
|
||||
d = SHUFFLE_SZ/(float)(SHUFFLE_N);
|
||||
for(i = 0; i < SHUFFLE_SZ; i++)
|
||||
{
|
||||
fail_if(rand_count[i]*d > 1.20f);
|
||||
fail_if(rand_count[i]*d < 0.80f);
|
||||
}
|
||||
|
||||
}
|
||||
EFL_END_TEST
|
||||
|
||||
|
|
Loading…
Reference in New Issue