December 17, 2018

...Learn TDD with Codemanship

The Santa Present Delivery Route Optimisation Kata

The holiday season is upon us, and one of the upsides of running a training company is that - while your clients run themselves ragged trying to hit seasonal deadlines - you get to relax and enjoy the inverse level of busyness.

This gives me time to imagine a fun but challenging new code kata: The Santa Present Delivery Route Optimisation Kata. It's a TDD challenge, but also a Third-Generation Testing challenge, as you'll see.

Santa has to visit the ten biggest cities in the US, listed here with their populations and coordinates:

New York
40.6635°N 73.9387°W

Los Angeles
34.0194°N 118.4108°W

41.8376°N 87.6818°W

29.7866°N 95.3909°W

33.5722°N 112.0901°W

40.0094°N 75.1333°W

San Antonio
29.4724°N 98.5251°W

San Diego
32.8153°N 117.1350°W

32.7933°N 96.7665°W

San Hose
37.2967°N 121.8189°W

Santa's sleigh travels at a constant speed of 3,000 km per hour between cities, and the delivery of each present takes him 0.001 seconds (i.e., he can deliver 3.6 million presents an hour in the same city.)

He has between midnight and 6 a.m. to deliver as many presents in the US as possible. He can start in any of the 10 cities.

Using this information, create a program that will efficiently calculate the route that will deliver the most amount of presents in those 6 hours.

Using parameterised tests, check your program's solution against the result of an exhaustive search of all possible routes between the 10 cities (assuming each city is visited only once).

Now generalise your solution for the following variables:

1. The list of cities

2. The amount of available delivery time

3. The speed of Santa's sleigh

4. The number of concurrent Santas

Posted 3 months, 4 days ago on December 17, 2018