Skip to content

Instantly share code, notes, and snippets.

@brockthebear
Created September 12, 2018 15:52
Show Gist options
  • Select an option

  • Save brockthebear/e082f7e24e94e43d19895b61922815c4 to your computer and use it in GitHub Desktop.

Select an option

Save brockthebear/e082f7e24e94e43d19895b61922815c4 to your computer and use it in GitHub Desktop.
using System;
public static class Leap
{
public static bool IsLeapYear(int year)
{
bool multipleOf4 = YearIsDivisibleByFactor(year, 4);
bool multipleOf100 = YearIsDivisibleByFactor(year, 100);
bool multipleOf400 = YearIsDivisibleByFactor(year, 400);
return !multipleOf4 ? false : !(multipleOf4 && (multipleOf100 && !multipleOf400));
}
public static bool YearIsDivisibleByFactor(int year, int divisor)
{
return (year % divisor) == 0;
}
}
// This file was auto-generated based on version 1.3.0 of the canonical data.
using Xunit;
public class LeapTest
{
[Fact]
public void Year_not_divisible_by_4_is_common_year()
{
Assert.False(Leap.IsLeapYear(2015));
}
[Fact]
public void Year_divisible_by_4_not_divisible_by_100_is_leap_year()
{
Assert.True(Leap.IsLeapYear(1996));
}
[Fact]
public void Year_divisible_by_100_not_divisible_by_400_is_common_year()
{
Assert.False(Leap.IsLeapYear(2100));
}
[Fact]
public void Year_divisible_by_400_is_leap_year()
{
Assert.True(Leap.IsLeapYear(2000));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment