The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

    • RT @lucpluijmen76: Zorgeconoom die meewerkte aan voorbereiden en instandhouden van het zorgstelsel, dat fundamenteel gebaseerd is op wantro… 6 minutes ago
    • RT @JacquelineAvun: KLM had in 2022 helemaal geen gebruik moeten maken van de NOW-regeling, KLM had die NOW-subsidie nl helemaal niet nodig… 15 minutes ago
    • RT @Unusual_Times: There are people on here I've developed a genuine fondness for over time. So i say this from the heart. Try your best no… 15 minutes ago
    • RT @timsneath: Microsoft has created so many UI frameworks: Blazor, Razor, .NET MAUI / Xamarin Native / Xamarin Forms, WinUI3, UWP, Win32,… 21 minutes ago
    • RT @IanColdwater: just reviewed a resume from a very junior dev, and I've been on both sides of this now: it's common for people trying to… 23 minutes ago
  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 4,180 other subscribers

Unittesting FizzBuzz

Posted by jpluimers on 2021/02/23

Keep a version history of how you approach the below TDD driven approach, then discuss it with one of your co-workers.

Note there is no “right” approach, though probably you will experience that some environments and approaches may lead to code that is better, for instance because it is:

  • easier to explain
  • shorter
  • more performant

The above 3 might points bite each other (;

Based on FizzBuzz: One Simple Interview Question – YouTube.

Write initial tests

Write unit tests for this unit under test in pseudo code:

type OutputMethod: method(string Value)
class FizzBuzzGame:
    method Construct(OutputMethod Value)
    method Process(int Value)

Unit test that captures Output with a certain set of Values, then tests for the four possible combinations:

  • number
  • Fizz
  • Buzz
  • FizzBuzz

and also ensures that the passed OutputMethod is being called once for each call to Process.

Extend the tests

Now extend the tests to cover the below multiples and all the permutations caused by the longer list. Think carefully about the permutations.

  • 3 -> Fizz
  • 5 -> Buzz
  • 7 -> Fuzz
  • 11 -> Bizz
  • 13 -> Biff

Write the unit under test

The least tricky bit should be this step.

Be sure to test the solution with your co-workers as well.

Non positive numbers.

Did you think about negative numbers?

Did you think about the number zero?

What would you do about them in the tests and unit under test?



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: