Last active
March 8, 2018 19:01
-
-
Save Programazing/9a346ca2f5711520fffea2180808b38c 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
namespace FizzBuzzChecker | |
{ | |
public string[] CheckForFizzBuzz(int[] inputs) | |
{ | |
int counter = 0; | |
string[] output = new string[inputs.Length]; | |
foreach (var number in inputs) | |
{ | |
string tempString = String.Empty; | |
//I still think 0 should print 0 but that's just me. | |
if (number % 3 == 0) { tempString += "Fizz"; } | |
if (number % 5 == 0) { tempString += "Buzz"; } | |
if (tempString == String.Empty) { tempString += number.ToString(); } | |
output[counter] += tempString; | |
counter++; | |
} | |
return output; | |
} | |
} |
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 Xunit; | |
namespace FizzBuzzChecker.Test | |
{ | |
public class FizzBuzzTests | |
{ | |
[InlineData(3, "Fizz")] | |
[InlineData(6, "Fizz")] | |
[InlineData(9, "Fizz")] | |
[InlineData(12, "Fizz")] | |
[Theory] | |
public void PrintsFizzWhenTheRemainderIsAMultipleOfThree(int numberToCheck, string expected) | |
{ | |
FizzBuzz sut = new FizzBuzz(); | |
string[] actual = sut.CheckForFizzBuzz(new int[] { numberToCheck }); | |
Assert.Equal(expected, actual[0]); | |
} | |
[InlineData(2, "Fizz")] | |
[InlineData(4, "Fizz")] | |
[InlineData(7, "Fizz")] | |
[InlineData(8, "Fizz")] | |
[Theory] | |
public void DoesNotPrintFizzWhenTheRemainderIsNotAMultipleOfThree(int numberToCheck, string expected) | |
{ | |
FizzBuzz sut = new FizzBuzz(); | |
string[] actual = sut.CheckForFizzBuzz(new int[] { numberToCheck }); | |
Assert.NotEqual(expected, actual[0]); | |
} | |
[InlineData(5, "Buzz")] | |
[InlineData(10, "Buzz")] | |
[InlineData(20, "Buzz")] | |
[InlineData(500, "Buzz")] | |
[Theory] | |
public void PrintsBuzzWhenTheRemainderIsAMultipleOfFive(int numberToCheck, string expected) | |
{ | |
FizzBuzz sut = new FizzBuzz(); | |
string[] actual = sut.CheckForFizzBuzz(new int[] { numberToCheck }); | |
Assert.Equal(expected, actual[0]); | |
} | |
[InlineData(3, "Buzz")] | |
[InlineData(6, "Buzz")] | |
[InlineData(9, "Buzz")] | |
[InlineData(12, "Buzz")] | |
[Theory] | |
public void DoesNotPrintBuzzWhenTheRemainderIsNotAMultipleOfFive(int numberToCheck, string expected) | |
{ | |
FizzBuzz sut = new FizzBuzz(); | |
string[] actual = sut.CheckForFizzBuzz(new int[] { numberToCheck }); | |
Assert.NotEqual(expected, actual[0]); | |
} | |
[InlineData(15, "FizzBuzz")] | |
[InlineData(30, "FizzBuzz")] | |
[InlineData(45, "FizzBuzz")] | |
[InlineData(60, "FizzBuzz")] | |
[Theory] | |
public void PrintsFizzBuzzWhenTheRemainderIsAMultipleOfThreeAndFive(int numberToCheck, string expected) | |
{ | |
FizzBuzz sut = new FizzBuzz(); | |
string[] actual = sut.CheckForFizzBuzz(new int[] { numberToCheck }); | |
Assert.Equal(expected, actual[0]); | |
} | |
[InlineData(1, "FizzBuzz")] | |
[InlineData(9, "FizzBuzz")] | |
[InlineData(3, "FizzBuzz")] | |
[InlineData(6, "FizzBuzz")] | |
[Theory] | |
public void DoesNotPrintsFizzBuzzWhenTheRemainderIsNotAMultipleOfThreeAndFive(int numberToCheck, string expected) | |
{ | |
FizzBuzz sut = new FizzBuzz(); | |
string[] actual = sut.CheckForFizzBuzz(new int[] { numberToCheck }); | |
Assert.NotEqual(expected, actual[0]); | |
} | |
private static int[] GenerateTestNumbers() | |
{ | |
int[] output = new int[1000]; | |
for (int i = 0; i < output.Length; i++) | |
{ | |
output[i] = i; | |
} | |
return output; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment