Created
July 12, 2018 03:09
-
-
Save JayBazuzi/4421d3b354bcb64502b3b1a05e460c59 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using FluentAssertions; | |
using Microsoft.VisualStudio.TestTools.UnitTesting; | |
namespace UnitTestProject1 | |
{ | |
[TestClass] | |
public class UnitTest1 | |
{ | |
[TestMethod] | |
public void Test1ReturnsStringOne() | |
{ | |
var subject = new FizzBuzzer(); | |
var result = subject.Emit(1); | |
result.Should().Be("1"); | |
} | |
[TestMethod] | |
public void TestMultiplesOf3ReturnStringFizz() | |
{ | |
var subject = new FizzBuzzer(); | |
var A_MULTIPLE_OF_THREE = 2 * 3; | |
var result = subject.Emit(A_MULTIPLE_OF_THREE); | |
result.Should().Be("Fizz"); | |
} | |
[TestMethod] | |
public void TestMultiplesOf5ReturnStringBuzz() | |
{ | |
var subject = new FizzBuzzer(); | |
var A_MULTIPLE_OF_FIVE = 2 * 5; | |
var result = subject.Emit(A_MULTIPLE_OF_FIVE); | |
result.Should().Be("Buzz"); | |
} | |
[TestMethod] | |
public void TestMultiplesOf3And5ReturnStringFizzBuzz() | |
{ | |
var subject = new FizzBuzzer(); | |
var A_MULTIPLE_OF_THREE_AND_FIVE = 3 * 5; | |
var result = subject.Emit(A_MULTIPLE_OF_THREE_AND_FIVE); | |
result.Should().Be("FizzBuzz"); | |
} | |
} | |
public class FizzBuzzer | |
{ | |
public string Emit(int value) | |
{ | |
if (value.IsMultipleOf(3 * 5)) | |
{ | |
return "FizzBuzz"; | |
} | |
if (value.IsMultipleOf(3)) | |
{ | |
return "Fizz"; | |
} | |
if (value.IsMultipleOf(5)) | |
{ | |
return "Buzz"; | |
} | |
return value.ToString(); | |
} | |
} | |
public static class Extensions | |
{ | |
public static bool IsMultipleOf(this int @this, int divisor) => @this % divisor == 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment