Simple Unit Tests

version 1/130803 by Dannii Willis

  • Home page
  • Beginning
  • Previous



  • Chapter - The Unit test rules unindexed

    The current unit test name is an indexed text variable.

    Unit test rules is a rulebook.

    Running the unit tests is an action out of world.
    Understand "run the unit test/tests" and "run unit test/tests" and "unit test/tests" and "unit" as running the unit tests.

    [ Manually go through the unit test rules so that we can reset the assertion count for each rule, and capture text automatically. ]
    Carry out running the unit tests (this is the run all unit tests rule):
        let index be 0;
        now the total assertion count is 0;
        now the assertion failures count is 0;
        [ Save and restore each time a unit test is run ]
        if the result of saving before running the unit tests is 2:
            stop;
        [ Loop through the unit test rules until we reach the end (NULL/-1) ]
        let addr be the address of unit test rule number index;
        while the addr is not -1:
            now the test assertion count is 0;
            [ Find the name of the rule, if we can ]
            now the current unit test name is "";
            if the memory economy option is inactive:
                now the current unit test name is "[the rule at address addr]";
                replace the regular expression " rule$|Unit test" in the current unit test name with "";
            if the current unit test name is "":
                now the current unit test name is "[index + 1]";
            [ Start capturing text so that the first assertion can use the captured output if it wants ]
            start capturing text;
            consider the rule at address addr;
            stop capturing text;
            increment index;
            now addr is the address of unit test rule number index;
        if the assertion failures count is 0:
            say "Congratulations! ";
        say "[the assertion failures count] of [the total assertion count] assertions failed.[paragraph break]";
        restore back to before running the unit tests;

    [ A couple of short I6 phrases to loop through the unit tests ]
    To decide what number is the address of unit test rule number (i - a number):
        (- (rulebooks_array-->(+ the unit test rules +) )-->{i} -).

    To decide what rule is the rule at address (addr - a number):
        (- {addr} -).

    [ A couple more for saving and restoring an undo point ]
    To decide what number is the result of saving before running the unit tests:
        (- VM_Save_Undo() -).

    To restore back to before running the unit tests:
        (- VM_Undo(); -).

    Simple Unit Tests ends here.