Skip to content

Instantly share code, notes, and snippets.

@MikeMKH
Created June 2, 2014 11:59
Show Gist options
  • Save MikeMKH/9d5eeab28943665cf39e to your computer and use it in GitHub Desktop.
Save MikeMKH/9d5eeab28943665cf39e to your computer and use it in GitHub Desktop.
Leap year check kata in C# using NUnit
using NUnit.Framework;
namespace LeapYear
{
public class LeapYearChecker
{
public bool IsLeapYear(int year)
{
if (year % 400 == 0) return true;
if (year % 100 == 0) return false;
if (year % 4 == 0) return true;
return false;
// or simply
//return DateTime.IsLeapYear(year);
}
}
[TestFixture]
public class LeapYearCheckerTest
{
private LeapYearChecker leapYearChecker;
[TestFixtureSetUp]
public void BeforeEachTest()
{
leapYearChecker = new LeapYearChecker();
}
[TestCase(2000, Result = true)]
[TestCase(4, Result = true)]
[TestCase(1, Result = false)]
[TestCase(64, Result = true)]
[TestCase(1900, Result = false)]
[TestCase(100, Result = false)]
public bool IsGivenYearALeapYear(int year)
{
return leapYearChecker.IsLeapYear(year);
}
}
}
@MikeMKH
Copy link
Author

MikeMKH commented Jun 7, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment