Fundamentals
Strings
Data Types
Logic
Write a function that returns string:
"Fizz" when the number is divisible by 3.
"Buzz" when the number is divisible by 5.
"FizzBuzz" when the number is divisible by 3 and 5.
public class FizzBuzz
{
public string GetOutput(int number)
{
if ((number % 3 == 0) && (number % 5 == 0))
return "FizzBuzz";
else if (number % 3 == 0)
return "Fizz";
else if (number % 5 == 0)
return "Buzz";
else return number.ToString();
}
}
namespace Solution {
using NUnit.Framework;
[TestFixture]
public class SolutionTest
{
[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"));
}
}
}
Fundamentals
Numbers
Data Types
Logic
Write a method that returns a greater number.
Perfect task for begginers!Welcome to CodeWars!
public class Math
{
public int Max(int a, int b)
{
return (a > b) ? a : b;
}
}
namespace Solution {
using NUnit.Framework;
[TestFixture]
public class SolutionTest
{
private Math math;
[SetUp]
public void SetUp()
{
math = new Math();
}
[Test]
[TestCase(1,2,2)]
[TestCase(2,1,2)]
[TestCase(1,1,1)]
public void Max_WhenCalled_ReturnTheGreaterArgument(int a, int b, int expectedResult)
{
var result = math.Max(a,b);
Assert.That(result, Is.EqualTo(expectedResult));
}
}
}