Skip to content

Commit 40b245b

Browse files
committed
Add README for gilded traffic light kata
1 parent 363baa1 commit 40b245b

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# The Gilded Traffic Light
2+
3+
Refactor a messy legacy traffic light system into a proper domain model.
4+
5+
You’ll start with a single-file procedural Ruby script that simulates an intersection with two directions of traffic lights and pedestrian signals. Your job is to gradually extract meaningful objects and ensure the behaviour doesn't change.
6+
7+
## Problem Description
8+
9+
Imagine a simplified but messy traffic controller. We have:
10+
11+
- Two directions of traffic (North-South and East-West).
12+
- Each direction cycles through Red → Green → Amber → Red.
13+
- Pedestrian signals can only display “WALK” when that direction is red.
14+
15+
In the provided code, everything (timers, states, and transitions) is lumped into one file and one giant method. Refactor it into a more object-oriented design, preserving functionality.
16+
17+
## Requirements and Constraints
18+
19+
### Requirements
20+
21+
- The system should prevent conflicting green lights and only allow pedestrians to cross on red.
22+
- The code must run forever unless interrupted.
23+
- Do not break the existing console output or sequence logic.
24+
- Preserve the timers for each colour transition.
25+
26+
### Constraints
27+
28+
- You must not remove or skip any stage of the light cycle (Red, Green, Amber).
29+
- Keep the pedestrian signals tied to the traffic light states.
30+
31+
## Examples and Test Cases
32+
33+
A sample test file has been provided. Ensure these tests continue to pass as you refactor and rearrange the code.
34+
35+
## Instructions
36+
37+
Open the single-file Ruby script that contains the messy procedural code.
38+
Run it directly to see the console output and confirm how the sequence changes over time.
39+
40+
Refactor the system one step at a time. Introduce appropriate classes to develop a deeper and more meaningful domain model, while preserving all the existing behaviour.
41+
42+
(Best to run the tests after each change to ensure everything still passes).
43+
44+
## Evaluation Criteria
45+
46+
- All tests pass for the final refactored solution.
47+
- Quality of design: Classes and methods have clear responsibilities.
48+
- Maintainability: Future changes (e.g. adding more directions or sensors) should be straightforward.

0 commit comments

Comments
 (0)