PreviousUpNext

15.4.967  src/lib/src/red-black-set-generic-unit-test.pkg

## 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 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 set;

    name =  "src/lib/src/red-black-set-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 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'' = delete (set', i);

                assert (all_invariants_hold set'');
            };




            assert (is_empty empty);

            summarize_unit_tests  name;
        };
};


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext