using System; public class LeapYears { // Works but hurts public static bool IsLeapYear(int y) => (y % 400 == 0) ? true : (y % 100 == 0 && y % 400 != 0) ? false : (y % 4 == 0 && y % 100 != 0) ? true : false; }
- using System;
- public class LeapYears
- {
public static bool IsLeapYear(int year){if (year % 400 == 0) return true;if (year % 100 == 0 && year % 400 != 0) return false;if (year % 4 == 0 && year % 100 != 0) return true;return false;}- // Works but hurts
- public static bool IsLeapYear(int y) => (y % 400 == 0) ? true : (y % 100 == 0 && y % 400 != 0) ? false : (y % 4 == 0 && y % 100 != 0) ? true : false;
- }
using System;
public class LeapYears
{
public static bool IsLeapYear(int year)
{
if (year % 400 == 0) return true;
if (year % 100 == 0 && year % 400 != 0) return false;
if (year % 4 == 0 && year % 100 != 0) return true;
return false;
}
}
namespace Solution {
using NUnit.Framework;
using System;
[TestFixture]
public class LeapTests
{
[Test]
public void Test1()
{
Assert.AreEqual(true, LeapYears.IsLeapYear(2000));
}
[Test]
public void Test2()
{
Assert.AreEqual(true, LeapYears.IsLeapYear(2004));
}
[Test]
public void Test3()
{
Assert.AreEqual(true, LeapYears.IsLeapYear(2008));
}
[Test]
public void Test4()
{
Assert.AreEqual(false, LeapYears.IsLeapYear(1913));
}
[Test]
public void Test5()
{
Assert.AreEqual(true, LeapYears.IsLeapYear(1848));
}
[Test]
public void Test6()
{
Assert.AreEqual(false, LeapYears.IsLeapYear(2397));
}
}
}