char *test_new() { val1 = DArray_new(array); mu_assert(val1 != NULL, "failed to make a new element"); val2 = DArray_new(array); mu_assert(val2 != NULL, "failed to make a new element"); return NULL; }
char *test_copy() { DArray *orig = DArray_create(sizeof(int), 11); DArray *dest = DArray_create(sizeof(int), 11); int i = 0; for(i = 0; i < 10; i++) { int *el_to_add = DArray_new(orig); *el_to_add = i; mu_assert(DArray_push(orig, el_to_add) == 0, "Pushing to DArray failed."); } int rc = DArray_copy(orig, dest); mu_assert(rc == 0, "Copy failed.") mu_assert(orig->max == dest->max, "max did not copy properly."); mu_assert(orig->end == dest->end, "end did not copy properly."); mu_assert(orig->element_size == dest->element_size, "element_size did not copy properly."); mu_assert(orig->expand_rate == dest->expand_rate, "expand_rate did not copy properly."); for(i = 0; i < 10; i++) { int *val = DArray_get(dest, i); mu_assert(val != NULL, "Got NULL from copy."); mu_assert(*val == i, "Failed to copy contents correctly."); } return NULL; }
char *test_push_pop() { int i = 0; for(i=0; i<1000; i++) { int *val = DArray_new(array); *val = i*333; DArray_push(array, val); } mu_assert(array->max == 1201, "Wrong max size"); for(i=999; i>=0; i--) { int *val = DArray_pop(array); mu_assert(val != NULL, "Should not be NULL"); mu_assert(*val == i*333, "Wrong value"); DArray_free(val); } return NULL; }
char *test_push_pop() { int i = 0; for (i = 0; i < 1000; i++) { int *val = DArray_new(array); *val = i * 333; DArray_push(array, val); //int valuepushed = *( (int*)DArray_get(array, i)); //printf("%d", valuepushed); //debug("%d: At address %x, we have %d",i, DArray_get(array, i), // *((int*)DArray_get(array, i)) ); } mu_assert(array->max == 1201, "Wrong max size."); for (i = 999; i >= 0; i--) { int *val = DArray_pop(array); mu_assert(val != NULL, "Shouldn't get a NULL"); mu_assert(*val == i * 333, "Wrong Value."); DArray_free(val); } return NULL; }