Race Car Katas - Leaderboard


Inspired by Emily Bache

The Situation

You just started your new job as a developer at the Ferrari Formula1 team. But you’re not really convinced by the legacy code-base. Now you want to write unit tests for them, and that is harder than it needs to be. The code snippet fails to follow one or more of the SOLID principles.

For this exercise, you should identify which SOLID principles are violated. There is only one class you are interested in writing tests for right now. As a first step, try to get some kind of test in place before you change the class at all. If the tests are hard to write, is that because of the problems with SOLID principles?

When you have some kind of test to lean on, refactor the code and make it testable. Take care when refactoring not to alter the functionality, or change interfaces which other client code may rely on. (Imagine there is client code in another repository that you can’t see right now). Add more tests to cover the functionality of the particular class you’ve been asked to get under test.

Apply the unit testing style and framework you are most comfortable with. You can choose to use stubs or mocks or none at all. If you do, you are free to use the mocking tool that you prefer.

Your Task

Write the unit tests for the Leaderboard class, including races with self driving cars. The Leaderboard calculates driver points and rankings based on results from a number of races.

Get the Code

On GitHub (This kata can be done using C, C#, C++, Go, Kotlin, Java, JavaScript, PHP, Python, Ruby, Scala, Swift, TypeScrpt) If your favorite language is missing, feel free to create a pull request. Be sure the maintainer will be happy ;-)

Image credits

Image by Rachel M. Carmena. It represents a greeting of respect and gratitude made at the beginning and at the end of a kata.