Transfer practice · A request is timely when elapsed is between 0 and window inclusive. Repair a reversed lower-bound condition, then choose a negative elapsed test that demonstrates the defect.
v3 · Activity 1 of 1 · logic-errors · test-design · 11 min Runs here
Use a familiar idea in a different task. Read the changed requirement before running.
A request is timely when elapsed is between 0 and window inclusive. Repair a reversed lower-bound condition, then choose a negative elapsed test that demonstrates the defect.
Interface: validCount(count:number,capacity:number) -> boolean
| Input | Expected |
|---|---|
Negative elapsed-1, 5 | false |
Within window3, 5 | true |
Boundary5, 5 | true |
local function validCount(count, capacity)
return count >= 1 and count <= capacity
end
return validCountBoth boundaries are included. Zero fails the lower bound, and capacity + 1 fails the upper bound.
New syntax: boundary tests
A logic error produces the wrong result even though the code compiles and runs. Tests need an expected result derived from the requirement.
A revealing test makes the incorrect implementation disagree with the intended rule. Testing only ordinary cases can leave the defect invisible.
This locker should accept quantities from 1 through capacity, inclusive. Check the lower boundary, upper boundary, and values just outside the allowed range.
Select a word or symbol in this authored example. Your editor draft stays unchanged.
validCountcount, capacity
count 1 count capacity
validCountThis is a private experiment copy. It does not replace your answer or complete the activity.
These inputs apply when your scratchpad returns the function described by the activity interface.
Your output will appear here.
Replace this code with the starter? Download your draft to keep a copy.
Your output will appear here.
Sign in with RoCreators to save private progress across devices. Community verification is separate.