Move History

Fork Selected
  • Description

    Shorter but not necessary as readable. I chose to break the line at what i would consider each thought. Like an "if, else" "If #calculations# is true? Do this. Otherwise keep going" "If #calculations# is true? Do this. Otherwise keep going" "If #calculations# is true? Do this. Otherwise keep going" Chould definitely be a oneliner, but in my opinion oneLiners makes it less readable which will make it harder for the next programmer to understand.

    Code
    // Fizz buzz is a popular computer science interview question.  
    // The function above is given a number - if the number is
    // divisible by 3, return "fizz", if it's divisible by 5, 
    // return "buzz", if not divisble by 3 or 5 - return the
    // number itself.
    public class FizzBuzz
    {
        public string GetOutput(int number) {
          return (number % 15 == 0) ? "FizzBuzz":
            (number % 3 == 0) ? "Fizz":
            (number % 5 == 0) ? "Buzz":
            number.ToString();      
        }
    }
    Test Cases
    namespace Solution {
      using NUnit.Framework;
      [TestFixture]
      public class SolutionTest
      {
         [Test]
         public void GetOutput_InputIsAll()
         {
            var fizzbuzz = new FizzBuzz();
            var result = fizzbuzz.GetOutput(0);
            Assert.That(result, Is.EqualTo("FizzBuzz"));
            result = fizzbuzz.GetOutput(17);
            Assert.That(result, Is.EqualTo("17"));
            result = fizzbuzz.GetOutput(50);
            Assert.That(result, Is.EqualTo("Buzz"));
            result = fizzbuzz.GetOutput(73);
            Assert.That(result, Is.EqualTo("73"));
            result = fizzbuzz.GetOutput(99);
            Assert.That(result, Is.EqualTo("Fizz"));
            result = fizzbuzz.GetOutput(100);
            Assert.That(result, Is.EqualTo("Buzz"));
            // write your own test to test all numbers from 0 to 100
         }
    
        [Test]
         public void GetOutput_InputIs4_Return4()
         {
            var fizzbuzz = new FizzBuzz();
            var result = fizzbuzz.GetOutput(4);
            Assert.That(result, Is.EqualTo("4"));
         }
         [Test]
         public void GetOutput_InputIsDivisibleBy3_ReturnFizz()
         {
            var fizzbuzz = new FizzBuzz();
            var result = fizzbuzz.GetOutput(3);
            Assert.That(result, Is.EqualTo("Fizz"));
         }
         [Test]
         public void GetOutput_InputIsDivisibleBy5_ReturnBuzz()
         {
            var fizzbuzz = new FizzBuzz();
            var result = fizzbuzz.GetOutput(5);
            Assert.That(result, Is.EqualTo("Buzz"));
         }
         [Test]
         public void GetOutput_InputIsDivisibleBy5And3_ReturnFizzBuzz()
         {
            var fizzbuzz = new FizzBuzz();
            var result = fizzbuzz.GetOutput(15);
            Assert.That(result, Is.EqualTo("FizzBuzz"));
         }
      }
    }
  • Code
    • // Fizz buzz is a popular computer science interview question.
    • // The function above is given a number - if the number is
    • // divisible by 3, return "fizz", if it's divisible by 5,
    • // return "buzz", if not divisble by 3 or 5 - return the
    • // number itself.
    • public class FizzBuzz
    • {
    • public string GetOutput(int number) {
    • if (number % 15 == 0) {
    • return "FizzBuzz";
    • }
    • else if (number % 3 == 0) {
    • return "Fizz";
    • }
    • else if (number % 5 == 0) {
    • return "Buzz";
    • }
    • else {
    • return number.ToString();
    • }
    • // Fizz buzz is a popular computer science interview question.
    • // The function above is given a number - if the number is
    • // divisible by 3, return "fizz", if it's divisible by 5,
    • // return "buzz", if not divisble by 3 or 5 - return the
    • // number itself.
    • return (number % 15 == 0) ? "FizzBuzz":
    • (number % 3 == 0) ? "Fizz":
    • (number % 5 == 0) ? "Buzz":
    • number.ToString();
    • }
    • }