Can you let more players join GAA training without turning away anyone who could before?
A GAA club's sign-up program lets players aged sixteen and over join training. The club wants to let fourteen- and fifteen-year-olds join if they bring an adult. How can you change the rule and check that players who could already join still get accepted?
Think of a program as taking inputs and producing an output. A unit test checks one part on its own. A function test checks whether a function meets its requirements, so calling can join directly can be both. A system test checks the whole program, from typing answers to reading the result.
Follow the code by hand. Python defines the function. Type sixteen and then no. The program stores sixteen as age and False as adult. The print line calls the function with those values. Inside, only age is checked. Sixteen meets the cutoff, so the program prints True. That's tracing.
Keep the original return line for this one. If you call can join with age fifteen and adult set to True, what does the function return? Pick the result the supplied code gives.
Predict what each version should print. Try thirteen with an adult, fourteen and fifteen with and without an adult, and sixteen alone. Run the untouched program for each row, typing the age and then yes or no. Record what it actually prints in the baseline column. Compare it with your predictions.
Keep the function name and its two inputs. On the return line, keep the check for age sixteen or over. Add a second route with or: you need to be at least fourteen and have an adult. Leave the input lines and the print call alone.
Try a fourteen-year-old with an adult. Put fourteen and True into the new rule. The sixteen check is False, but the fourteen check is True. Both parts inside the brackets are True, so the second route passes. False or True gives True.
Now try a fifteen-year-old who comes without an adult. Use the modified rule and check each route in turn. Pick the option that gives both the result and the right reason.
If you leave out the adult check, the program wrongly accepts fourteen- and fifteen-year-olds who come alone. The requested rule rejects them. Run all six planned cases again and record what the program prints. Only fourteen with an adult and fifteen with an adult should change. Keep the plan for future edits.
In the written and computer-based exam, worth seventy per cent, ‘Modify the program’ means make the requested change and leave unrelated working code alone. Check the cases that should change and those that should stay the same. When the paper says ‘Save your program as’, use the exact filename for the version you tested.