Parking Lot

Level: Intermediate 30–60 min

Concepts: DesignState

Solutions: C# | TypeScript | Python


Create a program to manage a parking lot system with different types of vehicles and parking spots.

Requirements

  1. Implement parking lot management:
    • Different types of vehicles (Motorcycle, Car, Bus)
    • Different types of parking spots (Motorcycle, Compact, Large)
    • Parking rules based on vehicle and spot types
    • Track available spots and parked vehicles
  2. Handle parking operations:
    • Park a vehicle (assign to appropriate spot)
    • Remove a vehicle (free up spot)
    • Check parking status
    • Find available spots
  3. Return appropriate results:
    • Success/failure of parking operations
    • Current parking lot status
    • Error messages for invalid operations

Test Cases

ScenarioInputExpected ResultNotes
Empty LotCheck statusAll spots availableInitial state
Park MotorcyclePark motorcycle in motorcycle spotSuccessFits in any spot
Park CarPark car in compact spotSuccessFits in compact or large
Park BusPark bus in large spotSuccessNeeds 5 consecutive large spots
Invalid ParkPark car in motorcycle spotErrorSpot too small
Remove VehicleRemove parked vehicleSuccessFrees up spot

Edge Cases to Consider

  • Parking lot is full
  • Vehicle already parked
  • Removing non-existent vehicle
  • Parking in occupied spot
  • Multiple vehicles of same type

Tips

  • Start with basic vehicle and spot types
  • Add parking rules next
  • Then implement spot management
  • Finally add status tracking
  • Consider using enums for vehicle and spot types

Reference Walkthrough

Full C#, TypeScript, and Python implementations live at tddbuddy-reference-katas/parking-lot. Twenty-two scenarios across lot construction, spot allocation (smallest-fit-first), entry with duplicate detection, exit with ticket validation, time-based fee calculation (per-hour rates by vehicle type, partial-hour ceiling, minimum one-hour charge), and an end-to-end worked example — shared across all three languages — with a Lot aggregate, Vehicle / Ticket / Fee value types, VehicleType and SpotType enums, Clock collaborator, LotBuilder + VehicleBuilder + FixedClock test doubles, and four domain exception types (VehicleAlreadyParkedException, NoAvailableSpotException, InvalidTicketException, InvalidLotConfigurationException).

  • C# (.NET 8, xUnit, FluentAssertions) — walkthrough
  • TypeScript (Node 20, Vitest, strict types) — walkthrough
  • Python (3.11, pytest, frozen dataclasses, Protocol clock) — walkthrough

This kata ships in Agent Full-Bake (F3) mode: one commit per language with the full domain design landing together. The walkthroughs read as design rationalewhy smallest-fit-first allocation preserves large spots for buses, why Fee is a value type not a bare decimal, why Clock is injected (same pattern as rate-limiter and memory-cache).

The reference simplifies the spec’s “bus needs 5 consecutive large spots” to “bus needs one large spot” — each spot is atomic, and the teaching focus is on allocation strategy and fee calculation rather than consecutive-spot search algorithms. The bonus items (floors/zones, dynamic pricing, reservation systems) are deliberately out of scope — the SpotType enum and Lot aggregate are ready to grow without the reference hiding seams under premature abstraction. See the repo’s Gears section for when middle gear is the right call.