## int-red-black-map-unit-test.pkg
# Compiled by:
#
src/lib/test/unit-tests.lib# Run by:
#
src/lib/test/all-unit-tests.pkgpackage int_red_black_map_unit_test {
#
include package unit_test; # unit_test is from
src/lib/src/unit-test.pkg include package int_red_black_map; # int_red_black_map is from
src/lib/src/int-red-black-map.pkg name = "src/lib/src/int-red-black-map-unit-test.pkg tests";
fun run ()
=
{
printf "\nDoing %s: (mode d=%d)\n" name (microthread_preemptive_scheduler::get_uninterruptible_scope_nesting_depth ());
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;
};
};