Skip to content

Commit

Permalink
exercises: Update song exercises
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikSchierboom committed May 26, 2018
1 parent 34ced36 commit 4f6c0f7
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 33 deletions.
5 changes: 5 additions & 0 deletions exercises/food-chain/Example.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions exercises/food-chain/FoodChain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down
16 changes: 8 additions & 8 deletions exercises/food-chain/FoodChainTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand All @@ -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")]
Expand All @@ -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")]
Expand All @@ -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")]
Expand All @@ -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")]
Expand All @@ -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")]
Expand All @@ -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")]
Expand All @@ -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")]
Expand Down
5 changes: 5 additions & 0 deletions exercises/house/Example.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions exercises/house/House.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down
24 changes: 12 additions & 12 deletions exercises/house/HouseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
44 changes: 38 additions & 6 deletions exercises/proverb/ProverbTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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" }));
}
}
2 changes: 1 addition & 1 deletion exercises/twelve-days/TwelveDays.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
Expand Down
5 changes: 5 additions & 0 deletions generators/Exercises/FoodChain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions generators/Exercises/House.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
}
}
Expand Down
12 changes: 7 additions & 5 deletions generators/Exercises/Proverb.cs
Original file line number Diff line number Diff line change
@@ -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<string>(canonicalDataCase.Input["strings"]);
canonicalDataCase.Expected = ConvertHelper.ToArray<string>(canonicalDataCase.Expected);
}
return base.RenderTestMethodBodyAssert(testMethodBody);
}
}
}
3 changes: 2 additions & 1 deletion generators/Exercises/TwelveDays.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down

0 comments on commit 4f6c0f7

Please sign in to comment.