Your programs work on the inputs you expected. Today: find the inputs you didn’t — the ones that break things — and write the tests that catch them. Then a 20-minute workout reading everything so far in AP Pseudocode.
No new reading. Bring your Decision Day calculator from 2.15 — you’re about to try to break it on purpose.
Still in Programs, opening Week 4. You can write programs that decide; now you make them trustworthy. Testing is the difference between code that works on your example and code that works on everyone’s.
The program isn’t broken in the crash sense; it runs fine. It’s broken in the way that actually costs money: it accepts input it should have rejected. Finding those inputs before your users do is called testing, and it’s a real engineering skill, not an afterthought.
An edge case is an input at the boundary or outside the range you expected: the zero, the negative, the empty, the enormous, the exact boundary value. Ordinary inputs test whether your code works; edge cases test whether it’s robust.
Guarding against bad input is input validation. You already have the tool: a compound condition from 2.14. The fix for the ticket calculator is one line at the top:
age = int(input("Age? ")) if age < 0 or age > 120: print("Please enter a real age.") else: # ... the elif price chain goes here ...
age ← INPUT() IF (age < 0 OR age > 120) { DISPLAY("Please enter a real age.") } ELSE { /* the price chain */ }
Hover or tap a line to light its twin. One or catches both the
negative and the impossible-old. This is why 2.14 mattered.
< that should be <= hides.
This is the 2.15 ticket calculator with no validation. Feed it edge cases and watch it give confident, sometimes-nonsense answers. Each one is a test you should write.
Six read-only reps in AP Pseudocode — the notation the exam uses for many trace questions. No Python here on purpose. Trace each on paper, then pick an answer.
A famous 1996 rocket, Ariane 5, was destroyed seconds after launch because a number got too big for the variable holding it — an overflow edge case (you met overflow in Unit 1). Spreadsheets have turned gene names into dates. Websites have charged $0.00 because a coupon drove a price negative and nobody tested for it.
None of these were exotic. They were ordinary programs meeting an input the author never tried. “It works on my example” is the most expensive sentence in software. Testing edge cases is how professionals earn the right to say “it works.”
or guard
is last week’s tool doing real work.