Testing
Pre- and Post-Conditions
-
Review the
MyroC.hheader file documentation. - 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 not point in calling it.)
-
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) forrMotors. -
The program
motors-test.csets the motor speeds of the Scribbler to the givenleftspeedandrightspeed.-
Initialize the variables
leftspeedandrightspeedto 1. -
Initialize the variables
leftspeedandrightspeedto 1 and -1 respectively. -
Initialize the variables
leftspeedandrightspeedto 2 and -1. respectively. - Now try 6 and 5 respectively.
- Try other numbers that you might need to figure out what works and what doesn't.
- How do these experimental results compare with the pre-conditions that you inferred in Step 1b?
-
Initialize the variables
The assert Function in C
-
Modify the same code,
motors-test.c, to useassertso that it will test the precondition(s) you wrote forrMotorsinmotors-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
-
Copy the program
object-avoid.cto your working directory. This program attempts to control the robot in avoiding obstacles. Run the program a few times and observe what it does.-
Develop two test plans
for
object-avoid.cto figure out if the program works correctly. That is, apply both black-box and white box testing by identifying test cases that will cover a full range of situations that might be encountered in executing the programobject-avoid.c. Remember that:- 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.
- You should have found that the program is not working properly. Now fix the program so that it performs in the intended way and the robot avoids obstacles.
-
Develop two test plans
for
-
Program
follower-test.cis supposed to control the robot in following a sheet of paper which is held in front of the robot.- Develop two test plans for this program, using both black-box and white-box testing strategies. Apply both black-box and white box testing to identify tests cases that will cover a full range of situations that might be encountered.
-
Run
follower-test.cwith all the cases from your test plan to determine whether the program works correctly. - Fix the errors you found in the program.
- Run the program again with all the cases from your test plan to be sure that it now works correctly.
