Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions exercises/leap/LeapTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@
public class LeapTest
{
[Fact]
public void Valid_leap_year()
public void Year_not_divisible_by_4_is_common_year()
{
Assert.True(Year.IsLeap(1996));
Assert.False(Year.IsLeap(2015));
}

[Fact(Skip = "Remove to run test")]
public void Invalid_leap_year()
public void Year_divisible_by_4_not_divisible_by_100_is_leap_year()
{
Assert.False(Year.IsLeap(1997));
Assert.True(Year.IsLeap(2016));
}

[Fact(Skip = "Remove to run test")]
public void Turn_of_the_20th_century_is_not_a_leap_year()
public void Year_divisible_by_100_not_divisible_by_400_is_common_year()
{
Assert.False(Year.IsLeap(1900));
Assert.False(Year.IsLeap(2100));
}

[Fact(Skip = "Remove to run test")]
public void Turn_of_the_25th_century_is_a_leap_year()
public void Year_divisible_by_400_is_leap_year()
{
Assert.True(Year.IsLeap(2400));
Assert.True(Year.IsLeap(2000));
}
}
35 changes: 35 additions & 0 deletions generators/Exercises/LeapExercise.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using System.Linq;
using Humanizer;

namespace Generators.Exercises
{
public class LeapExercise : Exercise
{
public LeapExercise() : base("leap")
{
}

public override TestClass CreateTestClass(CanonicalData canonicalData)
{
return new TestClass
{
ClassName = "Leap",
TestMethods = canonicalData.Cases.Select(CreateTestMethod).ToArray()
};
}

private static TestMethod CreateTestMethod(CanonicalDataCase canonicalDataCase, int index)
{
var year = Convert.ToInt32(canonicalDataCase.Input);
var isTrue = Convert.ToBoolean(canonicalDataCase.Expected);

return new TestMethod
{
Index = index,
MethodName = canonicalDataCase.Description.Replace(":", " is").Transform(To.TestMethodName),
Body = $"Assert.{isTrue}(Year.IsLeap({year}));"
};
}
}
}