Skip to content

Instantly share code, notes, and snippets.

@bitmaybewise
Created September 29, 2012 01:53
Show Gist options
  • Save bitmaybewise/3802894 to your computer and use it in GitHub Desktop.
Save bitmaybewise/3802894 to your computer and use it in GitHub Desktop.
FizzBuzz: From DojoPuzzles
/*
* FizzBuzz
* http://dojopuzzles.com/problemas/exibe/fizzbuzz/
*/
using System;
using System.Text;
namespace FizzBuzz
{
class FizzBuzz
{
public string Execute(int number)
{
var result = new StringBuilder();
if ( number % 3 == 0 )
result.Append("Fizz");
if ( number % 5 == 0 )
result.Append("Buzz");
if (result.ToString().Equals(string.Empty))
result.Append(number.ToString());
return result.ToString();
}
public static void Main(string[] args)
{
var fb = new FizzBuzz();
for (int i = 1; i <= 100; i++)
Console.WriteLine(fb.Execute(i));
}
}
}
/*
* FizzBuzz
* http://dojopuzzles.com/problemas/exibe/fizzbuzz/
*/

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace FizzBuzz
{
[TestClass]
public class FizzBuzzTest
{
private FizzBuzz fizzbuzz;
[TestInitialize]
public void Initialize()
{
fizzbuzz = new FizzBuzz();
}
[TestCleanup]
public void CleanUp()
{
fizzbuzz = null;
}
[TestMethod]
public void ShouldBeFizz()
{
Assert.AreEqual("Fizz", fizzbuzz.Execute(3));
}
[TestMethod]
public void ShouldBeBuzz()
{
Assert.AreEqual("Buzz", fizzbuzz.Execute(5));
}
[TestMethod]
public void ShouldBeFizzBuzz()
{
Assert.AreEqual("FizzBuzz", fizzbuzz.Execute(15));
}
[TestMethod]
public void ShouldBeTheNumber()
{
Assert.AreEqual("7", fizzbuzz.Execute(7));
}
[TestMethod]
public void ShouldBeFizzWithThirtyNine()
{
Assert.AreEqual("Fizz", fizzbuzz.Execute(39));
}
[TestMethod]
public void ShouldBeBuzzWithFifty()
{
Assert.AreEqual("Buzz", fizzbuzz.Execute(50));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment