Skip to content

Add food-chain generator #267

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 27, 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
4 changes: 2 additions & 2 deletions exercises/food-chain/Example.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ public static class FoodChain
"I don't know why she swallowed the fly. Perhaps she'll die."
};

public static string Song() => string.Join("\n\n", Enumerable.Range(1, Verses).Select(Verse));

public static string Verse(int number) => $"{VerseBegin(number)}\n{VerseEnd(number)}";

public static string Verse(int begin, int end) => string.Join("\n\n", Enumerable.Range(begin, end - begin + 1).Select(i => Verse(i)));

private static string VerseBegin(int number)
{
if (number == 1)
Expand Down
4 changes: 2 additions & 2 deletions exercises/food-chain/FoodChain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

public static class FoodChain
{
public static string Song()
public static string Verse(int number)
{
throw new NotImplementedException("You need to implement this function.");
}

public static string Verse(int number)
public static string Verse(int begin, int end)
{
throw new NotImplementedException("You need to implement this function.");
}
Expand Down
223 changes: 150 additions & 73 deletions exercises/food-chain/FoodChainTest.cs
Original file line number Diff line number Diff line change
@@ -1,103 +1,180 @@
using Xunit;
using Xunit;

public class FoodChainTest
{
[Fact]
public void Verse_one()
public void Fly()
{
const string expected = "I know an old lady who swallowed a fly.\n" +
"I don't know why she swallowed the fly. Perhaps she'll die.";

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.Verse(1));
}

[Fact(Skip = "Remove to run test")]
public void Verse_two()
public void Spider()
{
const string expected = "I know an old lady who swallowed a spider.\n" +
"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.";

var expected =
"I know an old lady who swallowed a spider.\n"+
"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.Verse(2));
}

[Fact(Skip = "Remove to run test")]
public void Verse_four()
public void Bird()
{
const string expected = "I know an old lady who swallowed a cat.\n" +
"Imagine that, to swallow a cat!\n" +
"She swallowed the cat to catch the bird.\n" +
"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.";
var expected =
"I know an old lady who swallowed a bird.\n"+
"How absurd to swallow a bird!\n"+
"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.Verse(3));
}

[Fact(Skip = "Remove to run test")]
public void Cat()
{
var expected =
"I know an old lady who swallowed a cat.\n"+
"Imagine that, to swallow a cat!\n"+
"She swallowed the cat to catch the bird.\n"+
"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.Verse(4));
}

[Fact(Skip = "Remove to run test")]
public void Verse_eight()
public void Dog()
{
const string expected = "I know an old lady who swallowed a horse.\n" +
"She's dead, of course!";
var expected =
"I know an old lady who swallowed a dog.\n"+
"What a hog, to swallow a dog!\n"+
"She swallowed the dog to catch the cat.\n"+
"She swallowed the cat to catch the bird.\n"+
"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.Verse(5));
}

[Fact(Skip = "Remove to run test")]
public void Goat()
{
var expected =
"I know an old lady who swallowed a goat.\n"+
"Just opened her throat and swallowed a goat!\n"+
"She swallowed the goat to catch the dog.\n"+
"She swallowed the dog to catch the cat.\n"+
"She swallowed the cat to catch the bird.\n"+
"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.Verse(6));
}

[Fact(Skip = "Remove to run test")]
public void Cow()
{
var expected =
"I know an old lady who swallowed a cow.\n"+
"I don't know how she swallowed a cow!\n"+
"She swallowed the cow to catch the goat.\n"+
"She swallowed the goat to catch the dog.\n"+
"She swallowed the dog to catch the cat.\n"+
"She swallowed the cat to catch the bird.\n"+
"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.Verse(7));
}

[Fact(Skip = "Remove to run test")]
public void Horse()
{
var expected =
"I know an old lady who swallowed a horse.\n"+
"She's dead, of course!";
Assert.Equal(expected, FoodChain.Verse(8));
}

[Fact(Skip = "Remove to run test")]
public void Complete_song()
public void Multiple_verses()
{
const string expected = "I know an old lady who swallowed a fly.\n" +
"I don't know why she swallowed the fly. Perhaps she'll die.\n" +
"\n" +
"I know an old lady who swallowed a spider.\n" +
"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.\n" +
"\n" +
"I know an old lady who swallowed a bird.\n" +
"How absurd to swallow a bird!\n" +
"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.\n" +
"\n" +
"I know an old lady who swallowed a cat.\n" +
"Imagine that, to swallow a cat!\n" +
"She swallowed the cat to catch the bird.\n" +
"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.\n" +
"\n" +
"I know an old lady who swallowed a dog.\n" +
"What a hog, to swallow a dog!\n" +
"She swallowed the dog to catch the cat.\n" +
"She swallowed the cat to catch the bird.\n" +
"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.\n" +
"\n" +
"I know an old lady who swallowed a goat.\n" +
"Just opened her throat and swallowed a goat!\n" +
"She swallowed the goat to catch the dog.\n" +
"She swallowed the dog to catch the cat.\n" +
"She swallowed the cat to catch the bird.\n" +
"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.\n" +
"\n" +
"I know an old lady who swallowed a cow.\n" +
"I don't know how she swallowed a cow!\n" +
"She swallowed the cow to catch the goat.\n" +
"She swallowed the goat to catch the dog.\n" +
"She swallowed the dog to catch the cat.\n" +
"She swallowed the cat to catch the bird.\n" +
"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.\n" +
"\n" +
"I know an old lady who swallowed a horse.\n" +
"She's dead, of course!";
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.\n"+
"\n"+
"I know an old lady who swallowed a spider.\n"+
"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.\n"+
"\n"+
"I know an old lady who swallowed a bird.\n"+
"How absurd to swallow a bird!\n"+
"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.Verse(1, 3));
}

Assert.Equal(expected, FoodChain.Song());
[Fact(Skip = "Remove to run test")]
public void Full_song()
{
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.\n"+
"\n"+
"I know an old lady who swallowed a spider.\n"+
"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.\n"+
"\n"+
"I know an old lady who swallowed a bird.\n"+
"How absurd to swallow a bird!\n"+
"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.\n"+
"\n"+
"I know an old lady who swallowed a cat.\n"+
"Imagine that, to swallow a cat!\n"+
"She swallowed the cat to catch the bird.\n"+
"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.\n"+
"\n"+
"I know an old lady who swallowed a dog.\n"+
"What a hog, to swallow a dog!\n"+
"She swallowed the dog to catch the cat.\n"+
"She swallowed the cat to catch the bird.\n"+
"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.\n"+
"\n"+
"I know an old lady who swallowed a goat.\n"+
"Just opened her throat and swallowed a goat!\n"+
"She swallowed the goat to catch the dog.\n"+
"She swallowed the dog to catch the cat.\n"+
"She swallowed the cat to catch the bird.\n"+
"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.\n"+
"\n"+
"I know an old lady who swallowed a cow.\n"+
"I don't know how she swallowed a cow!\n"+
"She swallowed the cow to catch the goat.\n"+
"She swallowed the goat to catch the dog.\n"+
"She swallowed the dog to catch the cat.\n"+
"She swallowed the cat to catch the bird.\n"+
"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.\n"+
"\n"+
"I know an old lady who swallowed a horse.\n"+
"She's dead, of course!";
Assert.Equal(expected, FoodChain.Verse(1, 8));
}
}
13 changes: 5 additions & 8 deletions exercises/luhn/LuhnTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,30 @@ public void A_single_zero_is_invalid()
Assert.False(Luhn.IsValid("0"));
}


[Fact(Skip = "Remove to run test")]
public void A_simple_valid_SIN_that_remains_valid_if_reversed()
public void A_simple_valid_sin_that_remains_valid_if_reversed()
{
Assert.True(Luhn.IsValid("059"));
}

[Fact(Skip = "Remove to run test")]
public void A_simple_valid_SIN_that_becomes_invalid_if_reversed()
public void A_simple_valid_sin_that_becomes_invalid_if_reversed()
{
Assert.True(Luhn.IsValid("59"));
}

[Fact(Skip = "Remove to run test")]
public void A_valid_Canadian_SIN()
public void A_valid_canadian_sin()
{
Assert.True(Luhn.IsValid("055 444 285"));
}

[Fact(Skip = "Remove to run test")]
public void Invalid_Canadian_SIN()
public void Invalid_canadian_sin()
{
Assert.False(Luhn.IsValid("055 444 286"));
}


[Fact(Skip = "Remove to run test")]
public void Invalid_credit_card()
{
Expand Down Expand Up @@ -81,5 +79,4 @@ public void Input_digit_9_is_correctly_converted_to_output_digit_9()
{
Assert.True(Luhn.IsValid("091"));
}

}
}
10 changes: 10 additions & 0 deletions generators/Data/CanonicalDataValue.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Newtonsoft.Json.Linq;

namespace Generators.Data
{
public static class CanonicalDataValue
{
public static string StringArrayToString(object expected)
=> string.Join("\\n\"+\n\"", ((JArray) expected).Values<string>());
}
}
27 changes: 27 additions & 0 deletions generators/Exercises/FoodChainExercise.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Generators.Data;
using Generators.Methods;

namespace Generators.Exercises
{
public class FoodChainExercise : EqualityExercise
{
public FoodChainExercise() : base("food-chain")
{
}

protected override TestMethodData CreateTestMethodData(CanonicalData canonicalData, CanonicalDataCase canonicalDataCase, int index)
{
var testMethodData = base.CreateTestMethodData(canonicalData, canonicalDataCase, index);

testMethodData.Options.UseVariableForExpected = true;
testMethodData.CanonicalDataCase.Expected = CanonicalDataValue.StringArrayToString(canonicalDataCase.Expected);

if (testMethodData.CanonicalDataCase.Data.ContainsKey("end verse"))
testMethodData.CanonicalDataCase.Input = new[] { testMethodData.CanonicalDataCase.Data["start verse"], testMethodData.CanonicalDataCase.Data["end verse"] };
else
testMethodData.Options.InputProperty = "start verse";

return testMethodData;
}
}
}
4 changes: 1 addition & 3 deletions generators/Exercises/NthPrimeExercise.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System;
using Generators.Data;
using Generators.Methods;
using Humanizer;

namespace Generators.Exercises
{
Expand All @@ -13,7 +11,7 @@ public NthPrimeExercise() : base("nth-prime")

protected override TestMethod CreateTestMethod(TestMethodData testMethodData)
{
if (testMethodData.CanonicalDataCase.Expected is bool b)
if (testMethodData.CanonicalDataCase.Expected is bool b && !b)
{
testMethodData.Options.ExceptionType = typeof(ArgumentOutOfRangeException);
return CreateExceptionTestMethod(testMethodData);
Expand Down
Loading