Curriculum

Curriculum

Test Invalid Negative Numbers and Wrong Types

Scenario

Audit three invalid-input tests for canBook(freeSeats).

Selected choicePick a choice below
Result—

Try it yourself

Compare negative, string, and null inputs against the documented INVALID_FREE_SEATS policy.

Reveal the explanation
  1. canBook(-1)

    Must raise/return INVALID_FREE_SEATS (not silent false).

  2. canBook("2")

    Must raise/return INVALID_FREE_SEATS (blocks silent string coercion).

  3. canBook(null)

    Must raise/return INVALID_FREE_SEATS (explicit missing-data rejection).

Always assert the exact error code or message—not just "throws anything"—so a random crash cannot masquerade as a passing validation test.

Review first
Download shared test cases

Your turn

Write 3 invalid-input fixture cases for canCheckoutBook(isAvailable, borrowedCount) expecting INVALID_CHECKOUT_INPUT.

Common mistake Asserting only "throws any error" without checking the error code string.

Check your work

(true, -1), ("yes", 1), and (true, null) all produce INVALID_CHECKOUT_INPUT.

Quick check

Why should an invalid-input test verify the specific error code (like INVALID_SCORE) instead of just checking that any exception occurred?
Show the answer and reasoning

Correct answer So an accidental typo or crash cannot falsely pass as intentional input validation

Matching the documented error code proves the intended guard clause fired.