diff --git a/exercises/raindrops/Example.cs b/exercises/raindrops/Example.cs index 635eb2220b..694098aeb2 100644 --- a/exercises/raindrops/Example.cs +++ b/exercises/raindrops/Example.cs @@ -1,4 +1,4 @@ -public class Raindrops +public static class Raindrops { public static string Convert(int number) { diff --git a/exercises/raindrops/RaindropsTest.cs b/exercises/raindrops/RaindropsTest.cs index af3491015c..04b6612bda 100644 --- a/exercises/raindrops/RaindropsTest.cs +++ b/exercises/raindrops/RaindropsTest.cs @@ -2,49 +2,111 @@ public class RaindropsTest { - [Theory] - [InlineData(1, "1")] - [InlineData(52, "52")] - [InlineData(12121, "12121")] - public void Non_primes_pass_through(int number, string expected) + [Fact] + public void The_sound_for_1_is_1() { - Assert.Equal(expected, Raindrops.Convert(number)); + Assert.Equal("1", Raindrops.Convert(1)); } - [Theory(Skip = "Remove to run test")] - [InlineData(3)] - [InlineData(6)] - [InlineData(9)] - public void Numbers_containing_3_as_a_prime_factor_give_pling(int number) + [Fact(Skip = "Remove to run test")] + public void The_sound_for_3_is_pling() { - Assert.Equal("Pling", Raindrops.Convert(number)); + Assert.Equal("Pling", Raindrops.Convert(3)); } - [Theory(Skip = "Remove to run test")] - [InlineData(5)] - [InlineData(10)] - [InlineData(25)] - public void Numbers_containing_5_as_a_prime_factor_give_plang(int number) + [Fact(Skip = "Remove to run test")] + public void The_sound_for_5_is_plang() { - Assert.Equal("Plang", Raindrops.Convert(number)); + Assert.Equal("Plang", Raindrops.Convert(5)); } - [Theory(Skip = "Remove to run test")] - [InlineData(7)] - [InlineData(14)] - [InlineData(49)] - public void Numbers_containing_7_as_a_prime_factor_give_plong(int number) + [Fact(Skip = "Remove to run test")] + public void The_sound_for_7_is_plong() { - Assert.Equal("Plong", Raindrops.Convert(number)); + Assert.Equal("Plong", Raindrops.Convert(7)); } - [Theory(Skip = "Remove to run test")] - [InlineData(15, "PlingPlang")] - [InlineData(21, "PlingPlong")] - [InlineData(35, "PlangPlong")] - [InlineData(105, "PlingPlangPlong")] - public void Numbers_containing_multiple_prime_factors_give_all_results_concatenated(int number, string expected) + [Fact(Skip = "Remove to run test")] + public void The_sound_for_6_is_pling_as_it_has_a_factor_3() { - Assert.Equal(expected, Raindrops.Convert(number)); + Assert.Equal("Pling", Raindrops.Convert(6)); + } + + [Fact(Skip = "Remove to run test")] + public void Number_2_to_the_power_3_does_not_make_a_raindrop_sound_as_3_is_the_exponent_not_the_base() + { + Assert.Equal("8", Raindrops.Convert(8)); + } + + [Fact(Skip = "Remove to run test")] + public void The_sound_for_9_is_pling_as_it_has_a_factor_3() + { + Assert.Equal("Pling", Raindrops.Convert(9)); + } + + [Fact(Skip = "Remove to run test")] + public void The_sound_for_10_is_plang_as_it_has_a_factor_5() + { + Assert.Equal("Plang", Raindrops.Convert(10)); + } + + [Fact(Skip = "Remove to run test")] + public void The_sound_for_14_is_plong_as_it_has_a_factor_of_7() + { + Assert.Equal("Plong", Raindrops.Convert(14)); + } + + [Fact(Skip = "Remove to run test")] + public void The_sound_for_15_is_pling_plang_as_it_has_factors_3_and_5() + { + Assert.Equal("PlingPlang", Raindrops.Convert(15)); + } + + [Fact(Skip = "Remove to run test")] + public void The_sound_for_21_is_pling_plong_as_it_has_factors_3_and_7() + { + Assert.Equal("PlingPlong", Raindrops.Convert(21)); + } + + [Fact(Skip = "Remove to run test")] + public void The_sound_for_25_is_plang_as_it_has_a_factor_5() + { + Assert.Equal("Plang", Raindrops.Convert(25)); + } + + [Fact(Skip = "Remove to run test")] + public void The_sound_for_27_is_pling_as_it_has_a_factor_3() + { + Assert.Equal("Pling", Raindrops.Convert(27)); + } + + [Fact(Skip = "Remove to run test")] + public void The_sound_for_35_is_plang_plong_as_it_has_factors_5_and_7() + { + Assert.Equal("PlangPlong", Raindrops.Convert(35)); + } + + [Fact(Skip = "Remove to run test")] + public void The_sound_for_49_is_plong_as_it_has_a_factor_7() + { + Assert.Equal("Plong", Raindrops.Convert(49)); + } + + [Fact(Skip = "Remove to run test")] + public void The_sound_for_52_is_52() + { + Assert.Equal("52", Raindrops.Convert(52)); + } + + [Fact(Skip = "Remove to run test")] + public void The_sound_for_105_is_pling_plang_plong_as_it_has_factors_3_5_and_7() + { + Assert.Equal("PlingPlangPlong", Raindrops.Convert(105)); + } + + [Fact(Skip = "Remove to run test")] + public void The_sound_for_3125_is_plang_as_it_has_a_factor_5() + { + Assert.Equal("Plang", Raindrops.Convert(3125)); } } \ No newline at end of file diff --git a/generators/Exercises/RaindropsExercise.cs b/generators/Exercises/RaindropsExercise.cs new file mode 100644 index 0000000000..502a940e05 --- /dev/null +++ b/generators/Exercises/RaindropsExercise.cs @@ -0,0 +1,20 @@ +using Generators.Data; +using Generators.Methods; + +namespace Generators.Exercises +{ + public class RaindropsExercise : EqualityExercise + { + public RaindropsExercise() : base("raindrops") + { + } + + protected override TestMethodOptions CreateTestMethodOptions(CanonicalData canonicalData, CanonicalDataCase canonicalDataCase, int index) + { + var testMethodOptions = base.CreateTestMethodOptions(canonicalData, canonicalDataCase, index); + testMethodOptions.InputProperty = "number"; + + return testMethodOptions; + } + } +} \ No newline at end of file diff --git a/generators/Methods/TestMethodNameTransformer.cs b/generators/Methods/TestMethodNameTransformer.cs index d7ebc42b3d..f75685bc9c 100644 --- a/generators/Methods/TestMethodNameTransformer.cs +++ b/generators/Methods/TestMethodNameTransformer.cs @@ -5,7 +5,19 @@ namespace Generators.Methods { public class TestMethodNameTransformer : IStringTransformer { - public string Transform(string input) - => Regex.Replace(input, @"[^\w]+", "_", RegexOptions.Compiled).Underscore().Transform(Humanizer.To.TitleCase); + public string Transform(string input) + { + var methodName = Regex.Replace(input, @"[^\w]+", "_", RegexOptions.Compiled) + .Underscore() + .Transform(To.TitleCase); + + if (char.IsDigit(methodName[0])) + return "Number_" + methodName; + + if (!char.IsLetter(methodName[0])) + return "Test_"; + + return methodName; + } } } \ No newline at end of file