PreviousUpNext

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

## red-black-numbered-set-generic-unit-test.pkg

# Compiled by:
#     src/lib/test/unit-tests.lib

# Run by:
#     src/lib/test/all-unit-tests.pkg



package red_black_numbered_set_generic_unit_test {

    include package   unit_test;                                                                # unit_test                             is from   src/lib/src/unit-test.pkg

    package numbered_set
        =
        red_black_numbered_set_g (                                              # red_black_numbered_set_g              is from   src/lib/src/red-black-numbered-set-g.pkg
            package {
                Key = int::Int;
                compare = int::compare;
            }
        );

    include package   numbered_set;

    name =  "src/lib/src/red-black-numbered-set-generic-unit-test.pkg unit tests";

    fun run ()
        =
        {
            printf "\nDoing %s:\n" name;

            my limit = 100;

            # Create a numbering by successive appends:
            #
            my test_numbering
                =
                for (m = empty, i = 0;  i < limit;  ++i; m) {

                    m = set (m, i);
                    assert (all_invariants_hold   m);
                    assert (not (is_empty m));
                    assert (the (first_key_else_null m) == 0);
                    assert (     vals_count m  == i+1);


                };

            # Check resulting numbering's contents:
            #
            for (i = 0;  i < limit;  ++i) {
                assert ((the (find (test_numbering, i))) == i);
            };

            # Try removing at all possible positions in numbering:
            #
            for (numbering' = test_numbering, i = 0;   i < limit;   ++i) {

                my (numbering'', value) = remove (numbering', i);
                assert (value == i);
                assert (all_invariants_hold numbering'');
            };




            assert (is_empty empty);

            summarize_unit_tests  name;
        };
};


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext