CSC 161 Schedule Readings Labs & Projects Homework Deadlines Resources

Testing

Pre- and Post-Conditions

  1. Review the MyroC.h header file documentation.
    1. In the documentation, find at least two functions that have stated a "pre-condition" and at least two functions that have stated a "post-condition". (Note that every function should have postconditions, otherwise there would be no point in calling it.)
    2. In anticipation of later work in this lab, review the documentation for the function rMotors. The documentation does not explicitly state pre-conditions for this function, but one might infer such conditions. Write a careful statement of the implied pre-condition(s) for rMotors.
  2. The program motors-test.c sets the motor speeds of the Scribbler to the given leftspeed and rightspeed.
    1. Initialize the variables leftspeed and rightspeed to 1; compile and run the program.
    2. Initialize the variables leftspeed and rightspeed to 1 and -1 respectively. Compile and run the program.
    3. Initialize the variables leftspeed and rightspeed to 2 and -1. respectively. Compile and run the program.
    4. Now try using values 6 and 5 respectively.
    5. Try other numbers that you might need to figure out what works and what doesn't.
    6. How do these experimental results compare with the pre-conditions that you inferred in Step 1b?

The assert Function in C

  1. Modify the same code, motors-test.c, to use assert so that it will test the precondition(s) you wrote for rMotors in motors-test.c.

Note: You can read about C's assert function in the accompanying reading and/or using the command man assert in a terminal window. Better yet, read about assert in both places!

Choosing Test Cases

  1. Program follower-test.c is supposed to use the Scribbler 2 IR sensors to follow an object (such as a sheet of paper held in front of it) if it moves.
    1. Develop two test plans for this program to determine whether the program works correctly. Apply both black-box and white-box testing strategies by identifying test cases that will cover a full range of situations that might be encountered in executing the program. Recall:
      • Black-box testing is when the problem is examined to determine the logical cases that might arise. Test cases are developed without reference to details of code.
      • White-box testing is when the code is examined to determine each of the possible conditions that may arise, and tests are developed to exercise each part of the code.

        Although black-box testing should not, for white-box testing you will consult the source code for follower-test.c.

    2. Run follower-test.c  with all the cases from your test plan to determine whether the program works correctly.
    3. Fix errors you found in the program.
    4. Run the program again with all the cases from your test plan to be sure that it now works correctly.