libbubulle/tbb.c

212 lines
4.6 KiB
C
Raw Normal View History

/*
2018-11-24 22:46:53 +11:00
* this is rudimentary test for the bubulles manager
*
* contact: <tth> on IRC freenode#tetalab
*/
2018-11-10 21:31:31 +11:00
#include <stdio.h>
#include <stdlib.h>
2023-03-30 14:16:19 +11:00
#include <unistd.h>
2018-11-10 21:31:31 +11:00
#include "bubulles.h"
2023-03-26 21:44:34 +11:00
#include "edges.h"
2018-11-10 21:31:31 +11:00
2023-03-26 21:44:34 +11:00
/* --------------------------------------------------------------------- */
2023-03-27 09:03:54 +11:00
int essai_des_edges_A(int k)
2023-03-26 21:44:34 +11:00
{
EdgeList * list;
int foo, idx;
2023-03-27 09:03:54 +11:00
int e0, e1;
fprintf(stderr, "============== %s %7d ===========\n", __func__, k);
2023-03-26 21:44:34 +11:00
list = alloc_edgelist("oups?", k, 0);
fprintf(stderr, " alloc edge list -> %p\n", list);
print_edgelist_desc(list, 0);
foo = push_an_edge(list, 13, 37);
fprintf(stderr, " push edge -> %d\n", foo);
foo = push_an_edge(list, 24, 36);
2023-03-30 14:16:19 +11:00
fprintf(stderr, " push edge -> %d\n", foo);
2023-03-26 21:44:34 +11:00
2023-03-30 14:16:19 +11:00
foo = print_the_edges(stdout, list, 0);
2023-03-26 21:44:34 +11:00
2023-03-27 09:03:54 +11:00
for (idx=0; idx<k; idx++) {
e0 = idx*7; e1 = 5-idx;
foo = push_an_edge(list, e0, e1);
if (foo) {
2023-03-30 14:16:19 +11:00
fprintf(stderr, "push %d (%d, %d) -> %d\n", idx, e0, e1, foo);
2023-03-27 09:03:54 +11:00
break;
}
}
2023-03-26 21:44:34 +11:00
2023-03-30 14:16:19 +11:00
foo = print_the_edges(stdout, list, 0); puts("");
2023-03-26 21:44:34 +11:00
2023-03-27 09:03:54 +11:00
foo = free_edgelist(list, 0);
fprintf(stderr, " free list -> %d\n", foo);
return 0;
}
/* --------------------------------------------------------------------- */
/*
* ici on va faire des essais sur la gestion
* de la -duplication des aretes.
*/
int essai_des_edges_B(int k)
{
EdgeList * list;
int foo, idx;
int e0, e1;
fprintf(stderr, "============== %s %7d ===========\n", __func__, k);
2023-03-30 14:16:19 +11:00
list = alloc_edgelist("gloubigoulba", k, 0);
2023-03-27 09:03:54 +11:00
if (NULL == list) {
fprintf(stderr, "%s: epic fail\n", __func__);
abort();
}
print_edgelist_desc(list, 0);
for (idx=0; idx<k; idx++) {
e0 = rand() % 666;
e1 = rand() % 666;
foo = push_a_missing_edge(list, e0, e1);
2023-03-26 21:44:34 +11:00
}
2023-03-27 09:03:54 +11:00
print_edgelist_desc(list, 0);
2023-03-30 14:16:19 +11:00
foo = print_the_edges(stdout, list, 0); puts("");
2023-03-26 21:44:34 +11:00
foo = free_edgelist(list, 0);
2023-03-27 09:03:54 +11:00
fprintf(stderr, " %s: free list -> %d\n", __func__, foo);
2023-03-26 21:44:34 +11:00
return -1;
}
2023-03-27 09:03:54 +11:00
2018-11-10 21:31:31 +11:00
/* --------------------------------------------------------------------- */
2023-03-27 09:03:54 +11:00
2018-11-10 21:31:31 +11:00
void test_alloc_free(int nbelm)
{
BBList *bublist;
int foo;
bublist = alloc_bubulles("plop !", nbelm, 0);
if (NULL==bublist) {
fprintf(stderr, "err in %s, aborting...\n", __func__);
abort();
}
2018-11-10 21:31:31 +11:00
print_bublist_desc(bublist, 1);
foo = free_bubulles(bublist, 0);
2020-02-01 04:22:05 +11:00
fprintf(stderr, "free bubulles -> %d\n", foo);
2018-11-10 21:31:31 +11:00
}
/* --------------------------------------------------------------------- */
int test_push_pop(int nbelm)
{
BBList *bublist;
int foo, idx;
Bubulle bubulle;
bublist = alloc_bubulles("push & pop", nbelm, 0);
for (idx=0; idx<nbelm; idx++) {
bubulle.p.x = (double)idx;
2020-02-01 04:22:05 +11:00
if (idx & 0xf0)
bubulle.p.y = bubulle.p.z = 0.3;
else
bubulle.p.y = bubulle.p.z = 0.8;
2018-11-10 21:31:31 +11:00
foo = push_bubulle(bublist, &bubulle);
}
/* WTF ? where is the 'pop' test ? */
2018-11-10 21:31:31 +11:00
foo = bubulles_to_data("dummy-file", NULL, bublist, 0);
2020-02-01 04:22:05 +11:00
fprintf(stderr, "ecriture bubulles -> %d\n", foo);
2018-11-10 21:31:31 +11:00
foo = free_bubulles(bublist, 0);
2020-02-01 04:22:05 +11:00
fprintf(stderr, "free bubulles -> %d\n", foo);
2018-11-10 21:31:31 +11:00
return 0;
}
/* --------------------------------------------------------------------- */
int test_cleanfill_my_bublist(int krkrkr)
{
BBList *bublist;
int foo;
bublist = alloc_bubulles("cleanfill", 567890, 0);
foo = cleanfill_my_bublist(bublist, 0);
fprintf(stderr, "clean & fill -> %d\n", foo);
free_bubulles(bublist, 0);
return 0;
}
/* --------------------------------------------------------------------- */
int test_peek_poke(int nbre)
{
BBList *bublist;
int foo, in, out;
Bubulle bubulle;
bublist = alloc_bubulles("peek & poke", nbre, 0);
print_bublist_desc(bublist, 0);
in = nbre / 2;
out = nbre + 42;
foo = peek_bubulle(bublist, &bubulle, in);
2020-02-01 04:22:05 +11:00
fprintf(stderr, "peek 1 -> %7d\n", foo);
2018-11-10 21:31:31 +11:00
foo = niceprint_bubulle(&bubulle, 0);
2020-02-01 04:38:18 +11:00
if (foo) fprintf(stderr, "niceprint -> %d\n", foo);
2018-11-10 21:31:31 +11:00
foo = peek_bubulle(bublist, &bubulle, out);
2020-02-01 04:22:05 +11:00
fprintf(stderr, "peek 2 -> %7d\n", foo);
2018-11-10 21:31:31 +11:00
bubulle.p.y = 3.14159;
foo = poke_bubulle(bublist, &bubulle, in);
2020-02-01 04:22:05 +11:00
fprintf(stderr, "poke 2 -> %7d\n", foo);
2018-11-10 21:31:31 +11:00
foo = peek_bubulle(bublist, &bubulle, in);
2020-02-01 04:22:05 +11:00
fprintf(stderr, "peek 3 -> %7d\n", foo);
2018-11-10 21:31:31 +11:00
foo = niceprint_bubulle(&bubulle, 0);
2020-02-01 04:38:18 +11:00
if (foo) fprintf(stderr, "niceprint -> %d\n", foo);
2018-11-10 21:31:31 +11:00
2018-11-16 23:18:30 +11:00
free_bubulles(bublist, 0);
return 0;
2018-11-10 21:31:31 +11:00
}
/* --------------------------------------------------------------------- */
int main(int argc, char *argv[])
{
int foo;
2023-05-01 22:09:01 +11:00
fprintf(stderr, "***\n*** Bubulles Testing %s %s\n***\n",
__DATE__, __TIME__);
2018-11-13 23:20:35 +11:00
2023-03-26 21:44:34 +11:00
bubulles_version(0);
2018-11-10 21:31:31 +11:00
2023-03-30 14:16:19 +11:00
srand(getpid()); /* INIT RANDOM */
2023-03-26 21:44:34 +11:00
#if (0)
2018-11-13 23:20:35 +11:00
test_alloc_free(5);
2018-11-25 21:44:42 +11:00
test_push_pop(20000);
2018-11-13 23:20:35 +11:00
test_cleanfill_my_bublist(999);
2018-11-10 21:31:31 +11:00
foo = test_peek_poke(5000);
fprintf(stderr, "test peek/poke -> %d\n", foo);
2023-03-26 21:44:34 +11:00
#endif
2023-05-01 22:09:01 +11:00
foo = essai_des_edges_A(25);
fprintf(stderr, "test A des edges -> %d\n", foo);
2023-03-30 14:16:19 +11:00
foo = essai_des_edges_B(5000);
2023-03-27 09:03:54 +11:00
fprintf(stderr, "test B des edges -> %d\n", foo);
2018-11-16 23:18:30 +11:00
2018-11-10 21:31:31 +11:00
return 0;
}