Skip to content

Added twelve days exercise #9

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 2 commits into from
May 12, 2014
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
1 change: 1 addition & 0 deletions EXERCISES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ phone-number
robot-name
sum-of-multiples
meetup
twelve-days
55 changes: 55 additions & 0 deletions twelve-days/Example.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

public class TwelveDaysSong
{
public string Sing()
{
return Verses(1, 12);
}

public string Verse(int verseNumber)
{
switch(verseNumber)
{
case 1:
return "On the first day of Christmas my true love gave to me, a Partridge in a Pear Tree.\n";
case 2:
return "On the second day of Christmas my true love gave to me, two Turtle Doves, and a Partridge in a Pear Tree.\n";
case 3:
return "On the third day of Christmas my true love gave to me, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\n";
case 4:
return "On the fourth day of Christmas my true love gave to me, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\n";
case 5:
return "On the fifth day of Christmas my true love gave to me, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\n";
case 6:
return "On the sixth day of Christmas my true love gave to me, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\n";
case 7:
return "On the seventh day of Christmas my true love gave to me, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\n";
case 8:
return "On the eighth day of Christmas my true love gave to me, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\n";
case 9:
return "On the ninth day of Christmas my true love gave to me, nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\n";
case 10:
return "On the tenth day of Christmas my true love gave to me, ten Lords-a-Leaping, nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\n";
case 11:
return "On the eleventh day of Christmas my true love gave to me, eleven Pipers Piping, ten Lords-a-Leaping, nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\n";
case 12:
return "On the twelfth day of Christmas my true love gave to me, twelve Drummers Drumming, eleven Pipers Piping, ten Lords-a-Leaping, nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\n";
default:
return "";
}
}

public string Verses(int start, int end)
{
var stringBuilder = new StringBuilder();

Enumerable.Range(start, end).ToList().ForEach(i => stringBuilder.Append(Verse(i)).Append("\n"));

return stringBuilder.ToString();
}
}
138 changes: 138 additions & 0 deletions twelve-days/TwelveDaysTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
using NUnit.Framework;

[TestFixture]
public class TwelveDaysTest
{
private TwelveDaysSong twelveDaysSong;

[SetUp]
public void Setup()
{
twelveDaysSong = new TwelveDaysSong();
}

[Test]
public void Return_Verse_1()
{
var expected = "On the first day of Christmas my true love gave to me, a Partridge in a Pear Tree.\n";

Assert.That(twelveDaysSong.Verse(1), Is.EqualTo(expected));
}

[Test]
[Ignore]
public void Return_Verse_2()
{
var expected = "On the second day of Christmas my true love gave to me, two Turtle Doves, and a Partridge in a Pear Tree.\n";

Assert.That(twelveDaysSong.Verse(2), Is.EqualTo(expected));
}

[Test]
[Ignore]
public void Return_Verse_3()
{
var expected = "On the third day of Christmas my true love gave to me, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\n";

Assert.That(twelveDaysSong.Verse(3), Is.EqualTo(expected));
}

[Test]
[Ignore]
public void Return_Verse_4()
{
var expected = "On the fourth day of Christmas my true love gave to me, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\n";

Assert.That(twelveDaysSong.Verse(4), Is.EqualTo(expected));
}

[Test]
[Ignore]
public void Return_Verse_5()
{
var expected = "On the fifth day of Christmas my true love gave to me, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\n";

Assert.That(twelveDaysSong.Verse(5), Is.EqualTo(expected));
}

[Test]
[Ignore]
public void Return_Verse_6()
{
var expected = "On the sixth day of Christmas my true love gave to me, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\n";

Assert.That(twelveDaysSong.Verse(6), Is.EqualTo(expected));
}

[Test]
[Ignore]
public void Return_Verse_7()
{
var expected = "On the seventh day of Christmas my true love gave to me, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\n";

Assert.That(twelveDaysSong.Verse(7), Is.EqualTo(expected));
}

[Test]
[Ignore]
public void Return_Verse_8()
{
var expected = "On the eighth day of Christmas my true love gave to me, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\n";

Assert.That(twelveDaysSong.Verse(8), Is.EqualTo(expected));
}

[Test]
[Ignore]
public void Return_Verse_9()
{
var expected = "On the ninth day of Christmas my true love gave to me, nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\n";

Assert.That(twelveDaysSong.Verse(9), Is.EqualTo(expected));
}

[Test]
[Ignore]
public void Return_Verse_10()
{
var expected = "On the tenth day of Christmas my true love gave to me, ten Lords-a-Leaping, nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\n";

Assert.That(twelveDaysSong.Verse(10), Is.EqualTo(expected));
}

[Test]
[Ignore]
public void Return_Verse_11()
{
var expected = "On the eleventh day of Christmas my true love gave to me, eleven Pipers Piping, ten Lords-a-Leaping, nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\n";

Assert.That(twelveDaysSong.Verse(11), Is.EqualTo(expected));
}

[Test]
[Ignore]
public void Return_Verse_12()
{
var expected = "On the twelfth day of Christmas my true love gave to me, twelve Drummers Drumming, eleven Pipers Piping, ten Lords-a-Leaping, nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\n";

Assert.That(twelveDaysSong.Verse(12), Is.EqualTo(expected));
}

[Test]
[Ignore]
public void Return_Multiple_Verses()
{
var expected = "On the first day of Christmas my true love gave to me, a Partridge in a Pear Tree.\n\n" +
"On the second day of Christmas my true love gave to me, two Turtle Doves, and a Partridge in a Pear Tree.\n\n" +
"On the third day of Christmas my true love gave to me, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\n\n";

Assert.That(twelveDaysSong.Verses(1, 3), Is.EqualTo(expected));
}

[Test]
[Ignore]
public void Return_Entire_Song()
{
Assert.That(twelveDaysSong.Verses(1, 12), Is.EqualTo(twelveDaysSong.Sing()));
}
}