Curriculum

Curriculum

Extend the Booking Checker with Group Size and Invalid Guards

Scenario

Contract `canBookGroup(freeSeats, requestedSeats, hasPermission)`: valid when `freeSeats` is integer >= 0, `requestedSeats` is integer >= 1, and `hasPermission` is boolean; accepts iff `hasPermission && requestedSeats <= freeSeats`. Otherwise returns `INVALID_GROUP_BOOKING`.

Selected choicePick a choice below
Result—

Try it yourself

Compare each case against the extended booking contract.

Reveal the explanation
  1. freeSeats = 4, requestedSeats = 4, hasPermission = true

    Accept (true). Exact capacity fit is allowed.

  2. freeSeats = 4, requestedSeats = 5, hasPermission = true

    Decline (false). Group exceeds available seats by 1.

  3. freeSeats = 4, requestedSeats = 0, hasPermission = true

    Error: INVALID_GROUP_BOOKING. A group must request at least 1 seat.

Adding `requestedSeats` generalizes single-seat booking (`requestedSeats = 1`) while explicit guards stop zero or negative group sizes from passing silently.

Review first
Download shared test cases

Your turn

Implement `canBookGroup` in Python or JavaScript and run all 6 cases in `fixture-extended-group-booking`.

Common mistake Allowing `requestedSeats = 0` to return `true` because `0 <= freeSeats` evaluates true.

Check your work

Working function, passing test output covering exact fit, over-capacity, no permission, and `requestedSeats = 0` error.

Project brief

Basic
Implement `canBookGroup` with exact-fit (`<=`) and permission checks plus 4 core tests.
Intermediate
Add explicit `INVALID_GROUP_BOOKING` validation for `requestedSeats < 1`, `freeSeats < 0`, and wrong types.
Stretch
Return remaining seats after an accepted booking while leaving state unchanged on decline.

What to hand in

Include your diagram, expected-result table, code, actual test output, and the commit or diff you reviewed.

Review criteria

  • Logic · Your diagram shows every required path and boundary.
  • Verification · The tests exercise the stated acceptance cases and the recorded results match the code.
  • Review · The change is focused and you can explain the decision it implements.

Quick check

Why must `requestedSeats = 0` be rejected with `INVALID_GROUP_BOOKING` instead of evaluating `0 <= freeSeats`?
Show the answer and reasoning

Correct answer Without the guard, `0 <= 4` would wrongly accept a zero-person booking

Validating `requestedSeats >= 1` first prevents meaningless bookings from slipping through `requestedSeats <= freeSeats`.