cs-029 — Triangle Classifier
| Field | Value |
|---|---|
| id | cs-029 |
| difficulty | Beginner |
| topics | testing, boundaries |
| lecture | lecture-08 |
| estimated time | 5-minute attempt + 10-minute discussion |
| prerequisites | none |
| objective | state inputs, outputs, and assumptions, then solve a small instance by hand |
| solution | held by the instructor; discussed after the attempt |
Problem
Classify a triangle from three sides. Design the full test set: equilateral, isosceles, scalene, degenerate, impossible — before looking at any implementation.
Your deliverable is the complete test table with expected outputs, the boundary rationale, and the automated run result. If the problem is ambiguous anywhere, state the assumption you are making and carry on — a stated assumption is part of a good answer.
Examples
- Input: sides (3,4,5), (5,5,5), (2,2,3), (1,2,3), (1,1,10), (0,4,4)
- Output: scalene; equilateral; isosceles; degenerate (1+2=3); impossible; invalid (zero side)
Solve for the worked instance first. Then ask what would change if one number, name, or condition were replaced by something stranger.
What to notice
- Write the verdict table BEFORE the function; the rows where the spec is silent are the discussion.
- A test case is a falsifiable claim about the requirement.
- Boundaries are where specifications and implementations disagree.
Discussion starter
After the solution is revealed, the class spends five minutes on this prompt: "What would a 'suite' that can never fail tell you about its tests?"
Constraints and assumptions
- Difficulty: Beginner (no prior experience assumed).
- Topics: testing, boundaries.
- Classroom-scale inputs unless the problem says otherwise.
- Time-box: about five minutes for a first attempt; partial answers with clear reasoning are worth more than silent struggling.
- Optional stretch (not required): describe an alternative approach and say when it beats the obvious one.
Hints and extension
- First nudge: identify the pattern the worked instance uses before computing anything.
- If stuck after three minutes, write the input/output line you expect and trace the smallest example by hand.
- After the reveal, attempt the extension below before the next lecture.
- Extension challenge: Add two boundary rows to your test table and justify each.