50 minutes. Self-marked against the rubric. 12 marks. In the full course this counts toward the labs and cases share (15% of the course grade). Write your answers in the boxes, then open the model answer and tick each mark you earned honestly. Nothing is sent or stored.
Scenario (invented)
A colleague wrote this method for “return the smallest number in a list of at least one number”: set smallest to 100; for each item in the list, if the item is less than smallest, set smallest to the item; output smallest.
Tasks
Task 1 (3 marks)
Trace the method on the list 140, 120, 130 and state the output.
Private: nothing you type here is sent or stored.
Task 2 (2 marks)
Name the fault and the kind of input that exposes it.
Private: nothing you type here is sent or stored.
Task 3 (3 marks)
Rewrite the method so that it meets the specification.
Private: nothing you type here is sent or stored.
Task 4 (4 marks)
Write four tests for the repaired method, each with a reason.
Private: nothing you type here is sent or stored.
Rubric and model answer
Task 1: trace (3 marks)
Model: smallest starts at 100. 140 is not less than 100, so no change. 120 is not less, so no change. 130 is not less, so no change. Output: 100, which is not in the list; the correct answer is 120.
Task 2: find the fault (2 marks)
Model: the starting value is a fixed number, 100, not the first item. Any list whose items are all 100 or more exposes it.
Task 3: repair (3 marks)
Model: set smallest to the first item; for each remaining item, if the item is less than smallest, set smallest to the item; output smallest.
Task 4: tests (4 marks)
Model: (1) 140, 120, 130 gives 120, the original failing case; (2) 7 gives 7, a single item; (3) -3, -8, -5 gives -8, all negative; (4) 4, 4, 4 gives 4, repeated values.
Marks so far: 0 of 12