Skip to content

Commit 0c26d8a

Browse files
Add TDD assignment questions for booking system
Added TDD assignment questions for a hotel room booking system, covering basic operations, modifications, pricing, and advanced features.
1 parent 630b7b7 commit 0c26d8a

1 file changed

Lines changed: 154 additions & 0 deletions

File tree

  • examples/with-unittest/booking_system
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
Here are some TDD assignment questions for a booking system:
2+
3+
## Assignment: Hotel Room Booking System (TDD Approach)
4+
5+
### Part 1: Basic Booking Operations
6+
7+
**Question 1: Create a Booking**
8+
Implement functionality to create a new booking. A booking should have:
9+
- Guest name
10+
- Room number
11+
- Check-in date
12+
- Check-out date
13+
- Booking reference (auto-generated unique ID)
14+
15+
Write tests first that verify:
16+
- A booking can be created with valid data
17+
- Booking reference is automatically generated and unique
18+
- Check-out date must be after check-in date
19+
- Required fields cannot be empty
20+
21+
**Question 2: Check Room Availability**
22+
Implement a method to check if a room is available for given dates.
23+
24+
Write tests for:
25+
- Room is available when no bookings exist
26+
- Room is unavailable when dates overlap with existing booking
27+
- Room is available when requested dates are before/after existing bookings
28+
- Same-day checkout and check-in (checkout at 11am, new checkin at 2pm) - decide and test your business rule
29+
30+
**Question 3: Prevent Double Booking**
31+
Implement logic to prevent booking a room that's already reserved.
32+
33+
Write tests for:
34+
- Cannot book room with exact same dates as existing booking
35+
- Cannot book room when dates partially overlap
36+
- Cannot book room when new booking spans existing booking
37+
- Cannot book room when new booking is contained within existing booking
38+
- Can book room for different dates
39+
40+
### Part 2: Booking Modifications
41+
42+
**Question 4: Cancel a Booking**
43+
Implement booking cancellation functionality.
44+
45+
Write tests for:
46+
- Successfully cancel an existing booking
47+
- Room becomes available after cancellation
48+
- Cannot cancel a booking that doesn't exist
49+
- Cannot cancel an already cancelled booking
50+
- Cancelled bookings are marked (not deleted) for audit purposes
51+
52+
**Question 5: Modify Booking Dates**
53+
Implement functionality to change check-in/check-out dates of existing booking.
54+
55+
Write tests for:
56+
- Successfully modify dates when room is available
57+
- Cannot modify if new dates overlap with another booking
58+
- Cannot modify to invalid dates (checkout before checkin)
59+
- Original booking is updated, not duplicated
60+
61+
### Part 3: Pricing & Calculations
62+
63+
**Question 6: Calculate Booking Cost**
64+
Implement cost calculation based on number of nights and room rate.
65+
66+
Write tests for:
67+
- Single night stay calculation
68+
- Multiple night stay calculation
69+
- Different room rates (standard: $100, deluxe: $150, suite: $200)
70+
- Zero or negative duration returns error
71+
72+
**Question 7: Apply Discounts**
73+
Implement discount logic for bookings.
74+
75+
Write tests for:
76+
- 10% discount for stays of 7+ nights
77+
- 15% discount for stays of 14+ nights
78+
- Weekend surcharge: 20% extra for Friday/Saturday nights
79+
- Discounts and surcharges are calculated correctly together
80+
81+
**Question 8: Calculate Refund Amount**
82+
Implement cancellation refund policy.
83+
84+
Write tests for:
85+
- Full refund if cancelled 7+ days before check-in
86+
- 50% refund if cancelled 3-6 days before check-in
87+
- No refund if cancelled within 2 days of check-in
88+
- No refund for cancellations after check-in date
89+
90+
### Part 4: Advanced Features
91+
92+
**Question 9: List Bookings**
93+
Implement methods to retrieve bookings with filters.
94+
95+
Write tests for:
96+
- Get all bookings for a specific room
97+
- Get all bookings for a specific guest
98+
- Get all bookings within a date range
99+
- Get upcoming bookings only (future check-ins)
100+
- Get active bookings (currently checked in)
101+
102+
**Question 10: Room Capacity Management**
103+
Implement guest count validation (assume rooms have max capacity).
104+
105+
Write tests for:
106+
- Room capacity limits (standard: 2, deluxe: 3, suite: 4)
107+
- Cannot book with more guests than room capacity
108+
- Can book with fewer guests than capacity
109+
- Extra guest fee: $25/night per guest above 2
110+
111+
**Question 11: Seasonal Pricing**
112+
Implement dynamic pricing based on season.
113+
114+
Write tests for:
115+
- Peak season (Dec-Feb, Jun-Aug): 1.5x base rate
116+
- Off-peak season (Mar-May, Sep-Nov): base rate
117+
- Calculate total cost correctly when booking spans seasons
118+
- Weekend surcharge applies to seasonal rate
119+
120+
**Question 12: Waitlist Management**
121+
When room is unavailable, add guest to waitlist.
122+
123+
Write tests for:
124+
- Add guest to waitlist when room unavailable
125+
- Notify/promote first waitlisted guest when booking cancelled
126+
- Remove from waitlist when they book different dates
127+
- Waitlist ordered by request date (first come, first served)
128+
129+
---
130+
131+
## Bonus Challenges
132+
133+
**Question 13: Multiple Room Booking**
134+
Allow booking multiple rooms in single reservation.
135+
136+
**Question 14: Loyalty Points**
137+
Award points: 10 points per dollar spent, implement redemption (100 points = $1 discount).
138+
139+
**Question 15: Payment Status Tracking**
140+
Track payment status: pending, partial, paid, refunded with state transitions.
141+
142+
---
143+
144+
## Instructions
145+
146+
For each question:
147+
1. **Write the test first** (Red phase)
148+
2. **Make it pass with minimal code** (Green phase)
149+
3. **Refactor** for clean code (Refactor phase)
150+
4. Run all previous tests to ensure nothing broke
151+
152+
Start simple with Question 1 and progress sequentially. Each question builds on previous functionality.
153+
154+
Which questions would you like to start with?

0 commit comments

Comments
 (0)