Error Correction (College Board AP® Computer Science Principles): Revision Note
Testing strategies
How is testing used to correct errors?
Testing is the process of running a program with specific inputs to check whether it produces the expected outcome
Testing helps developers identify errors so they can be corrected before the program is released
If the actual outcome does not match the expected outcome, the program contains an error that must be located and fixed
Types of test inputs
The three types of defined inputs used in testing are:
Test input type | Description | Example (score 0–100) |
|---|---|---|
At the extremes | Minimum and maximum values of the input range | 0, 100 |
Just beyond the extremes | Values immediately outside the minimum/maximum | −1, 101 |
Typical values | Values within the expected range that exercise normal logic paths | 50, 75 |
Testing with a range of input types ensures the program handles both expected and unexpected data correctly
Test input selection
How should test inputs be chosen?
Test inputs should be selected based on the requirements of the program (what the program is supposed to do)
Effective test input selection covers all branches and conditions in the program's logic, not just one possible path
Developers should plan test inputs before writing code, using the specification to identify what the program must handle
Planning test inputs from the specification
Identify the different expected outcomes the program should produce, and choose inputs at and just beyond the extremes that trigger each one
Include at least one input for each expected outcome
For each test input, define the expected outcome based on the program's requirements
If the actual outcome does not match, the error is in the program's logic or processing, not in the test
Examiner Tips and Tricks
When the AP exam presents a code segment and asks which input would best test it, look for the option that covers inputs at or just beyond the extremes of the input range, rather than typical values — this is the most effective way to reveal hidden errors, and examiners expect you to recognise it. Always connect your choice of test input back to the program's requirements.
For the AP Create Performance Task, you should test your program with a range of inputs before submission — on exam day you may be asked to identify inputs that would effectively test your program, so document the test cases you used and what each one was designed to check
Worked Example
A program accepts a student's test score as input and displays "Pass" if the score is 50 or above, and "Fail" if the score is below 50. Which of the following is the best set of test inputs to verify the program works correctly?
(A) 25, 75
(B) 0, 50, 100
(C) 49, 50
(D) 50, 51, 99
[1]
Answer:
(C) 49, 50 [1 mark]
The program's behaviour changes at 50, so testing at the boundary (50) and just beyond it (49) directly probes the
>=condition where errors are most likely to occur
Unlock more, it's free!
Was this revision note helpful?