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 Contract Test Is the Only Witness the Agent Cannot Author
A test the agent wrote against code the same agent wrote shares the agent's blind spot: a misunderstanding in the implementation becomes a matching misunderstanding in the test, the bar goes green, and the bug ships certified. Consumer-driven contract tests are the only category where a second team publishes the assertion the first team has to satisfy. That separation of authorship is exactly what tamper-resistant test design demanded, applied at the integration seam. - Cohesion Is the Coverage of the Agent Era
Agent-generated codebases pass every structural-modularity metric while fragmenting the domain concept the team was trying to encode. Coverage measured whether a line ran. Mutation score measured whether an assertion pinned behavior. Cohesion is the next axis, and it measures whether the codebase's concepts are traversable end-to-end.