The Given5ThenBuzz test

Our next requirements state that we must return Buzz when 5 is supplied. Let's write that test:

[Fact]
public void Given5ThenBuzz()
{
// Arrange
// Act
var result = FizzBuzz(5);

// Assert
Assert.Equal("Buzz", result);
}

How might we make that test pass? Perhaps a simple ternary operator? Let's take a look at what that might look like:

private object FizzBuzz(int value)
{
return value == 3 ? "Fizz" : "Buzz";
}

You might see a problem with our algorithm already. That's OK! We're not done yet. We've only gotten as far as the tests have guided us, and so far we're passing all of our tests. Let’s move on to the next most interesting test.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.220.114.0