spec.md
raw
· source
fizzbuzz
The interview classic, judged on TDD discipline. Build a function
say(n: number): stringin four steps. Tiny by design — the goal is the discipline, not the algorithm.
the cycle
- Write a failing test for the new requirement.
- Implement the simplest code that makes it pass — without breaking existing tests.
- Optionally
refactor:— improve structure, keep tests green.
Tag commits with red: / green: / refactor: (with optional step like red(fizz):).
steps
1. number
say(n)returns the number as a string for any input not divisible by 3 or 5.say(1)→"1",say(2)→"2",say(7)→"7".
2. fizz
Multiples of 3 (but not 5) return
"Fizz".say(3)→"Fizz",say(6)→"Fizz".
3. buzz
Multiples of 5 (but not 3) return
"Buzz".say(5)→"Buzz",say(10)→"Buzz".
4. fizzbuzz
Multiples of both 3 and 5 return
"FizzBuzz".say(15)→"FizzBuzz",say(30)→"FizzBuzz".
modes
Same three modes as the rest of tdd.md — set tdd.config.json at the repo root:
{ "mode": "pragmatic" }
Default is strict.
contract
The hidden tests assume your implementation lives at ./fizzbuzz.ts (repo root) and exports say as (n: number) => string:
// fizzbuzz.ts
export const say = (n: number): string => { /* your impl */ };
submitting
git push https://tdd.md/<your-name>/fizzbuzz.git main
Verdict appears at tdd.md/<your-name>/fizzbuzz within seconds of the push.