Exemplo n.º 1
0
void
test_OneElementQueue(void) {
    queue* q = create_queue();

    TEST_ASSERT_NOT_NULL(q);

    element e = {"string", 3};
    element* e_ptr = debug_get_node(sizeof(element));
    enqueue(q, e_ptr);
    *e_ptr = e;

    TEST_ASSERT_FALSE(empty(q));
    TEST_ASSERT_NOT_NULL(queue_head(q));
    TEST_ASSERT_EQUAL(1, get_no_of_elements(q));

    element* e_ptr_returned = dequeue(q);

    TEST_ASSERT_NOT_NULL(e_ptr_returned);
    TEST_ASSERT_EQUAL_STRING(e_ptr_returned->str, "string");
    TEST_ASSERT_EQUAL_PTR(e_ptr_returned, e_ptr);
    TEST_ASSERT_EQUAL(0, get_no_of_elements(q));
    TEST_ASSERT_TRUE(empty(q));
    TEST_ASSERT_NULL(dequeue(q));

    destroy_queue(q);
}
Exemplo n.º 2
0
void
test_AppendQueues(void) {
    queue* q1 = create_queue();
    queue* q2 = create_queue();
    queue* q3 = create_queue();
    queue* q4 = create_queue();
    queue* q5 = create_queue();

    // append empty queue to empty queue
    append_queue(q1, q2);	// destroys q2

    element *e1_ptr, *e2_ptr, *e3_ptr, *e4_ptr, *e5_ptr, *e6_ptr;
    e1_ptr = (element*)debug_get_node(sizeof(element));
    e2_ptr = (element*)debug_get_node(sizeof(element));
    e3_ptr = (element*)debug_get_node(sizeof(element));
    e4_ptr = (element*)debug_get_node(sizeof(element));
    e5_ptr = (element*)debug_get_node(sizeof(element));
    e6_ptr = (element*)debug_get_node(sizeof(element));

    enqueue(q1, e1_ptr);
    enqueue(q1, e2_ptr);
    enqueue(q1, e3_ptr);


    // append empty queue to non empty queue
    append_queue(q1, q3);	// destroys q3
    TEST_ASSERT_EQUAL(3, get_no_of_elements(q1));

    // append non empty queue to empty queue
    append_queue(q4, q1);	// destroys q1
    TEST_ASSERT_EQUAL(3, get_no_of_elements(q4));

    enqueue(q5, e4_ptr);
    enqueue(q5, e5_ptr);

    // append non empty queue to non empty queue
    append_queue(q4, q5);	// destroys q5
    TEST_ASSERT_EQUAL(5, get_no_of_elements(q4));

    dequeue(q4);
    dequeue(q4);
    dequeue(q4);
    dequeue(q4);
    dequeue(q4);

    free_node(e1_ptr);
    free_node(e2_ptr);
    free_node(e3_ptr);
    free_node(e4_ptr);
    free_node(e5_ptr);
    free_node(e6_ptr);

    TEST_ASSERT_EQUAL(0, get_no_of_elements(q4));

    // destroy_queue(q1);	// destroyed already
    // destroy_queue(q2);	// destroyed already
    // destroy_queue(q3);	// destroyed already
    destroy_queue(q4);
    // destroy_queue(q5);	// destroyed already
}
Exemplo n.º 3
0
void
test_EmptyQueue(void) {
    queue* q = create_queue();

    TEST_ASSERT_NOT_NULL(q);
    TEST_ASSERT_TRUE(empty(q));
    TEST_ASSERT_NULL(queue_head(q));
    TEST_ASSERT_NULL(dequeue(q));
    TEST_ASSERT_EQUAL(0, get_no_of_elements(q));

    destroy_queue(q);
}
Exemplo n.º 4
0
void
test_MultipleElementQueue(void) {
    queue* q = create_queue();

    TEST_ASSERT_NOT_NULL(q);

    element *e1_ptr, *e2_ptr, *e3_ptr;

    e1_ptr = (element*)debug_get_node(sizeof(element));
    e2_ptr = (element*)debug_get_node(sizeof(element));
    e3_ptr = (element*)debug_get_node(sizeof(element));

    enqueue(q, e1_ptr);
    enqueue(q, e2_ptr);
    enqueue(q, e3_ptr);

    TEST_ASSERT_EQUAL(3, get_no_of_elements(q));

    dequeue(q);
    enqueue(q, e1_ptr);

    TEST_ASSERT_EQUAL(3, get_no_of_elements(q));

    dequeue(q);
    dequeue(q);
    enqueue(q, e3_ptr);
    enqueue(q, e2_ptr);

    TEST_ASSERT_EQUAL_PTR(dequeue(q), e1_ptr);
    TEST_ASSERT_EQUAL_PTR(dequeue(q), e3_ptr);
    TEST_ASSERT_EQUAL_PTR(dequeue(q), e2_ptr);
    TEST_ASSERT_EQUAL(0, get_no_of_elements(q));
    TEST_ASSERT_NULL(dequeue(q));

    destroy_queue(q);
}
Exemplo n.º 5
0
static int
transform_sections (mpz_t X1, mpz_t X2, mpz_t no_of_elements,
		    gfc_expr * l_start, gfc_expr * l_end, gfc_expr * l_stride,
		    gfc_expr * r_start, gfc_expr * r_stride)
{
  if (NULL == l_start || NULL == l_end || NULL == r_start)
    return 1;

  /* TODO : Currently we check the dependency only when start, end and stride
    are constant.  We could also check for equal (variable) values, and
    common subexpressions, eg. x vs. x+1.  */

  if (l_end->expr_type != EXPR_CONSTANT
      || l_start->expr_type != EXPR_CONSTANT
      || r_start->expr_type != EXPR_CONSTANT
      || ((NULL != l_stride) && (l_stride->expr_type != EXPR_CONSTANT))
      || ((NULL != r_stride) && (r_stride->expr_type != EXPR_CONSTANT)))
    {
       return 1;
    }


  get_no_of_elements (no_of_elements, l_end, l_start, l_stride);

  mpz_sub (X1, r_start->value.integer, l_start->value.integer);
  if (l_stride != NULL)
    mpz_cdiv_q (X1, X1, l_stride->value.integer);
  
  if (r_stride == NULL)
    mpz_set (X2, no_of_elements);
  else
    mpz_mul (X2, no_of_elements, r_stride->value.integer);

  if (l_stride != NULL)
    mpz_cdiv_q (X2, X2, r_stride->value.integer);
  mpz_add (X2, X2, X1);

  return 0;
}