Created
June 2, 2014 11:59
-
-
Save MikeMKH/9d5eeab28943665cf39e to your computer and use it in GitHub Desktop.
Leap year check kata in C# using NUnit
This file contains hidden or 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
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); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See my blog post which goes with this: http://comp-phil.blogspot.com/2014/06/leap-year-in-key-of-c-f-haskell-and.html