## red-black-map-generic-unit-test.pkg
# Compiled by:
#
src/lib/test/unit-tests.lib# Run by:
#
src/lib/test/all-unit-tests.pkgpackage red_black_map_generic_unit_test {
include package unit_test; # unit_test is from
src/lib/src/unit-test.pkg package map
=
red_black_map_g ( # red_black_map_g is from
src/lib/src/red-black-map-g.pkg package {
Key = int::Int;
compare = int::compare;
}
);
include package map;
name = "src/lib/src/red-black-map-generic-unit-test.pkg unit tests";
fun run ()
=
{
printf "\nDoing %s:\n" name;
my limit = 100;
# debug_print (m, printf "%d", printf "%d");
# Create a map by successive appends:
#
my test_map
=
for (m = empty, i = 0; i < limit; ++i; m) {
m = set (m, i, i);
assert (all_invariants_hold m);
assert (not (is_empty m));
assert (the (first_val_else_null m) == 0);
assert ( vals_count m == i+1);
assert (#1 (the (first_keyval_else_null m)) == 0);
assert (#2 (the (first_keyval_else_null m)) == 0);
};
# Check resulting map's contents:
#
for (i = 0; i < limit; ++i) {
assert ((the (get (test_map, i))) == i);
};
# Try removing at all possible positions in map:
#
for (map' = test_map, i = 0; i < limit; ++i) {
#
map'' = drop (map', i);
assert (all_invariants_hold map'');
};
assert (is_empty empty);
summarize_unit_tests name;
};
};