-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
twelve-days: re-implement according to canonical data #1306
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
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
991807a
twelve-days: update tests to v1.1.0
mrcfps 93d5984
twelve-days: re-implement stub to match canonical data
mrcfps 778deb0
twelve-days: improve example to pass tests v1.1.0
mrcfps 4d12776
twelve-days: adopt concise tests of lyrics
mrcfps 6955e84
Merge branch 'master' into twelve-days-1221
cmccandless File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,2 @@ | ||
def verse(day_number): | ||
pass | ||
|
||
|
||
def verses(start, end): | ||
pass | ||
|
||
|
||
def sing(): | ||
def recite(start_verse, end_verse): | ||
pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,81 @@ | ||
import unittest | ||
|
||
from twelve_days import sing, verse, verses | ||
from twelve_days import recite | ||
|
||
|
||
class TwelveDaysTests(unittest.TestCase): | ||
# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0 | ||
|
||
class VerseTests(unittest.TestCase): | ||
def test_verse1(self): | ||
expected = ("On the first day of Christmas my true love gave to me, " | ||
"a Partridge in a Pear Tree.\n") | ||
self.assertEqual(verse(1), expected) | ||
expected = ["On the first day of Christmas my true love gave to me, " | ||
"a Partridge in a Pear Tree."] | ||
self.assertEqual(recite(1, 1), expected) | ||
|
||
def test_verse2(self): | ||
expected = ("On the second day of Christmas my true love gave to me, " | ||
expected = ["On the second day of Christmas my true love gave to me, " | ||
"two Turtle Doves, " | ||
"and a Partridge in a Pear Tree.\n") | ||
self.assertEqual(verse(2), expected) | ||
"and a Partridge in a Pear Tree."] | ||
self.assertEqual(recite(2, 2), expected) | ||
|
||
def test_verse3(self): | ||
expected = ("On the third day of Christmas my true love gave to me, " | ||
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") | ||
self.assertEqual(verse(3), expected) | ||
"and a Partridge in a Pear Tree."] | ||
self.assertEqual(recite(3, 3), expected) | ||
|
||
def test_verse4(self): | ||
expected = ("On the fourth day of Christmas my true love gave to me, " | ||
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") | ||
self.assertEqual(verse(4), expected) | ||
"and a Partridge in a Pear Tree."] | ||
self.assertEqual(recite(4, 4), expected) | ||
|
||
def test_verse5(self): | ||
expected = ("On the fifth day of Christmas my true love gave to me, " | ||
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") | ||
self.assertEqual(verse(5), expected) | ||
"and a Partridge in a Pear Tree."] | ||
self.assertEqual(recite(5, 5), expected) | ||
|
||
def test_verse6(self): | ||
expected = ("On the sixth day of Christmas my true love gave to me, " | ||
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") | ||
self.assertEqual(verse(6), expected) | ||
"and a Partridge in a Pear Tree."] | ||
self.assertEqual(recite(6, 6), expected) | ||
|
||
def test_verse7(self): | ||
expected = ("On the seventh day of Christmas my true love gave to me, " | ||
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") | ||
self.assertEqual(verse(7), expected) | ||
"and a Partridge in a Pear Tree."] | ||
self.assertEqual(recite(7, 7), expected) | ||
|
||
def test_verse8(self): | ||
expected = ("On the eighth day of Christmas my true love gave to me, " | ||
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") | ||
self.assertEqual(verse(8), expected) | ||
"and a Partridge in a Pear Tree."] | ||
self.assertEqual(recite(8, 8), expected) | ||
|
||
def test_verse9(self): | ||
expected = ("On the ninth day of Christmas my true love gave to me, " | ||
expected = ["On the ninth day of Christmas my true love gave to me, " | ||
"nine Ladies Dancing, " | ||
"eight Maids-a-Milking, " | ||
"seven Swans-a-Swimming, " | ||
|
@@ -82,11 +84,11 @@ def test_verse9(self): | |
"four Calling Birds, " | ||
"three French Hens, " | ||
"two Turtle Doves, " | ||
"and a Partridge in a Pear Tree.\n") | ||
self.assertEqual(verse(9), expected) | ||
"and a Partridge in a Pear Tree."] | ||
self.assertEqual(recite(9, 9), expected) | ||
|
||
def test_verse10(self): | ||
expected = ("On the tenth day of Christmas my true love gave to me, " | ||
expected = ["On the tenth day of Christmas my true love gave to me, " | ||
"ten Lords-a-Leaping, " | ||
"nine Ladies Dancing, " | ||
"eight Maids-a-Milking, " | ||
|
@@ -96,11 +98,11 @@ def test_verse10(self): | |
"four Calling Birds, " | ||
"three French Hens, " | ||
"two Turtle Doves, " | ||
"and a Partridge in a Pear Tree.\n") | ||
self.assertEqual(verse(10), expected) | ||
"and a Partridge in a Pear Tree."] | ||
self.assertEqual(recite(10, 10), expected) | ||
|
||
def test_verse11(self): | ||
expected = ("On the eleventh day of Christmas " | ||
expected = ["On the eleventh day of Christmas " | ||
"my true love gave to me, " | ||
"eleven Pipers Piping, " | ||
"ten Lords-a-Leaping, " | ||
|
@@ -112,11 +114,11 @@ def test_verse11(self): | |
"four Calling Birds, " | ||
"three French Hens, " | ||
"two Turtle Doves, " | ||
"and a Partridge in a Pear Tree.\n") | ||
self.assertEqual(verse(11), expected) | ||
"and a Partridge in a Pear Tree."] | ||
self.assertEqual(recite(11, 11), expected) | ||
|
||
def test_verse12(self): | ||
expected = ("On the twelfth day of Christmas my true love gave to me, " | ||
expected = ["On the twelfth day of Christmas my true love gave to me, " | ||
"twelve Drummers Drumming, " | ||
"eleven Pipers Piping, " | ||
"ten Lords-a-Leaping, " | ||
|
@@ -128,23 +130,137 @@ def test_verse12(self): | |
"four Calling Birds, " | ||
"three French Hens, " | ||
"two Turtle Doves, " | ||
"and a Partridge in a Pear Tree.\n") | ||
self.assertEqual(verse(12), expected) | ||
"and a Partridge in a Pear Tree."] | ||
self.assertEqual(recite(12, 12), expected) | ||
|
||
|
||
def test_multiple_verses(self): | ||
expected = ("On the first day of Christmas my true love gave to me, " | ||
"a Partridge in a Pear Tree.\n\n" | ||
class LyricsTests(unittest.TestCase): | ||
def test_first_three_verses_of_the_song(self): | ||
expected = ["On the first day of Christmas my true love gave to me, " | ||
"a Partridge in a Pear Tree.", | ||
"On the second day of Christmas my true love gave to me, " | ||
"two Turtle Doves, " | ||
"and a Partridge in a Pear Tree.\n\n" | ||
"and a Partridge in a Pear Tree.", | ||
"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") | ||
self.assertEqual(verses(1, 3), expected) | ||
"and a Partridge in a Pear Tree."] | ||
self.assertEqual(recite(1, 3), expected) | ||
|
||
def test_three_verses_from_the_middle_of_the_song(self): | ||
expected = ["On the fourth day of Christmas my true love gave to me, " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, |
||
"four Calling Birds, " | ||
"three French Hens, " | ||
"two Turtle Doves, " | ||
"and a Partridge in a Pear Tree.", | ||
"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.", | ||
"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."] | ||
self.assertEqual(recite(4, 6), expected) | ||
|
||
def test_the_whole_song(self): | ||
self.assertEqual(verses(1, 12), sing()) | ||
expected = ["On the first day of Christmas my true love gave to me, " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, |
||
"a Partridge in a Pear Tree.", | ||
"On the second day of Christmas my true love gave to me, " | ||
"two Turtle Doves, " | ||
"and a Partridge in a Pear Tree.", | ||
"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.", | ||
"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.", | ||
"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.", | ||
"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.", | ||
"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.", | ||
"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.", | ||
"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.", | ||
"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.", | ||
"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.", | ||
"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."] | ||
self.assertEqual(recite(1, 12), expected) | ||
|
||
|
||
if __name__ == '__main__': | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since there are other tests verifying correct output from
recite(n, n)
, I think the following would be adequate:This also removes the need for large redundant text blocks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cmccandless Pretty nice trick! But since
recite
returns a list of one string, we should capture its first element:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the idea of nice tricks...
Not really any neater than what you're already doing, and it's not as readable, so please don't use that for this exercise.