Esempio n. 1
0
char *test_array_pop()
{
    char *popped = Array_pop(a);
    test_assert(a->length == 2, "Array length is not 2");
    test_assert_streq(popped, three, "Wrong popped element: three");

    popped = Array_pop(a);
    test_assert(a->length == 1, "Array length is not 1");
    test_assert_streq(popped, two, "Wrong popped element: two");

    popped = Array_pop(a);
    test_assert(a->length == 0, "Array length is not 0");
    test_assert_streq(popped, one, "Wrong popped element: one");

    return NULL;
}
char *test_push_pop()
{
  int i = 0;
  for(i = 0; i < 1000; i++) {
    int *val = Array_new(array);
    *val = i * 333;
    Array_push(array, val);
  }

  mu_assert(array->max == 1201, "Wrong max size.");

  for(i = 999; i >= 0; i--) {
    int *val = Array_pop(array);
    mu_assert(val != NULL, "Shouldn't get a NULL.");
    mu_assert(*val == i * 333, "Wrong value.");
    Array_free(val);
  }

  return NULL;
}