Grade 9 · unit review

Review: Build Evidence for Small Functions

Test a function’s contract, boundaries and list structure, then retain regression cases.

Bring the unit skills together

Use these 4 new cases to check your reasoning. Choices are temporary and are not saved to an account, sent to staff or recorded as school grades. Download your current review choices before leaving or reloading.

Unit review questions
1. A fictional classifier returns junior for integer level < 5, standard otherwise. Which test detects replacing < 5 with ≤ 5?
2. Contract: integer x in 0..6, Boolean values excluded; low if x < 2, high otherwise. What is expected for 7?
3. A faulty sum visits positions 0 up to but excluding n−1. For [4, 2], what is actual versus expected?
4. Rule: low if x < 4, mid if x < 9, otherwise high. The second comparison was wrongly ≤ 9. Which regression test should be kept?

The download contains your current choices and any checked feedback. Keep the separate transfer-task work in your own document; downloading its instructions does not mark it complete.

Use the skills in a new task

Specify and repair sum_small(values): accepts lists of 0–3 integers, each in 0..9, and returns their sum; other inputs return invalid. Draft loop excludes the last position. Write and trace tests [], [6], [2,3], [10] and [1,2,3,4], repair the loop and retain a regression test.

Work on paper or in your own document. Explain the choices you made.

  • Reject [10] for an out-of-range element and [1,2,3,4] for excess length.
  • Expected accepted sums: 0, 6 and 5.
  • Explain faulty outputs 0, 0 and 2 for the accepted tests.
  • Repair to visit all positions 0..n−1 and retain [6] → 6.
Compare with a model response

First validate list length ≤ 3 and every element an integer in 0..9, with Boolean values excluded. Invalid cases: [10], [1,2,3,4]. For accepted [], [6], [2,3], expected sums are 0,6,5; the faulty loop returns 0,0,2. Set total = 0 and loop i from 0 up to but excluding n, adding values[i]. Retesting returns 0,6,5. Keep [6] → 6 as a regression test for the skipped-last-element error.

A different response can also meet the criteria. Compare the evidence and reasoning, rather than copying the wording.