Skip to content

Add raindrops generator #259

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 20, 2017
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
2 changes: 1 addition & 1 deletion exercises/raindrops/Example.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
public class Raindrops
public static class Raindrops
{
public static string Convert(int number)
{
Expand Down
124 changes: 93 additions & 31 deletions exercises/raindrops/RaindropsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
20 changes: 20 additions & 0 deletions generators/Exercises/RaindropsExercise.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
16 changes: 14 additions & 2 deletions generators/Methods/TestMethodNameTransformer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}