Skip to content

Instantly share code, notes, and snippets.

@alastairs
Created August 14, 2011 17:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alastairs/1145103 to your computer and use it in GitHub Desktop.
Save alastairs/1145103 to your computer and use it in GitHub Desktop.
Leap Year Calculator Second Attempt
public static bool IsLeapYear(int year)
{
return true;
}
[Test]
public void TestThat_IsLeapYear_ShouldReturnTrue_WhenTheYearIsDivisibleByFour()
{
const int year = 1984;
var isLeapYear = LeapYearCalculator.IsLeapYear(year);
Assert.IsTrue(isLeapYear);
}
public static bool IsLeapYear(int year)
{
if (year % 100 == 0)
{
return false;
}
return year % 4 == 0;
}
[Test]
public void TestThat_IsLeapYear_ShouldReturnFalse_WhenTheYearIsDivisibleByOneHundred()
{
const int year = 1700;
var isLeapYear = LeapYearCalculator.IsLeapYear(year);
Assert.IsFalse(isLeapYear);
}
public static bool IsLeapYear(int year)
{
if (IsCentury(year))
{
return year % 400 == 0;
}
return year % 4 == 0;
}
private static bool IsCentury(int year)
{
return year % 100 == 0;
}
public static bool IsLeapYear(int year)
{
return year % 4 == 0;
}
[Test]
public void TestThat_IsLeapYear_ShouldReturnFalse_WhenTheYearIsNotDivisibleByFour()
{
const int year = 1985;
var isLeapYear = LeapYearCalculator.IsLeapYear(year);
Assert.IsFalse(isLeapYear);
}
public static bool IsLeapYear(int year)
{
if (year % 100 == 0)
{
return year % 400 == 0;
}
return year % 4 == 0;
}
[Test]
public void TestThat_IsLeapYear_ShouldReturnTrue_WhenTheYearIsDivisibleByFourHundred()
{
// Whoops, this doesn't fail.
const int year = 1600;
var isLeapYear = LeapYearCalculator.IsLeapYear(year);
Assert.IsTrue(isLeapYear);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment