Search

Categories

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Send mail to the author(s) E-mail

# Wednesday, 24 September 2014

Leap Years:

I came up with the first one, and 2 others were from the site… Interesting.  I still really like obvious readability, so just prefer mine currently.  But am sure there is a better way

    //a leap year occurs: on every year that is evenly divisible by 4
    //except every year that is evenly divisible by 100
    //unless the year is also evenly divisible by 400

    public class Year {
        //public static bool IsLeap(int year) {
        //    // Is a LY if evenly divisible by 4
        //    if (year%4 != 0) return false;
            
        //    var isLeap = true;
        //    // Except every year that is evenly divisible by 100
        //    if (year % 100 == 0) {
        //        isLeap = false;
        //        // Unless the year is also evenly divisble by 400
        //        if (year%400 == 0) return true;
        //    }
        //    return isLeap;
        //}

        //public static bool IsLeap(int year) {
        //    return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
        //}

        public static bool IsLeap(int year) {
            if (year % 4 != 0) return false;
            if (year % 100 == 0 && year % 400 != 0) return false;
            return true;
        }
    }

    [TestFixture]
    public class LeapTest {
        [Test]
        public void Valid_leap_year() {
            Assert.That(Year.IsLeap(1996), Is.True);
        }

        [Test]
        public void Invalid_leap_year() {
            Assert.That(Year.IsLeap(1997), Is.False);
        }

        [Test]
        public void Turn_of_the_20th_century_is_not_a_leap_year() {
            Assert.That(Year.IsLeap(1900), Is.False);
        }

        [Test]
        public void Turn_of_the_21st_century_is_not_a_leap_year() {
            Assert.That(Year.IsLeap(2000), Is.True);
        }

        [Test]
        public void Turn_of_the_25th_century_is_a_leap_year() {
            Assert.That(Year.IsLeap(2400), Is.True);
        }
    }

http://exercism.io/submissions/3e64cb511521d02a4ee4f081

Giving some suggestions (nitpicks).. trying out the system for fun :-)

| | #