## red-black-set-generic-unit-test.pkg
# Compiled by:
#
src/lib/test/unit-tests.lib# Run by:
#
src/lib/test/all-unit-tests.pkg### "Look -- I'm getting much better errors now!"
###
### -- Sandy Stone
package red_black_set_generic_unit_test {
#
include package unit_test; # unit_test is from
src/lib/src/unit-test.pkg package set
=
red_black_set_g ( # red_black_set_g is from
src/lib/src/red-black-set-g.pkg #
package {
Key = int::Int;
compare = int::compare;
}
);
include package set;
name = "src/lib/src/red-black-set-generic-unit-test.pkg unit tests";
fun run ()
=
{ printf "\nDoing %s:\n" name;
#
limit = 100;
# debug_print (m, printf "%d", printf "%d");
# Create a set by successive appends:
#
my test_set
=
for (m = empty, i = 0; i < limit; ++i; m) {
#
m = add (m, i);
assert (all_invariants_hold m);
assert (not (is_empty m));
assert ( vals_count m == i+1);
};
# Check resulting set's contents:
#
for (i = 0; i < limit; ++i) {
#
assert (member (test_set, i));
};
# Try removing at all possible positions in set:
#
for (set' = test_set, i = 0; i < limit; ++i) {
#
set'' = drop (set', i);
assert (all_invariants_hold set'');
};
assert (is_empty empty);
summarize_unit_tests name;
};
};