test/rbtree/test_rbtree_delete_fixup.cpp
/**
 * Create an empty rbtree, sub in a single black node, and verify that
 * rbtree_delete_fixup works correctly.
 */
Create an empty rbtree, sub in a single black node, and verify that
rbtree_delete_fixup works correctly.
Create an empty rbtree sub in a single black node and verify that rbtree_delete_fixup works correctly .
TEST(fixup_single_black_node)
{
    allocator* alloc = nullptr;
    rbtree* tree = nullptr;
    TEST_ASSERT(
        STATUS_SUCCESS == malloc_allocator_create(&alloc));
    TEST_ASSERT(
        STATUS_SUCCESS ==
            rbtree_create(&tree, alloc, &dummy_compare, &dummy_key, nullptr));
    rbtree_node z;
    tree->root = &z;
    z.parent = tree->nil;
    z.left = tree->nil;
    z.right = tree->nil;
    z.color = RBTREE_BLACK;
    rbtree_delete_fixup(tree, &z);
    TEST_EXPECT(&z == tree->root);
    TEST_EXPECT(RBTREE_BLACK == z.color);
    TEST_EXPECT(RBTREE_BLACK == tree->nil->color);
    TEST_EXPECT(tree->nil == tree->nil->left);
    TEST_EXPECT(tree->nil == tree->nil->right);
    TEST_EXPECT(tree->nil == tree->nil->parent);
    tree->root = tree->nil;
    TEST_ASSERT(
        STATUS_SUCCESS == resource_release(rbtree_resource_handle(tree)));
    TEST_ASSERT(
        STATUS_SUCCESS == resource_release(allocator_resource_handle(alloc)));
}
TEST ( fixup_single_black_node ) { allocator * alloc = nullptr ; rbtree * tree = nullptr ; TEST_ASSERT ( STATUS_SUCCESS == malloc_allocator_create ( & alloc ) ) ; TEST_ASSERT ( STATUS_SUCCESS == rbtree_create ( & tree , alloc , & dummy_compare , & dummy_key , nullptr ) ) ; rbtree_node z ; tree -> root = & z ; z . parent = tree -> nil ; z . left = tree -> nil ; z . right = tree -> nil ; z . color = RBTREE_BLACK ; rbtree_delete_fixup ( tree , & z ) ; TEST_EXPECT ( & z == tree -> root ) ; TEST_EXPECT ( RBTREE_BLACK == z . color ) ; TEST_EXPECT ( RBTREE_BLACK == tree -> nil -> color ) ; TEST_EXPECT ( tree -> nil == tree -> nil -> left ) ; TEST_EXPECT ( tree -> nil == tree -> nil -> right ) ; TEST_EXPECT ( tree -> nil == tree -> nil -> parent ) ; tree -> root = tree -> nil ; TEST_ASSERT ( STATUS_SUCCESS == resource_release ( rbtree_resource_handle ( tree ) ) ) ; TEST_ASSERT ( STATUS_SUCCESS == resource_release ( allocator_resource_handle ( alloc ) ) ) ; }
Create an empty rbtree, sub in a single black node, and verify that
 rbtree_delete_fixup works correctly.
Create an empty rbtree sub in a single black node and verify that rbtree_delete_fixup works correctly .
/* we should be able to create a malloc allocator. */ /* we should be able to create an rbtree instance. */ /* PRECONDITIONS. */ /* perform the delete fixup. */ /* POSTCONDITIONS. */ /* before cleaning up rbtree, set the root to nil. */ /* clean up. */