0%

Plan, Build, and Test Programs · practice

Find Edge Cases on Purpose

A normal example shows that a program works somewhere comfortable. An edge case checks a near the limit of a rule.

The quiz plan requires every title, prompt, and expected answer to contain some usable text:

def has_usable_text(text):
    return len(text.strip()) > 0

Testing "Ocean Facts" is useful, but it cannot reveal whether the handles empty or padded text. Give those edges a turn too:

assert has_usable_text("") is False
assert has_usable_text("   ") is False
assert has_usable_text("?") is True

The one-character case matters because the requirement says non-empty, not “at least two characters.”

Common places to look

For the quiz engine, edge cases often live at:

  • exactly three questions, the minimum valid plan;

  • zero correct answers or a perfect score;

  • an empty , , or ;

  • text containing only spaces;

  • a one-character prompt or answer;

  • two prompts that match after cleaning;

  • an answer with spaces or different capitalization.

Do not add all of these blindly. Choose cases that can change the behavior promised by the requirements.

Boundary tables expose gaps

For a text rule, write a small table before code:

Original textAfter strip()Usable?
""""False
" """False
"?""?"True
" honey ""honey"True

The table makes the boundary visible: after cleaning, zero characters is unusable and one character is usable.

Test data should have a reason

Each test case should answer a question:

  • Does whitespace-only text count as empty?

  • Is the shortest non-empty prompt accepted?

  • Does cleaning preserve ordinary text?

Random values may shake the box, but a deliberate boundary case tells you exactly which hinge you are testing.

The question-count check begins passing at three questions. Which case most directly checks whether the boundary is included?

Task

Implement and test has_usable_text(text) using this contract:

  • after surrounding whitespace is removed, empty text returns False;

  • one or more remaining characters returns True.

The starter contains a with two edge-case mistakes and a cases of small . Replace every None in cases with the expected .

Keep the that checks every case’s "text" and "expected" fields with assert. Once all checks pass, print:

Boundary checks passed.

Your function must also work for text not listed in cases.