diff --git a/exercises/food-chain/Example.cs b/exercises/food-chain/Example.cs index 1b9dd29090..e0a4ed8f4c 100644 --- a/exercises/food-chain/Example.cs +++ b/exercises/food-chain/Example.cs @@ -36,6 +36,11 @@ public static class FoodChain "I don't know why she swallowed the fly. Perhaps she'll die." }; + public static string Recite(int verseNumber) + { + return Recite(verseNumber, verseNumber); + } + public static string Recite(int startVerse, int endVerse) => string.Join("\n\n", Enumerable.Range(startVerse, endVerse - startVerse + 1).Select(i => $"{VerseBegin(i)}\n{VerseEnd(i)}")); private static string VerseBegin(int number) diff --git a/exercises/food-chain/FoodChain.cs b/exercises/food-chain/FoodChain.cs index d51ecf5c7d..73b4505fca 100644 --- a/exercises/food-chain/FoodChain.cs +++ b/exercises/food-chain/FoodChain.cs @@ -2,6 +2,11 @@ public static class FoodChain { + public static string Recite(int verseNumber) + { + throw new NotImplementedException("You need to implement this function."); + } + public static string Recite(int startVerse, int endVerse) { throw new NotImplementedException("You need to implement this function."); diff --git a/exercises/food-chain/FoodChainTest.cs b/exercises/food-chain/FoodChainTest.cs index 80fbfada00..f6846e35da 100644 --- a/exercises/food-chain/FoodChainTest.cs +++ b/exercises/food-chain/FoodChainTest.cs @@ -10,7 +10,7 @@ public void Fly() var expected = "I know an old lady who swallowed a fly.\n" + "I don't know why she swallowed the fly. Perhaps she'll die."; - Assert.Equal(expected, FoodChain.Recite(1, 1)); + Assert.Equal(expected, FoodChain.Recite(1)); } [Fact(Skip = "Remove to run test")] @@ -21,7 +21,7 @@ public void Spider() "It wriggled and jiggled and tickled inside her.\n" + "She swallowed the spider to catch the fly.\n" + "I don't know why she swallowed the fly. Perhaps she'll die."; - Assert.Equal(expected, FoodChain.Recite(2, 2)); + Assert.Equal(expected, FoodChain.Recite(2)); } [Fact(Skip = "Remove to run test")] @@ -33,7 +33,7 @@ public void Bird() "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + "She swallowed the spider to catch the fly.\n" + "I don't know why she swallowed the fly. Perhaps she'll die."; - Assert.Equal(expected, FoodChain.Recite(3, 3)); + Assert.Equal(expected, FoodChain.Recite(3)); } [Fact(Skip = "Remove to run test")] @@ -46,7 +46,7 @@ public void Cat() "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + "She swallowed the spider to catch the fly.\n" + "I don't know why she swallowed the fly. Perhaps she'll die."; - Assert.Equal(expected, FoodChain.Recite(4, 4)); + Assert.Equal(expected, FoodChain.Recite(4)); } [Fact(Skip = "Remove to run test")] @@ -60,7 +60,7 @@ public void Dog() "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + "She swallowed the spider to catch the fly.\n" + "I don't know why she swallowed the fly. Perhaps she'll die."; - Assert.Equal(expected, FoodChain.Recite(5, 5)); + Assert.Equal(expected, FoodChain.Recite(5)); } [Fact(Skip = "Remove to run test")] @@ -75,7 +75,7 @@ public void Goat() "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + "She swallowed the spider to catch the fly.\n" + "I don't know why she swallowed the fly. Perhaps she'll die."; - Assert.Equal(expected, FoodChain.Recite(6, 6)); + Assert.Equal(expected, FoodChain.Recite(6)); } [Fact(Skip = "Remove to run test")] @@ -91,7 +91,7 @@ public void Cow() "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" + "She swallowed the spider to catch the fly.\n" + "I don't know why she swallowed the fly. Perhaps she'll die."; - Assert.Equal(expected, FoodChain.Recite(7, 7)); + Assert.Equal(expected, FoodChain.Recite(7)); } [Fact(Skip = "Remove to run test")] @@ -100,7 +100,7 @@ public void Horse() var expected = "I know an old lady who swallowed a horse.\n" + "She's dead, of course!"; - Assert.Equal(expected, FoodChain.Recite(8, 8)); + Assert.Equal(expected, FoodChain.Recite(8)); } [Fact(Skip = "Remove to run test")] diff --git a/exercises/house/Example.cs b/exercises/house/Example.cs index a4cb62ba99..50f37b2373 100644 --- a/exercises/house/Example.cs +++ b/exercises/house/Example.cs @@ -34,6 +34,11 @@ public static class House "" }; + public static string Recite(int verseNumber) + { + return Recite(verseNumber, verseNumber); + } + public static string Recite(int startVerse, int endVerse) { var numberOfVerses = endVerse - startVerse + 1; diff --git a/exercises/house/House.cs b/exercises/house/House.cs index 6cd41cd62e..fc72121b16 100644 --- a/exercises/house/House.cs +++ b/exercises/house/House.cs @@ -2,6 +2,11 @@ public static class House { + public static string Recite(int verseNumber) + { + throw new NotImplementedException("You need to implement this function."); + } + public static string Recite(int startVerse, int endVerse) { throw new NotImplementedException("You need to implement this function."); diff --git a/exercises/house/HouseTest.cs b/exercises/house/HouseTest.cs index fecadfcf6a..d8ee7a06d3 100644 --- a/exercises/house/HouseTest.cs +++ b/exercises/house/HouseTest.cs @@ -8,84 +8,84 @@ public class HouseTest public void Verse_one_the_house_that_jack_built() { var expected = "This is the house that Jack built."; - Assert.Equal(expected, House.Recite(1, 1)); + Assert.Equal(expected, House.Recite(1)); } [Fact(Skip = "Remove to run test")] public void Verse_two_the_malt_that_lay() { var expected = "This is the malt that lay in the house that Jack built."; - Assert.Equal(expected, House.Recite(2, 2)); + Assert.Equal(expected, House.Recite(2)); } [Fact(Skip = "Remove to run test")] public void Verse_three_the_rat_that_ate() { var expected = "This is the rat that ate the malt that lay in the house that Jack built."; - Assert.Equal(expected, House.Recite(3, 3)); + Assert.Equal(expected, House.Recite(3)); } [Fact(Skip = "Remove to run test")] public void Verse_four_the_cat_that_killed() { var expected = "This is the cat that killed the rat that ate the malt that lay in the house that Jack built."; - Assert.Equal(expected, House.Recite(4, 4)); + Assert.Equal(expected, House.Recite(4)); } [Fact(Skip = "Remove to run test")] public void Verse_five_the_dog_that_worried() { var expected = "This is the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built."; - Assert.Equal(expected, House.Recite(5, 5)); + Assert.Equal(expected, House.Recite(5)); } [Fact(Skip = "Remove to run test")] public void Verse_six_the_cow_with_the_crumpled_horn() { var expected = "This is the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built."; - Assert.Equal(expected, House.Recite(6, 6)); + Assert.Equal(expected, House.Recite(6)); } [Fact(Skip = "Remove to run test")] public void Verse_seven_the_maiden_all_forlorn() { var expected = "This is the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built."; - Assert.Equal(expected, House.Recite(7, 7)); + Assert.Equal(expected, House.Recite(7)); } [Fact(Skip = "Remove to run test")] public void Verse_eight_the_man_all_tattered_and_torn() { var expected = "This is the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built."; - Assert.Equal(expected, House.Recite(8, 8)); + Assert.Equal(expected, House.Recite(8)); } [Fact(Skip = "Remove to run test")] public void Verse_nine_the_priest_all_shaven_and_shorn() { var expected = "This is the priest all shaven and shorn that married the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built."; - Assert.Equal(expected, House.Recite(9, 9)); + Assert.Equal(expected, House.Recite(9)); } [Fact(Skip = "Remove to run test")] public void Verse_10_the_rooster_that_crowed_in_the_morn() { var expected = "This is the rooster that crowed in the morn that woke the priest all shaven and shorn that married the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built."; - Assert.Equal(expected, House.Recite(10, 10)); + Assert.Equal(expected, House.Recite(10)); } [Fact(Skip = "Remove to run test")] public void Verse_11_the_farmer_sowing_his_corn() { var expected = "This is the farmer sowing his corn that kept the rooster that crowed in the morn that woke the priest all shaven and shorn that married the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built."; - Assert.Equal(expected, House.Recite(11, 11)); + Assert.Equal(expected, House.Recite(11)); } [Fact(Skip = "Remove to run test")] public void Verse_12_the_horse_and_the_hound_and_the_horn() { var expected = "This is the horse and the hound and the horn that belonged to the farmer sowing his corn that kept the rooster that crowed in the morn that woke the priest all shaven and shorn that married the man all tattered and torn that kissed the maiden all forlorn that milked the cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built."; - Assert.Equal(expected, House.Recite(12, 12)); + Assert.Equal(expected, House.Recite(12)); } [Fact(Skip = "Remove to run test")] diff --git a/exercises/proverb/ProverbTest.cs b/exercises/proverb/ProverbTest.cs index 78fdd0f788..3cbe8a2d80 100644 --- a/exercises/proverb/ProverbTest.cs +++ b/exercises/proverb/ProverbTest.cs @@ -7,36 +7,68 @@ public class ProverbTest [Fact] public void Zero_pieces() { - Assert.Empty(Proverb.Recite(new string[] { })); + Assert.Empty(Proverb.Recite(new string[0])); } [Fact(Skip = "Remove to run test")] public void One_piece() { - Assert.Equal(new[] { "And all for the want of a nail." }, Proverb.Recite(new[] { "nail" })); + var expected = new[] + { + "And all for the want of a nail." + }; + Assert.Equal(expected, Proverb.Recite(new[] { "nail" })); } [Fact(Skip = "Remove to run test")] public void Two_pieces() { - Assert.Equal(new[] { "For want of a nail the shoe was lost.", "And all for the want of a nail." }, Proverb.Recite(new[] { "nail", "shoe" })); + var expected = new[] + { + "For want of a nail the shoe was lost.", + "And all for the want of a nail." + }; + Assert.Equal(expected, Proverb.Recite(new[] { "nail", "shoe" })); } [Fact(Skip = "Remove to run test")] public void Three_pieces() { - Assert.Equal(new[] { "For want of a nail the shoe was lost.", "For want of a shoe the horse was lost.", "And all for the want of a nail." }, Proverb.Recite(new[] { "nail", "shoe", "horse" })); + var expected = new[] + { + "For want of a nail the shoe was lost.", + "For want of a shoe the horse was lost.", + "And all for the want of a nail." + }; + Assert.Equal(expected, Proverb.Recite(new[] { "nail", "shoe", "horse" })); } [Fact(Skip = "Remove to run test")] public void Full_proverb() { - Assert.Equal(new[] { "For want of a nail the shoe was lost.", "For want of a shoe the horse was lost.", "For want of a horse the rider was lost.", "For want of a rider the message was lost.", "For want of a message the battle was lost.", "For want of a battle the kingdom was lost.", "And all for the want of a nail." }, Proverb.Recite(new[] { "nail", "shoe", "horse", "rider", "message", "battle", "kingdom" })); + var expected = new[] + { + "For want of a nail the shoe was lost.", + "For want of a shoe the horse was lost.", + "For want of a horse the rider was lost.", + "For want of a rider the message was lost.", + "For want of a message the battle was lost.", + "For want of a battle the kingdom was lost.", + "And all for the want of a nail." + }; + Assert.Equal(expected, Proverb.Recite(new[] { "nail", "shoe", "horse", "rider", "message", "battle", "kingdom" })); } [Fact(Skip = "Remove to run test")] public void Four_pieces_modernized() { - Assert.Equal(new[] { "For want of a pin the gun was lost.", "For want of a gun the soldier was lost.", "For want of a soldier the battle was lost.", "And all for the want of a pin." }, Proverb.Recite(new[] { "pin", "gun", "soldier", "battle" })); + var expected = new[] + { + "For want of a pin the gun was lost.", + "For want of a gun the soldier was lost.", + "For want of a soldier the battle was lost.", + "And all for the want of a pin." + }; + Assert.Equal(expected, Proverb.Recite(new[] { "pin", "gun", "soldier", "battle" })); } } \ No newline at end of file diff --git a/exercises/twelve-days/TwelveDays.cs b/exercises/twelve-days/TwelveDays.cs index 89421dd22c..b53c93dc19 100644 --- a/exercises/twelve-days/TwelveDays.cs +++ b/exercises/twelve-days/TwelveDays.cs @@ -7,7 +7,7 @@ public static string Recite(int verseNumber) throw new NotImplementedException("You need to implement this function."); } - public static string Recite(int start, int end) + public static string Recite(int startVerse, int endVerse) { throw new NotImplementedException("You need to implement this function."); } diff --git a/generators/Exercises/FoodChain.cs b/generators/Exercises/FoodChain.cs index d6a79e5d18..dd8bd01c4d 100644 --- a/generators/Exercises/FoodChain.cs +++ b/generators/Exercises/FoodChain.cs @@ -10,6 +10,11 @@ protected override void UpdateCanonicalData(CanonicalData canonicalData) { canonicalDataCase.Expected = ConvertHelper.ToMultiLineString(canonicalDataCase.Expected); canonicalDataCase.UseVariableForExpected = true; + + if (canonicalDataCase.Input["startVerse"] == canonicalDataCase.Input["endVerse"]) + { + canonicalDataCase.SetInputParameters("startVerse"); + } } } } diff --git a/generators/Exercises/House.cs b/generators/Exercises/House.cs index 77e7fa4b76..01ab6c12be 100644 --- a/generators/Exercises/House.cs +++ b/generators/Exercises/House.cs @@ -10,6 +10,11 @@ protected override void UpdateCanonicalData(CanonicalData canonicalData) { canonicalDataCase.UseVariableForExpected = true; canonicalDataCase.Expected = ConvertHelper.ToMultiLineString(canonicalDataCase.Expected); + + if (canonicalDataCase.Input["startVerse"] == canonicalDataCase.Input["endVerse"]) + { + canonicalDataCase.SetInputParameters("startVerse"); + } } } } diff --git a/generators/Exercises/Proverb.cs b/generators/Exercises/Proverb.cs index 57cffd9bf0..72a28e1a59 100644 --- a/generators/Exercises/Proverb.cs +++ b/generators/Exercises/Proverb.cs @@ -1,16 +1,18 @@ -using Generators.Output; +using Generators.Input; +using Generators.Output; namespace Generators.Exercises { public class Proverb : GeneratorExercise { - protected override string RenderTestMethodBodyAssert(TestMethodBody testMethodBody) + protected override void UpdateCanonicalData(CanonicalData canonicalData) { - if (testMethodBody.CanonicalDataCase.Properties["input"]["strings"] as string[] == null) + foreach (var canonicalDataCase in canonicalData.Cases) { - return TemplateRenderer.RenderInline("Assert.Empty(Proverb.Recite(new string[] { }));", new { }); + canonicalDataCase.UseVariableForExpected = true; + canonicalDataCase.Input["strings"] = ConvertHelper.ToArray(canonicalDataCase.Input["strings"]); + canonicalDataCase.Expected = ConvertHelper.ToArray(canonicalDataCase.Expected); } - return base.RenderTestMethodBodyAssert(testMethodBody); } } } \ No newline at end of file diff --git a/generators/Exercises/TwelveDays.cs b/generators/Exercises/TwelveDays.cs index 63c9e10c3e..fd2bcc3cbc 100644 --- a/generators/Exercises/TwelveDays.cs +++ b/generators/Exercises/TwelveDays.cs @@ -16,7 +16,8 @@ protected override void UpdateCanonicalData(CanonicalData canonicalData) { canonicalDataCase.UseVariableForExpected = true; canonicalDataCase.Expected = ConvertHelper.ToMultiLineString(canonicalDataCase.Expected); - if ((int)canonicalDataCase.Input["startVerse"] == (int)canonicalDataCase.Input["endVerse"]) + + if (canonicalDataCase.Input["startVerse"] == canonicalDataCase.Input["endVerse"]) { canonicalDataCase.SetInputParameters("startVerse"); }