v3 · Activity 2 of 5 · logic-errors · test-design · 11 min Runs here
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.
Choose a revealing test, then repair validCount so only counts 1 through capacity are accepted. The coding check evaluates the repaired behavior. Keep the final return shown in the starter so the checker can call or inspect your result.
Interface: validCount(count:number,capacity:number) -> boolean
| Input | Expected |
|---|---|
Minimum valid1, 5 | true |
Full locker5, 5 | true |
Over capacity6, 5 | false |
Zero0, 5 | false |
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.