Created
November 18, 2015 13:30
-
-
Save jasongorman/819344924166190e8d03 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
[TestFixture] | |
public class FizzBuzzerTests | |
{ | |
[Test] | |
public void OneHundredElementsSeparatedByCommas() | |
{ | |
Assert.AreEqual(100, SplitFizzBuzzString().Length); | |
} | |
[Test] | |
public void NumbersDivisibleByThreeStartWithFizz([Range(3, 99, 3)] int number) | |
{ | |
Assert.IsTrue(GetFizzBuzzElement(number).StartsWith("Fizz")); | |
} | |
[Test] | |
public void NumbersDivisibleByFiveEndWithBuzz([Range(5, 100, 5)] int number) | |
{ | |
Assert.IsTrue(GetFizzBuzzElement(number).EndsWith("Buzz")); | |
} | |
[Test] | |
public void RemainingNumbersAreUnchanged([ValueSource("unchangedNumbers")] int number) | |
{ | |
Assert.AreEqual((number).ToString(), GetFizzBuzzElement(number)); | |
} | |
private IEnumerable<int> unchangedNumbers() | |
{ | |
return Enumerable.Range(1, 100).Where(n => n%3 != 0 && n%5 != 0); | |
} | |
private string GetFizzBuzzElement(int number) | |
{ | |
return SplitFizzBuzzString()[number - 1]; | |
} | |
private string[] SplitFizzBuzzString() | |
{ | |
return new FizzBuzzer().FizzBuzz().Split(','); | |
} | |
} | |
public class FizzBuzzer | |
{ | |
public string FizzBuzz() | |
{ | |
string[] sequence = new string[100]; | |
for (int index = 2; index < 99; index += 3) | |
{ | |
sequence[index] = "Fizz"; | |
} | |
for (int index = 4; index < 100; index += 5) | |
{ | |
sequence[index] += "Buzz"; | |
} | |
for (int index = 0; index < 100; index++) | |
{ | |
if (sequence[index] == null) | |
{ | |
sequence[index] = (index + 1).ToString(); | |
} | |
} | |
return String.Join(",", sequence); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment