X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;ds=sidebyside;f=prioq-test.c;fp=prioq-test.c;h=56cfbc120f704f63e4ef18e939c361574fdf320f;hb=4de18a7015ed77eac277bee669d4c8d9dae60b89;hp=0000000000000000000000000000000000000000;hpb=c77f4231ed850b90b9b6f337727e19b63418426f;p=catta diff --git a/prioq-test.c b/prioq-test.c new file mode 100644 index 0000000..56cfbc1 --- /dev/null +++ b/prioq-test.c @@ -0,0 +1,55 @@ +#include +#include +#include + +#include "prioq.h" + +static gint compare(gpointer a, gpointer b) { + gint i = GPOINTER_TO_INT(a), j = GPOINTER_TO_INT(b); + + return i < j ? -1 : (i > j ? 1 : 0); +} + +static void rec(flxPrioQueueNode *n) { + if (!n) + return; + + if (n->parent) { + int a = GPOINTER_TO_INT(n->parent->data), b = GPOINTER_TO_INT(n->data); + if (a > b) { + printf("%i <= %i: NO\n", a, b); + abort(); + } + } + + rec(n->left); + rec(n->right); +} + +int main(int argc, char *argv[]) { + flxPrioQueue *q; + gint i, prev; + + q = flx_prio_queue_new(compare); + + srand(time(NULL)); + + flx_prio_queue_put(q, GINT_TO_POINTER(255)); + flx_prio_queue_put(q, GINT_TO_POINTER(255)); + + for (i = 0; i < 10000; i++) + flx_prio_queue_put(q, GINT_TO_POINTER(random() & 0xFFFF)); + + prev = 0; + while (q->root) { + gint v = GPOINTER_TO_INT(q->root->data); + rec(q->root); + printf("%i\n", v); + flx_prio_queue_remove(q, q->root); + g_assert(v >= prev); + prev = v; + } + + flx_prio_queue_free(q); + return 0; +}