Curriculum

Curriculum

Diagnose Expected vs. Actual Assertion Failures

Scenario

Three failing test outputs appear after porting a function. Inspect each Expected vs. Actual pair to classify the cause.

Selected choicePick a choice below
Result—

Try it yourself

Compare each assertion diff and decide what kind of bug it reveals.

Reveal the explanation
  1. Expected: 3 (number) · Actual: "3" (string)

    Type mismatch. The score looks identical in text but fails strict equality.

  2. Expected: false · Actual: true (input: freeSeats = 0)

    Boundary logic bug. Both are booleans, so the comparison operator itself is wrong.

  3. Expected error: INVALID_LENGTH · Actual value: 2

    Missing guard bug. The function returned a number instead of rejecting mismatched lengths.

Reading both the type and value of Expected vs. Actual prevents chasing the wrong bug—for example, rewriting math logic when the only issue was returning a string.

Review first

Your turn

Classify `Expected: ["Ana", "Bo"] · Actual: ["Bo", "Ana"]` and state what kind of bug to look for.

Common mistake Seeing the same names and assuming the test is flaky instead of checking list order.

Check your work

Order mismatch bug: elements match, so check sorting or insertion order in the promoter loop.

Quick check

A test fails with `Expected: true (boolean), Actual: "true" (string)`. What is the bug?
Show the answer and reasoning

Correct answer A return-type mismatch: the function returned a string instead of a boolean

Both show the word true, but the types differ (string vs boolean).