Exemplo n.º 1
0
END_TEST


START_TEST ( llist_11_find_min_max )
{
    int retval;
    llist_node min_max;
    llist listToTest = NULL;
    listToTest = llist_create ( trivial_comperator, NULL, test_mt ? MT_SUPPORT_FALSE : MT_SUPPORT_TRUE );

    // Insert a 5 nodes 1..5
    retval = llist_add_node ( listToTest, ( llist_node ) 2, ADD_NODE_REAR );
    retval = llist_add_node ( listToTest, ( llist_node ) 5, ADD_NODE_REAR );
    retval = llist_add_node ( listToTest, ( llist_node ) 3, ADD_NODE_REAR );
    retval = llist_add_node ( listToTest, ( llist_node ) 4, ADD_NODE_REAR );
    retval = llist_add_node ( listToTest, ( llist_node ) 1, ADD_NODE_REAR );


    retval = llist_get_max( listToTest, &min_max);
    ck_assert_int_eq ( retval, LLIST_SUCCESS );
    ck_assert_int_eq ( min_max, 5 );

    retval = llist_get_min( listToTest, &min_max);
    ck_assert_int_eq ( retval, LLIST_SUCCESS );
    ck_assert_int_eq ( min_max, 1 );

    llist_destroy ( listToTest, false, NULL );
}
Exemplo n.º 2
0
END_TEST

START_TEST ( llist_09_list_sort )
{
    int retval;
    llist listToTest = NULL;
    listToTest = llist_create ( trivial_comperator , NULL, test_mt ? MT_SUPPORT_FALSE : MT_SUPPORT_TRUE );

    // Insert a 5 nodes 1..5
    retval = llist_add_node ( listToTest, ( llist_node ) 3, ADD_NODE_REAR );
    retval = llist_add_node ( listToTest, ( llist_node ) 2, ADD_NODE_REAR );
    retval = llist_add_node ( listToTest, ( llist_node ) 1, ADD_NODE_REAR );
    retval = llist_add_node ( listToTest, ( llist_node ) 4, ADD_NODE_REAR );
    retval = llist_add_node ( listToTest, ( llist_node ) 5, ADD_NODE_REAR );

    printf ( "List before sorting: " );
    print_llist ( listToTest );

    retval = llist_sort ( listToTest, SORT_LIST_ASCENDING );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    printf ( "List After sorting ascending: " );
    print_llist ( listToTest );

    retval = llist_sort ( listToTest,  SORT_LIST_DESCENDING );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    printf ( "List After sorting descending: " );
    print_llist ( listToTest );

    llist_destroy ( listToTest, false, NULL );
}
Exemplo n.º 3
0
END_TEST

START_TEST ( llist_08_list_reverse )
{
    int retval;
    llist listToTest = NULL;
    listToTest = llist_create ( NULL, NULL, test_mt ? MT_SUPPORT_FALSE : MT_SUPPORT_TRUE );

    // Insert a 5 nodes 1..5
    retval = llist_add_node ( listToTest, ( llist_node ) 1, ADD_NODE_REAR );
    retval = llist_add_node ( listToTest, ( llist_node ) 2, ADD_NODE_REAR );
    retval = llist_add_node ( listToTest, ( llist_node ) 3, ADD_NODE_REAR );
    retval = llist_add_node ( listToTest, ( llist_node ) 4, ADD_NODE_REAR );
    retval = llist_add_node ( listToTest, ( llist_node ) 5, ADD_NODE_REAR );

    printf ( "List before reversing: " );
    print_llist ( listToTest );

    retval = llist_reverse ( listToTest );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    printf ( "List After reversing: " );
    print_llist ( listToTest );

    llist_destroy ( listToTest, false, NULL );
}
Exemplo n.º 4
0
END_TEST


START_TEST ( llist_05_list_for_each )
{
    int retval;
    llist listToTest = NULL;
    listToTest = llist_create ( NULL, NULL, test_mt ? MT_SUPPORT_FALSE : MT_SUPPORT_TRUE );

    // Insert a 5 nodes 1..5
    retval = llist_add_node ( listToTest, ( llist_node ) 1, ADD_NODE_REAR );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    retval = llist_add_node ( listToTest, ( llist_node ) 2, ADD_NODE_REAR );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    retval = llist_add_node ( listToTest, ( llist_node ) 3, ADD_NODE_REAR );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    retval = llist_add_node ( listToTest, ( llist_node ) 4, ADD_NODE_REAR );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    retval = llist_add_node ( listToTest, ( llist_node ) 5, ADD_NODE_REAR );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    retval = llist_for_each ( listToTest, trivial_node_func );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    llist_destroy ( listToTest, false, NULL );
}
Exemplo n.º 5
0
struct LList_t *picframe_add_element_to_window(struct LList_t *window, Element_t *data) {
	struct LList_t *node = NULL;
	if (window == NULL) return NULL;
	
	node = llist_add_node((struct LList_t **)&window->data, 1, (void *)data);
	
	return node;
}
Exemplo n.º 6
0
struct LList_t *picframe_add_window() {
	struct LList_t *node = NULL;

	_num_windows++;
	node = llist_add_node(&_windows, _num_windows, NULL);

	return node;
}
Exemplo n.º 7
0
END_TEST

START_TEST ( llist_03_add_dynamic_nodes )
{
    int retval;
    int *data[5];

    for ( int i = 0; i < 5; i++ )
    {
        data[i] = malloc ( sizeof ( int ) );
    }

    llist listToTest = NULL;
    llist_node retptr;
    listToTest = llist_create ( NULL, trivial_equal, test_mt ? MT_SUPPORT_FALSE : MT_SUPPORT_TRUE );

    // Insert a 5 nodes 1..5
    retval = llist_add_node ( listToTest, ( llist_node ) data[0], ADD_NODE_FRONT );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    retval = llist_add_node ( listToTest, ( llist_node ) data[1], ADD_NODE_REAR );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    retval = llist_add_node ( listToTest, ( llist_node ) data[2], ADD_NODE_FRONT );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    retval = llist_add_node ( listToTest, ( llist_node ) data[3], ADD_NODE_REAR );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    retval = llist_add_node ( listToTest, ( llist_node ) data[4], ADD_NODE_FRONT );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    // find node
    retval = llist_find_node ( listToTest, ( llist_node ) data[2], &retptr );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );
    ck_assert_ptr_eq ( retptr, ( llist_node ) data[2] );

    // destroy list, and also free the data
    llist_destroy ( listToTest, true, NULL );
}
Exemplo n.º 8
0
END_TEST

START_TEST ( llist_02_add_nodes )
{
    int retval;
    llist listToTest = NULL;
    llist_node retptr;
    listToTest = llist_create ( NULL, trivial_equal, test_mt ? MT_SUPPORT_FALSE : MT_SUPPORT_TRUE  );

    // Insert a 5 nodes 1..5
    retval = llist_add_node ( listToTest, ( llist_node ) 1, ADD_NODE_FRONT );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    retval = llist_add_node ( listToTest, ( llist_node ) 2, ADD_NODE_FRONT );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    retval = llist_add_node ( listToTest, ( llist_node ) 3, ADD_NODE_FRONT );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    retval = llist_add_node ( listToTest, ( llist_node ) 4, ADD_NODE_FRONT );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    retval = llist_add_node ( listToTest, ( llist_node ) 5, ADD_NODE_FRONT );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    printf ( "List after adding nodes: " );
    print_llist ( listToTest );

   // find
    retval = llist_find_node ( listToTest, ( llist_node ) 1, &retptr);
    ck_assert_int_eq ( retval, LLIST_SUCCESS );
    ck_assert_ptr_eq ( retptr, ( llist_node ) 1 );

    // find again, but this time, with a non existant node
    retval = llist_find_node ( listToTest, ( llist_node ) 6, &retptr);
    ck_assert_int_eq ( retval, LLIST_NODE_NOT_FOUND );

    llist_destroy ( listToTest, false, NULL );
}
Exemplo n.º 9
0
END_TEST

void * list_put_data(void * arg)
{
    ptrdiff_t i = 50;
    int retval;
    ck_assert ( arg != NULL );
    llist listToTest = (llist)arg;
    while( i > 0)
    {
        retval = llist_add_node ( listToTest, ( llist_node ) i, ADD_NODE_REAR );
        ck_assert_int_eq ( retval, LLIST_SUCCESS );
        i --;
    }
    return NULL;
}
Exemplo n.º 10
0
END_TEST

START_TEST ( llist_06_insert_nodes )
{
    int retval;
    llist listToTest = NULL;
    llist_node retptr;
    listToTest = llist_create ( NULL, trivial_equal, test_mt ? MT_SUPPORT_FALSE : MT_SUPPORT_TRUE );

    // Insert a 5 nodes 1..5
    retval = llist_add_node ( listToTest, ( llist_node ) 1, ADD_NODE_FRONT );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    retval = llist_add_node ( listToTest, ( llist_node ) 2, ADD_NODE_FRONT );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    retval = llist_add_node ( listToTest, ( llist_node ) 3, ADD_NODE_FRONT );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    retval = llist_add_node ( listToTest, ( llist_node ) 4, ADD_NODE_FRONT );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    retval = llist_add_node ( listToTest, ( llist_node ) 5, ADD_NODE_FRONT );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    printf ( "List after adding nodes: " );
    print_llist ( listToTest );

    // Find the middle node (3)
    retval = llist_find_node ( listToTest, ( llist_node ) 3, &retptr );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    // Add node before
    retval =  llist_insert_node ( listToTest,  ( llist_node ) 7, retptr, ADD_NODE_BEFORE );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    printf ( "List after adding before 3 node: " );
    print_llist ( listToTest );


    // Add node after
    retval =  llist_insert_node ( listToTest,  ( llist_node ) 8, retptr, ADD_NODE_AFTER );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    printf ( "List after adding after 3 node: " );
    print_llist ( listToTest );

    // insert node at the start of the list (before the first node)
    retval = llist_find_node ( listToTest, ( llist_node ) 5, &retptr );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    retval =  llist_insert_node ( listToTest,  ( llist_node ) 9, retptr, ADD_NODE_BEFORE );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    printf ( "List after adding 9 before the first node: " );
    print_llist ( listToTest );


    // insert node at the start of the list (after the first node)
    retval = llist_find_node ( listToTest, ( llist_node ) 9, &retptr );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    retval =  llist_insert_node ( listToTest,  ( llist_node ) 10, retptr, ADD_NODE_AFTER );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    printf ( "List after adding 10 after the first node: " );
    print_llist ( listToTest );

    // insert node at the end of the list (after the first node)
    retval = llist_find_node ( listToTest, ( llist_node ) 1, &retptr);
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    retval =  llist_insert_node ( listToTest,  ( llist_node ) 11, retptr, ADD_NODE_AFTER );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    printf ( "List after adding 11 after the last node: " );
    print_llist ( listToTest );

    llist_destroy ( listToTest, false, NULL );
}
Exemplo n.º 11
0
END_TEST

START_TEST ( llist_04_delete_nodes )
{
    int retval;
    //llist_node temp;
    llist listToTest = NULL;
    listToTest = llist_create ( NULL, trivial_equal,  test_mt ? MT_SUPPORT_FALSE : MT_SUPPORT_TRUE  );

    // Insert a 5 nodes 1..5
    retval = llist_add_node ( listToTest, ( llist_node ) 1, ADD_NODE_FRONT );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    retval = llist_add_node ( listToTest, ( llist_node ) 2, ADD_NODE_FRONT );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    retval = llist_add_node ( listToTest, ( llist_node ) 3, ADD_NODE_FRONT );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    retval = llist_add_node ( listToTest, ( llist_node ) 4, ADD_NODE_FRONT );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    retval = llist_add_node ( listToTest, ( llist_node ) 5, ADD_NODE_FRONT );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    printf ( "List after adding nodes: " );
    print_llist ( listToTest );

   // Delete tail
    retval = llist_delete_node ( listToTest, ( llist_node ) 1, false, NULL );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    printf ( "List after deleting tail: " );
    print_llist ( listToTest );

    // Delete node in the middle
    retval = llist_delete_node ( listToTest, ( llist_node ) 3, false, NULL );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    printf ( "List after deleting middle node: " );
    print_llist ( listToTest );

    // Delete head
    retval = llist_delete_node ( listToTest, ( llist_node ) 5, false, NULL );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    printf ( "List after deleting head node: " );
    print_llist ( listToTest );

    // Delete a node that doesn't exist
    retval = llist_delete_node ( listToTest, ( llist_node ) 6, false, NULL );
    ck_assert_int_eq ( retval, LLIST_NODE_NOT_FOUND );

    retval = llist_delete_node ( listToTest, ( llist_node ) 2, false, NULL );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    // The list should not  be empty now
    ck_assert_int_eq(llist_is_empty ( listToTest ), FALSE );

    ck_assert_int_eq(llist_is_empty ( listToTest ), FALSE );

    // Delete last node
    retval = llist_delete_node ( listToTest, ( llist_node ) 4, false, NULL );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    // The list should be empty now
    ck_assert_int_eq(llist_is_empty ( listToTest ), TRUE );

    llist_destroy ( listToTest, false, NULL );
}