Technologies K–10 · Years 9–10
Testing a leap-year function with boundary cases
Computing Technology 7–10 (NSW, 2022); Digital Technologies: Processes and production skills, Generating and designing (ACARA v9)
This site has no interactive model of its own. Where a step or a material names a Concept Studio model, simulation or tool, it has not been built; an external simulation a step names (for example PhET) is not part of this site.
The idea
A program is validated by comparing its output with expected results for a planned set of test cases, and boundary cases catch errors that everyday cases miss.
What you need
- Computer with Python 3
- Test table: input year, expected result, reason for choosing it, actual result
How to do it
- Write the Gregorian rule as pseudocode: divisible by 4, except centuries, except centuries divisible by 400.
- Choose test years before coding: two ordinary years, a year divisible by 4, a century not divisible by 400, a century divisible by 400.
- Write is_leap(year) in Python and run the tests.
- Compare every result with calendar.isleap from the Python standard library.
- Write a faulty version that only checks divisibility by 4 and find which tests catch it.
- Remove the century tests and show that the faulty version then passes: explain what that says about test design.
What you should see
Correct results: 1900 False, 2000 True, 2024 True, 2026 False, 2100 False, 2400 True; calendar.isleap agrees on every year. The faulty divisible-by-4 version fails only 1900 and 2100, so a test set of 2024 and 2026 alone would pass it. The learner knows it worked when their function passes every case and their test set catches the faulty version.
What changes
This activity lists no variables to change, measure and keep the same.
Common misconceptions
Each of these ideas is wrong, and the activity is a chance to test it.
- Every year divisible by 4 is a leap year (centuries not divisible by 400 are not).
- If a program passes its tests it is correct (the tests may miss the cases that matter).
- Tests are written after the program works (planning them first shows what the program must do).
Safety card
Hazards
- None beyond normal computer use
Controls
- Not applicable
Note
No chemicals or heat.
Curriculum references
The NSW syllabus outcomes and Australian Curriculum v9 codes this activity supports. They are references, not a verified or complete curriculum alignment.
- Computing Technology 7–10 Syllabus (2022), NESA. Current elective syllabus. Code read from the outcomes page on 2026-09-22.CT5-OPL-01CT5-DPM-01
- Australian Curriculum v9AC9TDI10P06
Sources
The pages the author read to write this activity.