C28 · Topic 3.6 · 40 minutes · AAP-2.G, AAP-2.H
Conditions at the boundary
By the end you can:
- Implement an inclusive requirement.
- Test each branch and a threshold.
- Explain a distinguishing failing input.
Before this lesson: topics 3.5.
- Selection
- Choosing which statements execute based on a condition.
- Branch
- A path through conditional code.
Understand
Translate the whole specification before choosing an operator. A requirement can be implemented by an IF/ELSE or an equivalent logically inverted condition with swapped branches, but only if both the condition and effects are transformed consistently. Boundary cases check whether a rule includes its endpoint.
Branch coverage means tests cause the relevant branches to execute; it does not alone prove the condition matches the rule. A test exactly at a threshold may distinguish two algorithms that both exercise their true/false branches on other inputs. Document expected behaviour from the specification rather than from the code being tested.
Worked example
A fictional pass is free for ages 65 or above. Faulty code uses age>65.
- Age 64 should take the paid branch.
- Age 65 should be free but the faulty condition sends it to paid.
- Age 66 is free in both versions, so it does not distinguish them.
Explore each concept
Choose a concept, change its inputs and follow the explanation. Each example models the stated rule or scenario; completing it is practice rather than evidence of mastery.
- Multiple outputs in order
- Exclusive branches
- Inverted equivalent conditions
Change it · step through · explain
Change an input, predict what will happen, then advance one step. Read why the state changes, reset and experiment. This fixed teaching model does not save progress or award XP.
Ready · Make a prediction
- Score (0–100)85Waiting
- Structureindependent-IFsWaiting
Ready to explore: Independent IFs versus IF/ELSE
Why: Change an input, predict the first effect, then advance one step.
Try this: Change one input or choose another listed case. Predict the effect, reset and compare the states and governing rule.
Step through and experiment
Change it · step through · explain
Change an input, predict what will happen, then advance one step. Read why the state changes, reset and experiment. This fixed teaching model does not save progress or award XP.
Ready · Make a prediction
- Input 114Waiting
- Input 20Waiting
Ready to experiment
Why: Predict the first change, then advance one step.
Try this: Compare ages 13 and 14 with places 0 and 1.
Check a misconception
Claim: Testing one true branch and one false branch proves a boundary is correct.
Both versions can cover both branches while disagreeing at the exact endpoint.
Guided practice
Give expected and faulty outputs for ages 64,65 and 66.
Work with a partner. Make a prediction, compare your reasoning, then identify the rule that supports your answer.
Independent transfer
Write the same correct rule using age<65 as the condition.
Exit check
Why should expected outputs be written before running faulty code?
Write your reasoning before comparing with a classmate. If your teacher assigned this task, submit it through My classes to save your work and receive feedback.
Check yourself
Your practice so far
Check an answer to see its rationale.