Phase 6: Testing & Code Quality · ~30 minutes · Python · uv
Why Untested Code Lies to You
find_median([3, 1, 2]) works. find_median([5, 9, 1, 7, 3]) works. Nobody tried an even-length list, and the function has been silently wrong the whole time.
Real-world application: Instinctively tries empty input, single-item input, and boundary values before trusting a function works
What you will learn
- Explain the difference between 'it ran' and 'it's correct'
- Explain what a test actually asserts, as distinct from manually re-running code and eyeballing the result
- Find a real edge-case bug in a function that passed every example its author tried by hand
- Propose an input that would have caught a specific hidden bug
Introduction
- Type: Learn
- Languages: Python
- Prerequisites: Object-Oriented & Modular Thinking
- Time: ~30 minutes
Objective
Learning objectives
- Explain the difference between "it ran" and "it's correct"
- Explain what a test actually asserts, as distinct from manually re-running code and eyeballing the result
- Find a real edge-case bug in a function that passed every example its author tried by hand
- Propose an input that would have caught a specific hidden bug
What you're building
Pick one function you wrote in an earlier phase of this course (a lab from Phase 01-05 — your choice). A script (edge_case_hunt.py) that:
- Copies that function in as-is
- Tries at least 4 inputs that were not part of the original lab's test cases, specifically chosen to hit different categories: empty input, a single item, a boundary value, and one more you choose
- If you find a real bug this way, fix the function and add a comment describing exactly what was wrong and which specific input revealed it
- If you don't find a bug, that's a valid, real outcome — write a comment stating which edge cases you deliberately tried and why you believe they're the right ones to have checked
A function is_even_count(items) returns True if a list has an even number of items. It was tested on [1, 2] (True) and [1, 2, 3] (False), both passing. What's the single most valuable additional input to try, and why?
[] is exactly the category this lesson's get_last_item predict block highlighted: the input most commonly skipped by hand-testing, precisely because it doesn't look like a 'real' example. It's also a genuinely meaningful case here specifically: 0 is mathematically even, so a correct is_even_count([]) should return True — and it's easy to write an implementation that mishandles the empty case without realizing it, exactly like find_median did for even-length lists. A larger list ([1, 2, 3, 4, 5, 6]) tests the same category of logic already covered by [1, 2], just at a bigger size — new category of input matters far more than a bigger example of a category already tested.
This lesson is free
You've read the first 2 sections. The rest covers The Problem, Check Yourself, Key Terms & Next. A free account opens all of it, with its practice questions and its lab. No card.
Create a free account — the opening phases of 29 of 35 courses, and the first lesson of every phase, are free, no credit card.
Browse all courses · View pricing · DeVenture Academy