Metric Converter

Level: Beginner 15–30 min

Concepts: 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.

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.


  • 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.
  • Test Deletion Is a Privileged Operation
    The cheapest way for an agent to make a failing test pass is to delete it. That is logical for the agent and catastrophic for the codebase. Tests are append-only by default. Deletion needs a human author, a separate commit, and a separate review.
  • Refactor Was Always Where Compounding Lived
    Red and green were the visible two thirds of TDD. Refactor was the optional polish. Codebases that compound did the refactor pass; codebases that accrete did not. Agents skip refactor by default because it has no green-bar reward, and a year of skipped refactors is how a codebase loses its shape.