A stationery supplier specifies item_total(n) for a nonnegative integer item count. An order of at least ten items costs 15 cents per item; a smaller order costs 20 cents per item. The function returns the total in cents, with no other fees.
A student implements:
def item_total(n: int) -> int: if n > 10: return 15 * n return 20 * n
Tests with inputs 0, 4 and 12 expect 0, 80 and 180 cents, respectively, and all pass. Which statements correctly assess this design work? Select every correct statement.
Adding a test with ten items and an expected total of 150 cents would expose a disagreement between the implementation and the stated pricing requirement.
Replacing the expected totals with values produced by the current function would make the tests an independent check that the pricing requirement has been implemented correctly.
The passing tests show agreement for their particular inputs, but they do not establish that the function meets the requirement for every valid count.
Adding a test with eleven items and an expected total of 165 cents would distinguish the written comparison from the comparison required by the specification.
Unlock full course notes by signing up
Predict crate-count examples
A laboratory specifies crates_needed(bottles) to return the minimum number of crates required to hold all its bottles. Each crate holds at most eight bottles, the input is a nonnegative integer, and zero bottles require zero crates. Before implementing the function, complete its expected outputs below using exact integer numbers of crates.
Count failures against the specification
An inventory function restock_needed(stock, target) should return how many items must be added to make stock at least the target. Both inputs are nonnegative integers. If stock already meets or exceeds the target, the required addition is zero.
A student writes:
The built-in abs turns a negative difference into its positive magnitude. Count a test failure whenever the returned value differs from the value required by the specification.
Expected results for a list-consuming function
A library is designing a function total_fine. Its signature and purpose statement are written first:
Signature: total_fine(days_late: list[int]) -> float
Purpose: consumes the number of days each borrowed book is late and produces the total fine in dollars. Each book is charged $0.25 per day late, but no single book is charged more than $5.00.
Trace review notes to the artifact to revise
A code review of several functions produced the notes in the table. For each note, name the design recipe artifact that should be revised first to fix the cause of the problem, not just its symptom. Type exactly one of these answers in each cell: signature, purpose statement, examples, template. An answer may be used more than once.