Commits

Christoph Schindler committed 109cb90

10. Dojo: Weihnachten 2012

Comments (0)

Files changed (2)

Xmas2012/test_twelve_days.py

+#!/usr/bin/env python
+# encoding: utf-8
+"""
+test_twelve_days.py
+
+Created by Coding Dojo on 2012-12-16.
+"""
+
+from nose.tools import assert_equal
+
+import twelve_days
+
+def test_song():
+        assert_equal(twelve_days.song(),
+                 '\n'.join([
+                            "The first day of Christmas",
+                            "My true love gave to me",
+                            "A partridge in a pear tree",
+                            "",
+                            "The second day of Christmas",
+                            "My true love gave to me",
+                            "Two turtle doves,",
+                            "And a partridge in a pear tree",
+                            "",
+                            "The third day of Christmas",
+                            "My true love gave to me",
+                            "Three French hens,",
+                            "Two turtle doves,",
+                            "And a partridge in a pear tree",
+                            "",
+                            "The fourth day of Christmas",
+                            "My true love gave to me",
+                            "Four colly birds,",
+                            "Three French hens,",
+                            "Two turtle doves,",
+                            "And a partridge in a pear tree",
+                            "",
+                            "The fifth day of Christmas",
+                            "My true love gave to me",
+                            "Five gold rings,",
+                            "Four colly birds,",
+                            "Three French hens,",
+                            "Two turtle doves,",
+                            "And a partridge in a pear tree",
+                            "",
+                            "The sixth day of Christmas",
+                            "My true love gave to me",
+                            "Six geese a-laying,",
+                            "Five gold rings,",
+                            "Four colly birds,",
+                            "Three French hens,",
+                            "Two turtle doves,",
+                            "And a partridge in a pear tree",
+                            "",
+                            "The seventh day of Christmas",
+                            "My true love gave to me",
+                            "Seven swans a-swimming,",
+                            "Six geese a-laying,",
+                            "Five gold rings,",
+                            "Four colly birds,",
+                            "Three French hens,",
+                            "Two turtle doves,",
+                            "And a partridge in a pear tree",
+                            "",
+                            "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 colly birds,",
+                            "Three French hens,",
+                            "Two turtle doves,",
+                            "And a partridge in a pear tree",
+                            "",
+                            "The ninth day of Christmas",
+                            "My true love gave to me",
+                            "Nine drummers drumming,",
+                            "Eight maids a-milking,",
+                            "Seven swans a-swimming,",
+                            "Six geese a-laying,",
+                            "Five gold rings,",
+                            "Four colly birds,",
+                            "Three French hens,",
+                            "Two turtle doves,",
+                            "And a partridge in a pear tree",
+                            "",
+                            "The tenth day of Christmas",
+                            "My true love gave to me",
+                            "Ten ladies dancing,",
+                            "Nine drummers drumming,",
+                            "Eight maids a-milking,",
+                            "Seven swans a-swimming,",
+                            "Six geese a-laying,",
+                            "Five gold rings,",
+                            "Four colly birds,",
+                            "Three French hens,",
+                            "Two turtle doves,",
+                            "And a partridge in a pear tree",
+                            "",
+                            "The eleventh day of Christmas",
+                            "My true love gave to me",
+                            "Eleven pipers piping,",
+                            "Ten ladies dancing,",
+                            "Nine drummers drumming,",
+                            "Eight maids a-milking,",
+                            "Seven swans a-swimming,",
+                            "Six geese a-laying,",
+                            "Five gold rings,",
+                            "Four colly birds,",
+                            "Three French hens,",
+                            "Two turtle doves,",
+                            "And a partridge in a pear tree",
+                            "",
+                            "The twelfth day of Christmas",
+                            "My true love gave to me",
+                            "Twelve lords a-leaping,",
+                            "Eleven pipers piping,",
+                            "Ten ladies dancing,",
+                            "Nine drummers drumming,",
+                            "Eight maids a-milking,",
+                            "Seven swans a-swimming,",
+                            "Six geese a-laying,",
+                            "Five gold rings,",
+                            "Four colly birds,",
+                            "Three French hens,",
+                            "Two turtle doves,",
+                            "And a partridge in a pear tree",
+                            ]))
+
+
+def test_twelfth_verse():
+        assert_equal(twelve_days.verse(12),
+                 '\n'.join(["The twelfth day of Christmas",
+                            "My true love gave to me",
+                            "Twelve lords a-leaping,",
+                            "Eleven pipers piping,",
+                            "Ten ladies dancing,",
+                            "Nine drummers drumming,",
+                            "Eight maids a-milking,",
+                            "Seven swans a-swimming,",
+                            "Six geese a-laying,",
+                            "Five gold rings,",
+                            "Four colly birds,",
+                            "Three French hens,",
+                            "Two turtle doves,",
+                            "And a partridge in a pear tree"]))
+
+def test_fourth_verse():
+        assert_equal(twelve_days.verse(4),
+                 '\n'.join(["The fourth day of Christmas",
+                            "My true love gave to me",
+                            "Four colly birds,",
+                            "Three French hens,",
+                            "Two turtle doves,",
+                            "And a partridge in a pear tree"]))
+
+
+def test_third_verse():
+        assert_equal(twelve_days.verse(3),
+                 '\n'.join(["The third day of Christmas",
+                            "My true love gave to me",
+                            "Three French hens,",
+                            "Two turtle doves,",
+                            "And a partridge in a pear tree"]))
+
+def test_first_verse():
+    assert_equal(twelve_days.verse(1),
+                 '\n'.join(["The first day of Christmas",
+                            "My true love gave to me",
+                            "A partridge in a pear tree"]))
+
+def test_second_verse():
+    assert_equal(twelve_days.verse(2),
+                 '\n'.join(["The second day of Christmas",
+                            "My true love gave to me",
+                            "Two turtle doves,",
+                            "And a partridge in a pear tree"]))

Xmas2012/twelve_days.py

+#!/usr/bin/env python
+# encoding: utf-8
+"""
+twelve_days.py
+
+Created by Coding Dojo on 2012-12-16.
+"""
+
+ORDINALS = {
+    1: "first",
+    2: "second",
+    3: "third",
+    4: "fourth",
+    5: "fifth",
+    6: "sixth",
+    7: "seventh",
+    8: "eighth",
+    9: "ninth",
+    10: "tenth",
+    11: "eleventh",
+    12: "twelfth"
+}
+
+DAYS = [
+    "A partridge in a pear tree",
+    "Two turtle doves,",
+    "Three French hens,",
+    "Four colly birds,",
+    "Five gold rings,",
+    "Six geese a-laying,",
+    "Seven swans a-swimming,",
+    "Eight maids a-milking,",
+    "Nine drummers drumming,",
+    "Ten ladies dancing,",
+    "Eleven pipers piping,",
+    "Twelve lords a-leaping,"
+]
+
+def verse(number):
+    result = []
+    result.append("The %s day of Christmas" % ORDINALS[number])
+    result.append("My true love gave to me")
+    result.extend(reversed(DAYS[1:number]))
+
+    if number > 1:
+        result.append("And " + DAYS[0].lower())
+    else:
+        result.append(DAYS[0])
+
+    return '\n'.join(result)
+
+def song():
+    return '\n\n'.join(verse(i) for i in range(1, 13))
+
+if __name__ == '__main__':
+	print song()
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.