Skip to main content
AP CSP course

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.

  1. Age 64 should take the paid branch.
  2. Age 65 should be free but the faulty condition sends it to paid.
  3. 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
Open this example on its own

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

Ready to explore: Independent IFs versus IF/ELSE
  1. Score (0–100)85Waiting
  2. 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

Ready to experiment
  1. Input 114Waiting
  2. 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

  1. Question 1 of 2Which condition directly implements a free pass at 65 or above?

    Select one answer.

  2. Question 2 of 2Which test best distinguishes age>65 from age≥65?

    Select one answer.

Your practice so far

Check an answer to see its rationale.

Teacher guidance and scoring