Metric Converter
Level: Beginner 15–30 minConcepts: Algorithms
Solutions: C# | TypeScript | Python
You are to write a metric to imperial unit converter. The code should only focus on the algorithms, no need to need to worry about a UI.
There are four types of conversion to be implemented:
- Kilometers to Miles
- Takes kilometers to convert and returns the result in miles
- For conversion use 1 kilometer = 0.621371 miles
- Celsius to Fahrenheit
- Takes the temperature in Celsius and returns the result in Fahrenheit
- For conversion use the following formula: (TemperatureInCelsius * 1.8) + 32
- E.g. 30C * 1.8 + 32 = 86F
- Kilogram to Pound
- Takes the number of kilograms to convert and returns pounds
- For conversion use the following formula: (Kilograms / 0.45359237)
- E.g. 5kg / 0.45359237 = 11.02311310 pounds
- Liters to Gallons
- Takes number of liters to convert and the TargetUnit (Either US or UK)
- Handles conversion to both US and UK gallon
- For US gallon use 3.785411784 liters = 1 US gallon
- For UK gallon use 4.54609 liters = 1 UK gallon
Reference Walkthrough
Reference implementations in C#, TypeScript, and Python live at tddbuddy-reference-katas/metric-converter. Thirteen scenarios cover all four conversion dimensions — length (Kilometers → Miles), temperature (Celsius → Fahrenheit, including the -40 crossover), weight (Kilograms → Pounds), and volume (Liters → US Gallons, Liters → UK Gallons) — shared across all three languages, each a single pure function convert(value, from, to) → number. A thirteenth scenario locks down that unsupported pairs raise a domain error; the converter is one-directional metric → imperial.
- C# (.NET 8, xUnit, FluentAssertions 6.12.0) — walkthrough
- TypeScript (Node 20, Vitest 1.6, TS 5 strict) — walkthrough
- Python (3.11, pytest) — walkthrough
This kata ships in Agent Full-Bake mode at high gear (F1 tier): the algorithm is small enough to land as one commit per language, with a brief walkthrough noting there are no builders — but the nine units are modelled as typed enums (C# enum, TypeScript string-literal union, Python StrEnum) rather than bare strings. The closed set of recognized units is the ubiquitous language, and a single convert(value, from, to) entry point with a pattern-matched dispatch reads as the spec sentence — “convert value from unit to unit” — instead of spreading one concept over five overloaded methods. See the repo’s Gears section for when high gear is the right call.
Related reading
- Katas Are Rehearsal, Not Performance
You don't practice TDD on production code. You practice on katas and bring the muscle memory to production. The gap between knowing TDD and doing TDD is reps. - The Test Pyramid Was an Economic Argument
The test pyramid was not a quality law. It was a cost structure: unit tests were cheap, integration tests were expensive, so you wrote many of the first and few of the second. Agents collapsed the cost of writing tests at every level, and the cheapest test that still tells the truth is the one that pins a seam the agent cannot fake. - Agents Pattern-Match Your Test Smells
Test smells used to drift in at typing speed. Agents reproduce them at generation speed because they sample whatever is already in the suite. The smells in your codebase are now the smells in your roadmap.