Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Chris Müller
crystal
Commits
1ec2c1af
Commit
1ec2c1af
authored
Oct 30, 2012
by
Chris Müller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test: add testcases for in-order traversal in red-black trees.
parent
3b9cef12
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
1 deletion
+38
-1
test/red_black_tree.c
test/red_black_tree.c
+38
-1
No files found.
test/red_black_tree.c
View file @
1ec2c1af
...
...
@@ -113,6 +113,42 @@ test_red_black_tree_removal(const_pointer list)
}
static
void
test_red_black_tree_traversal
(
const_pointer
list
)
{
struct
RBTree
*
tree
=
rb_tree_new
(
cry_int_compare
);
const
int
*
keys
=
cry_cast
(
const
int
*
,
list
);
struct
RBNode
*
data
=
0
;
assert
(
tree
->
nodes
==
0
);
while
(
*
keys
>
0
)
{
assert
(
rb_tree_insert
(
tree
,
keys
)
!=
0
);
++
keys
;
}
assert
(
tree
->
nodes
==
10
);
keys
=
cry_cast
(
const
int
*
,
list
);
data
=
rb_node_first
(
tree
);
while
(
data
!=
0
)
{
data
=
rb_node_next
(
data
);
}
data
=
rb_node_last
(
tree
);
while
(
data
!=
0
)
{
data
=
rb_node_prev
(
data
);
}
rb_tree_clear
(
tree
,
0
);
cry_free
(
tree
);
}
void
cry_test_red_black_trees
(
void
)
...
...
@@ -121,5 +157,6 @@ cry_test_red_black_trees(void)
cry_unittest_run
(
"structures.red_black_tree.insertion"
,
test_red_black_tree_insertion
,
keys
,
10
);
cry_unittest_run
(
"structures.red_black_tree.removal"
,
test_red_black_tree_removal
,
keys
,
10
);
cry_unittest_run
(
"structures.red_black_tree.initialization"
,
test_red_black_tree_initialization
,
0
,
10
);
cry_unittest_run
(
"structures.red_black_tree.initialization"
,
test_red_black_tree_initialization
,
0
,
10
);
cry_unittest_run
(
"structures.red_black_tree.traversal"
,
test_red_black_tree_traversal
,
keys
,
10
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment