Created
August 14, 2011 17:35
-
-
Save alastairs/1145103 to your computer and use it in GitHub Desktop.
Leap Year Calculator Second Attempt
This file contains 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
public static bool IsLeapYear(int year) | |
{ | |
return true; | |
} |
This file contains 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
[Test] | |
public void TestThat_IsLeapYear_ShouldReturnTrue_WhenTheYearIsDivisibleByFour() | |
{ | |
const int year = 1984; | |
var isLeapYear = LeapYearCalculator.IsLeapYear(year); | |
Assert.IsTrue(isLeapYear); | |
} |
This file contains 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
public static bool IsLeapYear(int year) | |
{ | |
if (year % 100 == 0) | |
{ | |
return false; | |
} | |
return year % 4 == 0; | |
} |
This file contains 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
[Test] | |
public void TestThat_IsLeapYear_ShouldReturnFalse_WhenTheYearIsDivisibleByOneHundred() | |
{ | |
const int year = 1700; | |
var isLeapYear = LeapYearCalculator.IsLeapYear(year); | |
Assert.IsFalse(isLeapYear); | |
} |
This file contains 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
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; | |
} |
This file contains 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
public static bool IsLeapYear(int year) | |
{ | |
return year % 4 == 0; | |
} |
This file contains 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
[Test] | |
public void TestThat_IsLeapYear_ShouldReturnFalse_WhenTheYearIsNotDivisibleByFour() | |
{ | |
const int year = 1985; | |
var isLeapYear = LeapYearCalculator.IsLeapYear(year); | |
Assert.IsFalse(isLeapYear); | |
} |
This file contains 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
public static bool IsLeapYear(int year) | |
{ | |
if (year % 100 == 0) | |
{ | |
return year % 400 == 0; | |
} | |
return year % 4 == 0; | |
} |
This file contains 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
[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