Curriculum

Curriculum

Pinpoint the Failing Branch with a Step Trace

Scenario

Input: freeSeats = 2, hasPermission = false, isMaintenance = false. Expected: false. Actual buggy code returned true. Trace the buggy function line by line.

  1. 1Step 1 · Check if isMaintenance is true
  2. 2Step 2 · Check freeSeats > 0 || hasPermission
  3. 3Step 3 · Return decision

Try it yourself

Step through each decision to find the exact branch where actual diverges from expected.

Reveal the explanation
  1. Step 1 · Check if isMaintenance is true

    isMaintenance is false → continue to next check (matches expected).

  2. Step 2 · Check freeSeats > 0 || hasPermission

    Divergence found! Buggy code used OR instead of AND, so freeSeats = 2 made it true.

  3. Step 3 · Return decision

    Buggy code returns true instead of false; root cause is isolated to Step 2.

A step trace replaces random edits with proof. Once you see the first line where the actual path splits from the expected path, you know the exact line to fix.

Review first

Your turn

Trace a library checkout bug where (isAvailable=false, borrowedCount=1) wrongly returned true using `if (isAvailable || borrowedCount < 3)`.

Common mistake Changing multiple lines at once before finding which branch first disagreed with the expected trace.

Check your work

A 3-step trace showing Step 1 evaluates `isAvailable || borrowedCount < 3` as `false || true -> true`, isolating the `||` operator.

Quick check

When tracing a failing input through three branches, which line is the root cause to inspect first?
Show the answer and reasoning

Correct answer The first branch where the actual path diverges from the expected path

Fixing the first divergence point stops the wrong path before downstream steps even run.