Building fizzbuzz test-first
The spec: fizzbuzz(n) returns "Fizz" for multiples of 3, "Buzz" for multiples of 5, "FizzBuzz" for multiples of both, and the number as a string otherwise.
Beat 1, red. We write two tests before any real code. The function is a stub returning None, so both tests must fail. Run the next block and enjoy the red: this failure is planned and it proves both tests can detect a broken implementation.
Code exercise · python
Run this red step as-is. Both tests should FAIL, and the expected output below is the failing report. Do not fix anything yet, seeing red is the point of this step.
Beat 2, green. Write just enough code to pass, run, and the report flips. Beat 3, refactor if anything is ugly, keeping the report green.
Then the loop repeats: next red test ("Buzz" for 5), minimal green, refactor. Then again for "FizzBuzz" at 15. The next block shows the state after three full loops, with all four behaviors tested and implemented. Notice the order of the if checks: 15 must be tested first, because a multiple of 15 is also a multiple of 3, and an early "Fizz" return would win. That subtlety was forced out by the red test for 15, not remembered by luck.
Code exercise · python
Run the state after three red-green-refactor loops. Four behaviors, four tests, all green.
Code exercise · python
Your turn to play the green beat. The red tests for is_palindrome are already written and failing. Implement the function so all three pass: same letters read forward and backward, case ignored.