## 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_with_implicit_keys_generic_unit_test {
include package unit_test; # unit_test is from
src/lib/src/unit-test.pkg package map
=
red_black_map_with_implicit_keys_g ( # red_black_map_wit_implicit_keys_g is from
src/lib/src/red-black-map-with-implicit-keys-g.pkg package {
Key = int::Int;
compare = int::compare;
}
);
include package map;
name = "src/lib/src/red-black-map-with-implicit-keys-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:
#
Value = (Int, Int);
value_to_key = #1: Value -> Int;
empty_map = empty value_to_key;
my test_map
=
for (m = empty_map, 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,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,0));
};
# Check resulting map's contents:
#
for (i = 0; i < limit; ++i) {
assert ((the (get (test_map, i))) == (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_map);
summarize_unit_tests name;
};
};