• Stars
    star
    112
  • Rank 301,866 (Top 7 %)
  • Language
    Python
  • License
    MIT License
  • Created about 11 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Kata exercise. This one involves writing code to reserve seats on a train.

Kata: Train Reservation

Railway operators aren't always known for their use of cutting edge technology, and in this case they're a little behind the times. The railway people want you to help them to improve their online booking service. They'd like to be able to not only sell tickets online, but to decide exactly which seats should be reserved, at the time of booking.

You're working on the "TicketOffice" service, and your next task is to implement the feature for reserving seats on a particular train. The railway operator has a service-oriented architecture, and both the interface you'll need to fulfill, and some services you'll need to use are already implemented.

All the starting code for this kata is available in my github repo. The latest version of these instructions is also there.

Business Rules around Reservations

There are various business rules and policies around which seats may be reserved. For a train overall, no more than 70% of seats may be reserved in advance, and ideally no individual coach should have no more than 70% reserved seats either. However, there is another business rule that says you must put all the seats for one reservation in the same coach. This could make you and go over 70% for some coaches, just make sure to keep to 70% for the whole train.

The Guiding Test

The Ticket Office service needs to respond to a HTTP POST request that comes with form data telling you which train the customer wants to reserve seats on, and how many they want. It should return a json document detailing the reservation that has been made.

A reservation comprises a json document with three fields, the train id, booking reference, and the ids of the seats that have been reserved. Example json:

{"train_id": "express_2000", "booking_reference": "75bcd15", "seats": ["1A", "1B"]}

If it is not possible to find suitable seats to reserve, the service should instead return an empty list of seats and an empty string for the booking reference. The test cases in guiding_test.py outline the expected interface. (For Python 2.x users, there is also a version called 'python2_guiding_test.py')

Command line option

If you think it's too hard to come up with a fully deployed HTTP service, you could instead write a command line program which takes the train id and number of seats as command line arguments, and returns the same json as above.

Booking Reference Service

You can get a unique booking reference using a REST-based service. For test purposes, you can start a local service using the provided code in the "booking_reference_service" folder. You can assume the real service will behave the same way, but be available on a different url.

Install Python 3.3 and CherryPy, then start the server by running:

python booking_reference_service.py

You can use this service to get a unique booking reference. Make a GET request to:

http://localhost:8082/booking_reference

This will return a string that looks a bit like this:

75bcd15

Train Data Service

You can get information about which each train has by using the train data service. For test purposes, you can start a local service using the provided code in the "train_data_service" folder. You can assume the real service will behave the same way, but be available on a different url.

Again, you need Python 3.3 and CherryPy, then start the server by running:

python start_service.py

You can use this service to get data for example about the train with id "express_2000" like this:

http://localhost:8081/data_for_train/express_2000

this will return a json document with information about the seats that this train has. The document you get back will look for example like this:

{"seats": {"1A": {"booking_reference": "", "seat_number": "1", "coach": "A"}, "2A": {"booking_reference": "", "seat_number": "2", "coach": "A"}}}

Note I've left out all the extraneous details about where the train is going to and from, at what time, whether there's a buffet car etc. All that's there is which seats the train has, and if they are already booked. A seat is available if the "booking_reference" field contains an empty string. To reserve seats on a train, you'll need to make a POST request to this url:

http://localhost:8081/reserve

and attach form data for which seats to reserve. There should be three fields:

"train_id", "seats", "booking_reference"

The "seats" field should be a json encoded list of seat ids, for example:

'["1A", "2A"]'

The other two fields are ordinary strings. Note the server will prevent you from booking a seat that is already reserved with another booking reference.

The service has one additional method, that will remove all reservations on a particular train. Use it with care:

http://localhost:8081/reset/express_2000

More Repositories

1

GildedRose-Refactoring-Kata

Starting code for the GildedRose Refactoring Kata in many programming languages.
C++
3,428
star
2

Tennis-Refactoring-Kata

This is a Refactoring Kata based on the rules of Tennis
TypeScript
649
star
3

Racing-Car-Katas

The starting code for several code katas on a racing car theme
Java
267
star
4

Theatrical-Players-Refactoring-Kata

Example from first chapter of 'Refactoring' by Martin Fowler, with tests and translations
C++
153
star
5

Parrot-Refactoring-Kata

Kata to learn about Polymorphism
XSLT
106
star
6

Yatzy-Refactoring-Kata

Starting code for a Refactoring Code Kata on the Yatzy rules
C++
93
star
7

SupermarketReceipt-Refactoring-Kata

This is a refactoring kata for improving your coding skills
C#
84
star
8

Phone-Numbers-Kata

Some sample data you could use to help test your solution to the Phone Numbers code kata, and a script to create it.
Python
36
star
9

Product-Export-Refactoring-Kata

exercise for practicing refactoring
C
21
star
10

Lift-Kata

starting position for the Lift Kata with an Approval Testing approach
C++
21
star
11

Clarify-Exception-Refactoring-Kata

For practicing refactoring, removing duplication, and making code more flexible
Java
19
star
12

DiamondKata

skeleton solution and test cases for comparing iterative and incremental approaches
PHP
19
star
13

Online-Shopping-Kata

Refactoring Kata to practice teasing out incohesive, coupled code
PHP
18
star
14

CustomerSync-Refactoring-Kata

Refactoring exercise where data layer and business layer are not clearly separated
Java
18
star
15

Email-Sender-Refactoring-Kata

Code from Michael Feathers presentation about "Tell, Don't Ask" at Craft 2019
Java
18
star
16

Necklace-Refactoring-Kata

the goal is to practice refactoring to a Chain of Responsibility pattern
Java
17
star
17

Hands-On-Approval-Testing-For-Developers-Materials

exercises for this training course offered via O'Reilly
Java
17
star
18

ValidateAndAddProduct-Refactoring-Kata

a kata for practicing both testing with Combination Approvals and 'Split Phase' refactoring
Java
14
star
19

vsftpd-server

docker image for vsftpd ftp server
Shell
13
star
20

OvertimeCalculation-Refactoring-Kata

a refactoring exercise with a complex conditional for dividing overtime hours into two rates
Java
12
star
21

StrangeCharacters-TestDesign-Kata

for writing tests that check correct objects are included in a list
C++
11
star
22

DeliveryController-Refactoring-Kata

refactoring kata where you need a mock or stub
Java
10
star
23

KataMedicineClash

Sample solution and graph visualization code for the MedicineClash Code Kata
Python
10
star
24

Scrabble-Kata

starting code and instructions to help you with the Scrabble kata
Ruby
9
star
25

Horse-Kata

An exercise for practicing Test-Driven Development
C#
8
star
26

IceCreamForecasting-Refactoring-Kata

an exercise for getting awkward code under test
Python
8
star
27

TimerExpiry-Refactoring-Kata

exercise to practice removing duplication
C
8
star
28

ApprovalTools

useful little scripts
Python
7
star
29

Single-Sign-On-Kata

a kata useful for understanding Test Doubles
C++
7
star
30

LeapYearTestExamples

Documents a variety of ways to write unit tests for the Leap Year Kata
Java
7
star
31

DungeonEscape-Refactoring-Kata

Write tests for a command line program that takes user input.
C
7
star
32

FancyCommand-Refactoring-Kata

For practicing refactoring techniques like 'peel' and approval testing xml
C#
7
star
33

Encryptor-Refactoring-Kata

refactoring kata
C#
6
star
34

personnummer

library for generating Swedish personal numbers for testing purposes
Python
6
star
35

FizzBuzzKata-Samples

Some sample solutions to the FizzBuzz Kata, to provoke discussion.
C++
5
star
36

BeeFriendly

app for learning about testing in a microservices architecture
Python
5
star
37

RefactoringGolf

Practice using your refactoring tools with 'before' and 'after' code snippets
Java
5
star
38

SafeCalculator-TestDesign-Kata

the code has a bug and needs some unit tests. You'll need a test double too.
CMake
5
star
39

Yatzy-Vendor-Assessment-Kata

Exercise in finding bugs in three competing implementations of the Yatzy rules
Java
4
star
40

Approvals-Puzzles

Which of these programs are suitable to be tested with Approval Testing?
Python
4
star
41

Theater-Kata

Java
4
star
42

CashMachine-Refactoring-Kata

sample code for explaining the Law of Demeter
C#
4
star
43

K8sAudit-Kata

an exercise for practicing TDD when you have dependencies on a REST API and a file system
4
star
44

starter

empty starting projects in various languages
C
4
star
45

EventParserDesignKata

For better understanding that how you set up your tests changes the design of your production code.
Java
4
star
46

LockController-Refactoring-Kata

for practicing testing a class with awkward dependencies
Kotlin
4
star
47

Refactor-Conditionals

some examples of ways to refactor conditional statements
C++
4
star
48

pytest-approvaltests

Plugin to configure pytest for use with approval tests
Python
4
star
49

Phonebook-Python-Example-Project

example project using Python and Pytest with standard layout of files
Python
4
star
50

MarsRover-Kata

Sample solution to the Mars Rover Kata with different testing approaches
Python
4
star
51

VendingMachine-Approval-Kata

An exercise for learning about Approval testing and in particular designing a printer
C++
4
star
52

Spiral-Refactoring-Kata

This code works but could do with some attention to make it more readable and maintainable.
Kotlin
3
star
53

Encode-TestDesign-Kata

the code works and the tests pass, can you make the code easier to maintain?
C++
3
star
54

EnvironmentalControllerKata

sample code for discussing test design principles
C++
3
star
55

gothpy-katas

A collection of code (mostly katas) done at the GothPy meetings
Python
3
star
56

Cloud-Migration-Refactoring-Kata

Exercise in good use of test doubles and the dangers of mandating 80% test coverage
Java
3
star
57

FIRST-Test-Design-Kata

to practice writing test cases that follow the FIRST principles
CMake
3
star
58

FizzBuzz-Refactoring-Kata

For practicing "make the change easy, then make the easy change"
C#
3
star
59

TicTacToe-Kata

Starting code for the TicTacToe Kata including a printer for the board
Python
3
star
60

UI-Katas

Kata exercises that have user interfaces.
Java
3
star
61

Roadload-Refactoring-Kata

A calculation with some duplication and no tests
C#
3
star
62

Yatzy-Approval-Kata

Excercise to help you learn how to use approval testing and TextTest in particular
Python
3
star
63

DiscountApplier-TestDesign-Kata

the code has bugs and needs some unit tests. You'll need a test double too.
C
3
star
64

Device-Driver-Kata

a Kata for practicing the use of Mocks
C
3
star
65

RecentlyUsedList-Test-Design-Kata

for practicing test design, fixtures in particular
C++
2
star
66

GameOfLife-Refactoring-Kata

Code that works but which could do with some attention to make it more readable and maintainable.
Kotlin
2
star
67

StrangeCharacters-Refactoring-Kata

refactoring exercise to practice extract method and extract class
C++
2
star
68

VoidFunctionNoArgs-Refactoring-Kata

exercise to practice getting a void function with no arguments under test and refactored
Java
2
star
69

patients

Sample application for testing
Ruby
2
star
70

Recently-Used-List-Docs

practice writing user documentation based on unit tests
C++
2
star
71

GildedRose-Approval-Kata

Same problem code as for GildedRose-Refactoring-Kata, but set up for TextTest Approval tests
Java
2
star
72

ApprovalTests.Python

python port of the ApprovalTests library http://approvaltests.sourceforge.net/
Python
2
star
73

sbt-texttest

SBT plugin that can run texttests in your sbt projects.
Scala
2
star
74

buildstats

keep track of how long the build is taking
Python
2
star
75

ChainOfResponsibility-Pets

A lighthearted codebase to remind you what a Chain Of Responsibility design pattern looks like
Java
2
star
76

WikiSearchKata

a kata for practicing a refactoring: template method -> strategy pattern
Python
2
star
77

Yatzy-Prompts

for introducing typist and navigator roles
C#
2
star
78

MarsRover-Screencast

the repo I used when I recorded myself solving this kata in Java
Java
2
star
79

ShoppingBasket-TDD-Kata

Starting code for doing the Shopping Basket kata with TDD https://sammancoaching.org/kata_descriptions/shopping_basket.html
Java
2
star
80

MetricTables-Kata

starting position for a from-scratch TDD exercise
Python
2
star
81

TestDesign-Samples

some examples to get you thinking about test design.
C++
1
star
82

TrigMath-Kata

some code for trig math calculations that you should add tests for, as an exercise
C++
1
star
83

PipelineSimulation

Python
1
star
84

Screencast-Katas

The code I end up with after doing a screencast
Python
1
star
85

CalcStats-TestDesign-Kata

for practicing test design using https://sammancoaching.org/kata_descriptions/calc_stats.html
C
1
star
86

TirePressure-Kata

split out from RacingCarKatas to make it simpler to get set up
CMake
1
star
87

Instavoiced-Architecture-Kata

Materials to supplement this kata
1
star
88

ShoppingBasket-Test-Design-Kata

to practice making full use of your test framework to get the best possible feedback when you have a bug
C++
1
star
89

RPG-Combat-Approval-Kata

starting position for the RPG Combat Kata with an approval testing approach
C++
1
star
90

MarsRover-Sample-Tests

sample tests for mars rover kata, for review
C++
1
star
91

texttest-maven-plugin

Plugin to enable you to run tests created with TextTest as part of a maven build.
Java
1
star
92

Supermarket-Kata-Sample-Tests

Sample test cases for Supermarket Kata, for review and discussion
C#
1
star
93

SupermarketReceipt-Java

just the java version of this refactoring kata
Java
1
star
94

ClosestToZero-Parameterized

practice writing parameterized tests and interpreting failures
Go
1
star
95

HandbagEvent-Refactoring-Kata

Exercise to practice sorting out a bumpy road smell
Python
1
star