Refine designs and choose test data
Refine before writing statements
For a largest-gap report, start with read data → calculate gaps → find greatest gap → output. Refine calculate gaps to compare indices I and I - 1 for I from 2 to NumberOfReadings. This avoids reading before the lower bound.
![The report splits into read data, calculate gaps, find greatest gap and output; calculate gaps is refined into FOR I ← 2 TO NumberOfReadings with Gap ← Reading[I] - Reading[I - 1]](/static/code/as-pseudocode/refine-gaps.png)
Translate a flow into control structures
A decision that returns to an earlier input step is repetition, not a single IF. Write the continuation condition carefully. Make an identifier table with each name, type and purpose before coding.
Common mistakes
- Starting the gap loop at 1.
Data[I - 1]then readsData[0], which is outside[1:6]: a runtime error. - Turning a back edge into an
IF. The input is checked only once, so a second bad value gets through. - A test plan with an input but no expected result. Without a prediction, the output cannot be judged.
- Refining every box into statements at once. Refine one step, check it, then refine the next.
Test with expected outcomes
A test plan must state input, reason and expected result. For largest adjacent gap, [2, 2] should produce 0; [-3, 5] should produce 8. Include the smallest permitted list and a maximum gap at the last pair. Compare the observed output with the prediction; merely running a program is not evidence of correctness.
On paper, draw a flowchart for the validation task and explain how its back edge becomes a loop. The structured checks below assess the algorithm and chosen values; your diagram and explanation need self-review or teacher review.
Difficulty 4/5 · 280 coins + a small bonus on first completion today
Translate this flow into pseudocode: 1 read Value; 2 if Value < 1 OR Value > 6, return to step 1; 3 output Value * 5; 4 stop.
Click Run to see the output here.
Difficulty 4/5 · 280 coins + a small bonus on first completion today
Valid integers are 1 to 6. Choose one normal, one boundary and one invalid value, in that order, from: 3, 6, 7.
Difficulty 4/5 · 280 coins + a small bonus on first completion today
Read NumberOfReadings (2 to 6), then NumberOfReadings non-decreasing integer readings. Store them in an array. Output the largest gap between adjacent readings.
Click Run to see the output here.
Explain your choice of data structure and loop. Identify one boundary case and predict its result. For a subroutine, explain what is returned or changed in the caller.
Saved for this sitting on this browser. Review this yourself or with your teacher; these explanations are not automatically marked.
Review your explanation against these criteria
- My types and data structure match the data and the question.
- I justified the loop and checked its first and last iterations.
- Initial values and rejected operations preserve the intended state.
- My test includes input, purpose and expected result.
- I distinguished returning a value from printing and changing caller state.