Created
September 29, 2012 01:53
-
-
Save bitmaybewise/3802894 to your computer and use it in GitHub Desktop.
FizzBuzz: From DojoPuzzles
This file contains 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
/* | |
* 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)); | |
} | |
} | |
} |
This file contains 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
/* | |
* 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