AI with MattLearn as you work.Member area

There are four seats left.
Why can’t I book them?

A booking app says no even when there is enough room. Follow a small fix and see how to check that the last four seats can be booked.

The task

There are 10 seats and six are taken. Someone asks for the four seats left. The app should allow it, but the original code says no.

Ask a question you can check.

The app has four seats left, but it will not let someone book all four. Find out why. Make the smallest change that fixes it. Check that booking too many seats is still blocked. Explain what you changed and what you actually checked.

The download contains sample inputs and an authored explanation. It does not contain the full member skill instructions. Supply your actual context when using the corresponding workflow.

What should you check?

Try booking four seats: it should work. Try booking five: it should be blocked. This lesson explains a code-only teaching sample. For a useful app you can try in your browser, open the project estimate tool.

Optional: see the code and automatic checks

Follow the finding back to the rule.

  1. State the expected boundary.

    Capacity 10, reserved 6 and requested 4 should be allowed: the request uses exactly the four remaining seats.

  2. Inspect the faulty expression.

    src/before.js checks requested < capacity - reserved. At this boundary, 4 < 4 is false. The finding follows from the supplied contract.

  3. Change the comparison, then check it.

    src/after.js changes only the final comparison to <=. The same test suite checks the correction.

Before

// Contract: nonnegative integer quantities; a request may use the final seat.
export function canReserve(capacity, reserved, requested) {
  if (![capacity, reserved, requested].every(Number.isInteger) ||
      capacity < 0 || reserved < 0 || requested <= 0 || reserved > capacity) return false;
  return requested < capacity - reserved;
}

After

// Contract: nonnegative integer quantities; a request may use the final seat.
export function canReserve(capacity, reserved, requested) {
  if (![capacity, reserved, requested].every(Number.isInteger) ||
      capacity < 0 || reserved < 0 || requested <= 0 || reserved > capacity) return false;
  return requested <= capacity - reserved;
}

Reproduce both results.

From the extracted code-review folder:

node check.js before
node check.js after

The before command deliberately exits 1: three tests pass, one fails. That failure is the demonstration. The after command exits 0: all four tests pass. Both results were observed on the included source. Saved failure output uses sample-relative paths in place of the local checkout directory.

Read the actual failing test output
TAP version 13
# Subtest: a request below the remaining capacity is allowed
ok 1 - a request below the remaining capacity is allowed
  ---
  duration_ms: 0.442064
  type: 'test'
  ...
# Subtest: a request over capacity is denied
ok 2 - a request over capacity is denied
  ---
  duration_ms: 0.070292
  type: 'test'
  ...
# Subtest: invalid quantities are denied
ok 3 - invalid quantities are denied
  ---
  duration_ms: 0.061426
  type: 'test'
  ...
# Subtest: a request may use exactly the final remaining seats
not ok 4 - a request may use exactly the final remaining seats
  ---
  duration_ms: 0.423328
  type: 'test'
  location: 'code-review/test/booking.test.js:10:1'
  failureType: 'testCodeFailure'
  error: |-
    Expected values to be strictly equal:
    
    false !== true
    
  code: 'ERR_ASSERTION'
  name: 'AssertionError'
  expected: true
  actual: false
  operator: 'strictEqual'
  stack: |-
    TestContext.<anonymous> (code-review/test/booking.test.js:10:74)
    Test.runInAsyncScope (node:async_hooks:214:14)
    Test.run (node:internal/test_runner/test:1047:25)
    Test.processPendingSubtests (node:internal/test_runner/test:744:18)
    Test.postRun (node:internal/test_runner/test:1173:19)
    Test.run (node:internal/test_runner/test:1101:12)
    async Test.processPendingSubtests (node:internal/test_runner/test:744:7)
  ...
1..4
# tests 4
# suites 0
# pass 3
# fail 1
# cancelled 0
# skipped 0
# todo 0
# duration_ms 40.289435
Read the actual corrected test output
TAP version 13
# Subtest: a request below the remaining capacity is allowed
ok 1 - a request below the remaining capacity is allowed
  ---
  duration_ms: 0.513389
  type: 'test'
  ...
# Subtest: a request over capacity is denied
ok 2 - a request over capacity is denied
  ---
  duration_ms: 0.073439
  type: 'test'
  ...
# Subtest: invalid quantities are denied
ok 3 - invalid quantities are denied
  ---
  duration_ms: 0.065944
  type: 'test'
  ...
# Subtest: a request may use exactly the final remaining seats
ok 4 - a request may use exactly the final remaining seats
  ---
  duration_ms: 0.053772
  type: 'test'
  ...
1..4
# tests 4
# suites 0
# pass 4
# fail 0
# cancelled 0
# skipped 0
# todo 0
# duration_ms 36.496289

Keep the conclusion bounded.

This finding establishes a specific mismatch between a pure function and its stated contract. The tests cover ordinary, over-capacity, exact-capacity and selected invalid inputs. The sample does not store bookings or coordinate concurrent requests; it proves no database, authorization or production-concurrency property.

Follow the member review path

Bring the checking habit to your own task.

Use your own permitted material, make the intended outcome explicit and inspect the result. Membership adds full available skills, setup guidance and starter paths; these samples remain free.