Exemple #1
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
}
Exemple #2
0
void test_append_queue() {
	Queue *q1 = init_queue();
	enqueue(q1, "abc");
	Queue *q2 = init_queue();
	enqueue(q2, "def");
	append_queue(q1, q2);
	append_queue(q1, NULL);
	append_queue(NULL, NULL);
	assert(strcmp(q1->head->next->element, "def") == 0);
}
Exemple #3
0
int main(void){
    char buf[128];
    append_queue("aaa1");
    append_queue("aaa2");
    
    remove_queue(buf);
    printf("%s\n",buf);
    remove_queue(buf);
    printf("%s\n",buf);
    return (0);
}
Exemple #4
0
void _read_workload(char *file_path)
{
	FILE *file = fopen(file_path, "r");
	size_t ln = 0;

	if (file != NULL)
	{
		char line[100];
		while (fgets(line, sizeof(line), file) != NULL)
		{
			ln = strlen(line);
			if (line[ln - 1] == '\n')
			{
				line[ln - 1] = '\0';
			}
			append_queue(job_queue, line);
		}
	}
}