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. - Red-Green-Refactor Was Always a Provenance Rule
Two 2026 empirical studies land the same shape: tests generated from a task description alone catch roughly 25% of injected faults, while tests generated after the model has seen the implementation catch roughly 14%, and chain-of-thought and chain-of-verification prompting do not close the gap. Red-green-refactor's temporal order was never a workflow preference. It was a provenance claim about the test, and the agentic workflow that generates code and then back-fills tests inherits a measurable disadvantage the human discipline was always built to prevent. - Property-Based Tests Are the Guardrail Agents Need
Example-based tests encode cases an agent can enumerate and hardcode past. Property-based tests quantify over inputs the agent did not see at code-write time, which is the gap that makes the lookup-table attack more expensive than the honest fix. Properties are one layer in the enforcement stack, not the whole stack.