Test Valid and Invalid Inputs Separately
Turn a function contract into representative tests and boundary tests.
Supplied materials
- Paper and pencil; an adult may read aloud. No device, account or purchase is needed.
Learn the idea
A function contract states which inputs are allowed and what outputs should mean. Tests should cover both accepted and rejected groups. Here count must be an integer from 0 through 8, excluding Boolean values; return invalid for anything else. For valid counts below 4 return small; at least 4 return large.
Pseudocode: if count is not an allowed integer, return invalid; if count < 4, return small; otherwise return large. The lower input boundary 0, classification boundary 4 and upper input boundary 8 are separate. A value can be within the input contract but on either side of the classification threshold.
- Write test rows for −1, 0, 3, 4, 8, 9 and 2.5.
- Mark each row valid or invalid before classification.
- Add a text input "4" and a Boolean true to confirm they are rejected rather than coerced.
- Record expected returns and explain which boundary or input group each test covers.
See the method in action
−1 → invalid; 0 → small; 3 → small; 4 → large; 8 → large; 9 → invalid; 2.5 → invalid; text "4" → invalid; Boolean true → invalid. Validity and classification are tested separately.
Check your reasoning
Your answer is temporary and is not saved to an account. Download your current answer before leaving or reloading. Written work on paper or in another app stays in your own file.
See the answer and explanation
8 → large
8 is the included highest allowed integer, so it is valid and large. 9 is above the contract, and fractional/text values are rejected.
Take it further
Change the allowed upper limit to 6, leaving the classification threshold 4. Expected tests: 6 → large; 7 → invalid. Previous input 8 now becomes invalid.
Nothing here is saved to an account or sent to a teacher. The answer download includes your current choice and any checked feedback.
Check the subject sources
These LifeStarter passages, scenarios and exercises are authored for this Academy with AI assistance and review. External resources keep their publishers’ terms. A grade label suggests a starting level; it does not establish alignment with your school’s complete requirements.