A simple FizzBuzz implementation, to try out Kumites.
Take a positive integer as input, and output:
"Fizz" if the number is divisible by three
"Buzz" if the number is divisible by five
"FizzBuzz" if the number is divisible by three and five
otherwise, just the number (as a string)
using System; namespace Solution { class FizzBuzz { public static string convert(int input) { var output = (input % 3 == 0 ? "Fizz" : "") + (input % 5 == 0 ? "Buzz" : ""); return output == "" ? input.ToString() : output; } } }
- using System;
- namespace Solution {
- class FizzBuzz {
- public static string convert(int input)
- {
var output = "";- var output = (input % 3 == 0 ? "Fizz" : "") + (input % 5 == 0 ? "Buzz" : "");
output += (input % 3 == 0) ? "Fizz" : "";output += (input % 5 == 0) ? "Buzz" : "";output += (string.IsNullOrEmpty(output)) ? input.ToString() : "";return output;- return output == "" ? input.ToString() : output;
- }
- }
- }
namespace Solution { using NUnit.Framework; using System; [TestFixture] public class SolutionTest { [Test] public void NotDivisibleByThreeOrFive() { Assert.That(FizzBuzz.convert(1), Is.EqualTo("1")); Assert.That(FizzBuzz.convert(7), Is.EqualTo("7")); } [Test] public void DivisibleByThree() { Assert.That(FizzBuzz.convert(3), Is.EqualTo("Fizz")); Assert.That(FizzBuzz.convert(12), Is.EqualTo("Fizz")); } [Test] public void DivisibleByFive() { Assert.That(FizzBuzz.convert(5), Is.EqualTo("Buzz")); Assert.That(FizzBuzz.convert(95), Is.EqualTo("Buzz")); } [Test] public void DivisibleByThreeAndFive() { Assert.That(FizzBuzz.convert(15), Is.EqualTo("FizzBuzz")); Assert.That(FizzBuzz.convert(90), Is.EqualTo("FizzBuzz")); } } }
- namespace Solution {
- using NUnit.Framework;
- using System;
// TODO: Replace examples and use TDD development by writing your own tests- [TestFixture]
- public class SolutionTest
- {
- [Test]
- public void NotDivisibleByThreeOrFive()
- {
- Assert.That(FizzBuzz.convert(1), Is.EqualTo("1"));
- Assert.That(FizzBuzz.convert(7), Is.EqualTo("7"));
- }
- [Test]
- public void DivisibleByThree()
- {
- Assert.That(FizzBuzz.convert(3), Is.EqualTo("Fizz"));
- Assert.That(FizzBuzz.convert(12), Is.EqualTo("Fizz"));
- }
- [Test]
- public void DivisibleByFive()
- {
- Assert.That(FizzBuzz.convert(5), Is.EqualTo("Buzz"));
- Assert.That(FizzBuzz.convert(95), Is.EqualTo("Buzz"));
- }
- [Test]
- public void DivisibleByThreeAndFive()
- {
- Assert.That(FizzBuzz.convert(15), Is.EqualTo("FizzBuzz"));
- Assert.That(FizzBuzz.convert(90), Is.EqualTo("FizzBuzz"));
- }
- }
- }
A simple FizzBuzz implementation, to try out Kumites.
Take a positive integer as input, and output:
- "Fizz" if the number is divisible by three
- "Buzz" if the number is divisible by five
- "FizzBuzz" if the number is divisible by three and five
- otherwise, just the number (as a string)
using System;
namespace Solution {
class FizzBuzz {
public static string convert(int input){
if (input % 3 == 0 && input % 5 == 0) {
return "FizzBuzz";
}
if (input % 3 == 0) {
return "Fizz";
}
if (input % 5 == 0) {
return "Buzz";
}
return input.ToString();
}
}
}
namespace Solution {
using NUnit.Framework;
using System;
// TODO: Replace examples and use TDD development by writing your own tests
[TestFixture]
public class SolutionTest
{
[Test]
public void NotDivisibleByThreeOrFive()
{
Assert.That(FizzBuzz.convert(1), Is.EqualTo("1"));
Assert.That(FizzBuzz.convert(7), Is.EqualTo("7"));
}
[Test]
public void DivisibleByThree()
{
Assert.That(FizzBuzz.convert(3), Is.EqualTo("Fizz"));
Assert.That(FizzBuzz.convert(12), Is.EqualTo("Fizz"));
}
[Test]
public void DivisibleByFive()
{
Assert.That(FizzBuzz.convert(5), Is.EqualTo("Buzz"));
Assert.That(FizzBuzz.convert(95), Is.EqualTo("Buzz"));
}
[Test]
public void DivisibleByThreeAndFive()
{
Assert.That(FizzBuzz.convert(15), Is.EqualTo("FizzBuzz"));
Assert.That(FizzBuzz.convert(90), Is.EqualTo("FizzBuzz"));
}
}
}