/* GENERATED FILE, DO NOT EDIT */
/*******************************/
-#line 730 "xbt/dynar.c"
+#line 754 "xbt/dynar.c"
#define NB_ELEM 5000
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)",
/* 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);
+ int cursor,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 */
+
+ 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 %d 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 %d elements in the dynar after removing everything",
+ xbt_dynar_length(d));
+ xbt_dynar_free(&d);
+}
+
/*******************************************************************************/
/*******************************************************************************/
/*******************************************************************************/
/* SGU: BEGIN FILE xbt/dynar.c */
void test_dynar_int(void);
+ void test_dynar_insert(void);
void test_dynar_double(void);
void test_dynar_string(void);
void test_dynar_sync_int(void);
/* SGU: BEGIN FILE xbt/dynar.c */
suite = xbt_test_suite_by_name("dynar","Dynar data container");
xbt_test_suite_push(suite, "int", test_dynar_int, "Dynars of integers");
+ xbt_test_suite_push(suite, "insert", test_dynar_insert, "Using the xbt_dynar_insert and xbt_dynar_remove functions");
xbt_test_suite_push(suite, "double", test_dynar_double, "Dynars of doubles");
xbt_test_suite_push(suite, "string", test_dynar_string, "Dynars of strings");
xbt_test_suite_push(suite, "synchronized int", test_dynar_sync_int, "Synchronized dynars of integers");
void *res;
unsigned long old_used;
unsigned long new_used;
- unsigned long nb_shift;
+ long nb_shift;
_sanity_check_dynar(dynar);
_sanity_check_idx(idx);
nb_shift = old_used - idx;
- if (nb_shift)
+ if (nb_shift>0) {
memmove(_xbt_dynar_elm(dynar, idx + 1),
_xbt_dynar_elm(dynar, idx), nb_shift * dynar->elmsize);
+ }
dynar->used = new_used;
res = _xbt_dynar_elm(dynar, idx);
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)",
/* 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);
+ int cursor,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 */
+
+ 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 %d 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 %d elements in the dynar after removing everything",
+ xbt_dynar_length(d));
+ xbt_dynar_free(&d);
+}
+
/*******************************************************************************/
/*******************************************************************************/
/*******************************************************************************/