X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/0f5e8daaa6e9f74521068aa75837200bcd182ea6..45f880d271401cfebc534f5d02f2f5d3533a6673:/src/dynar_unit.c diff --git a/src/dynar_unit.c b/src/dynar_unit.c index 2800ad965e..aea22a5151 100644 --- a/src/dynar_unit.c +++ b/src/dynar_unit.c @@ -8,7 +8,7 @@ /* GENERATED FILE, DO NOT EDIT */ /*******************************/ -#line 730 "xbt/dynar.c" +#line 752 "xbt/dynar.c" #define NB_ELEM 5000 @@ -122,12 +122,12 @@ XBT_TEST_UNIT("int", test_dynar_int, "Dynars of integers") xbt_dynar_push_as(d, int, cpt); DEBUG2("Push %d, length=%lu", cpt, xbt_dynar_length(d)); } - for (cpt = 0; cpt < 1000; cpt++) { - xbt_dynar_insert_at_as(d, 2500, int, cpt); + for (cpt = 0; cpt < NB_ELEM/5; cpt++) { + xbt_dynar_insert_at_as(d, NB_ELEM/2, int, cpt); DEBUG2("Push %d, length=%lu", cpt, xbt_dynar_length(d)); } - for (cpt = 0; cpt < 2500; cpt++) { + for (cpt = 0; cpt < NB_ELEM/2; cpt++) { xbt_dynar_shift(d, &i); xbt_test_assert2(i == cpt, "The retrieved value is not the same than the injected one at the begining (%d!=%d)", @@ -167,6 +167,80 @@ XBT_TEST_UNIT("int", test_dynar_int, "Dynars of integers") /* in your code is naturally the way to go outside a regression test */ } +/*******************************************************************************/ +/*******************************************************************************/ +/*******************************************************************************/ +XBT_TEST_UNIT("insert",test_dynar_insert,"Using the xbt_dynar_insert and xbt_dynar_remove functions") +{ + xbt_dynar_t d = xbt_dynar_new(sizeof(int), NULL); + unsigned int cursor; + int cpt; + + xbt_test_add1("==== Insert %d int, traverse them, remove them",NB_ELEM); + /* Populate_ints [doxygen cruft] */ + /* 1. Populate the dynar */ + for (cpt = 0; cpt < NB_ELEM; cpt++) { + xbt_dynar_insert_at(d, cpt, &cpt); + xbt_test_log2("Push %d, length=%lu", cpt, xbt_dynar_length(d)); + } + + /* 3. Traverse the dynar */ + xbt_dynar_foreach(d, cursor, cpt) { + xbt_test_assert2(cursor == cpt, + "The retrieved value is not the same than the injected one (%d!=%d)", + cursor, cpt); + } + /* end_of_traversal */ + + /* Re-fill with the same values using set_as (and re-verify) */ + for (cpt = 0; cpt < NB_ELEM; cpt++) + xbt_dynar_set_as(d, cpt, int, cpt); + xbt_dynar_foreach(d, cursor, cpt) + xbt_test_assert2(cursor == cpt, + "The retrieved value is not the same than the injected one (%d!=%d)", + cursor, cpt); + + for (cpt = 0; cpt < NB_ELEM; cpt++) { + int val; + xbt_dynar_remove_at(d,0,&val); + xbt_test_assert2(cpt == val, + "The retrieved value is not the same than the injected one (%d!=%d)", + cursor, cpt); + } + xbt_test_assert1(xbt_dynar_length(d) == 0, + "There is still %lu elements in the dynar after removing everything", + xbt_dynar_length(d)); + xbt_dynar_free(&d); + + /* ********************* */ + xbt_test_add1("==== Insert %d int in reverse order, traverse them, remove them",NB_ELEM); + d = xbt_dynar_new(sizeof(int), NULL); + for (cpt = NB_ELEM-1; cpt >=0; cpt--) { + xbt_dynar_replace(d, cpt, &cpt); + xbt_test_log2("Push %d, length=%lu", cpt, xbt_dynar_length(d)); + } + + /* 3. Traverse the dynar */ + xbt_dynar_foreach(d, cursor, cpt) { + xbt_test_assert2(cursor == cpt, + "The retrieved value is not the same than the injected one (%d!=%d)", + cursor, cpt); + } + /* end_of_traversal */ + + for (cpt =NB_ELEM-1; cpt >=0; cpt--) { + int val; + xbt_dynar_remove_at(d,xbt_dynar_length(d)-1,&val); + xbt_test_assert2(cpt == val, + "The retrieved value is not the same than the injected one (%d!=%d)", + cursor, cpt); + } + xbt_test_assert1(xbt_dynar_length(d) == 0, + "There is still %lu elements in the dynar after removing everything", + xbt_dynar_length(d)); + xbt_dynar_free(&d); +} + /*******************************************************************************/ /*******************************************************************************/ /*******************************************************************************/