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`.
Try it yourself
Compare each case against the extended booking contract.
| Case | Result |
|---|---|
| freeSeats = 4, requestedSeats = 4, hasPermission = true | Select a choice above to see what happens. |
| freeSeats = 4, requestedSeats = 5, hasPermission = true | Select a choice above to see what happens. |
| freeSeats = 4, requestedSeats = 0, hasPermission = true | Select a choice above to see what happens. |
Reveal the explanation
- freeSeats = 4, requestedSeats = 4, hasPermission = true
Accept (true). Exact capacity fit is allowed.
- freeSeats = 4, requestedSeats = 5, hasPermission = true
Decline (false). Group exceeds available seats by 1.
- 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.
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
This browser could not save your progress. Changes last until you leave the page.