|
| 1 | +module twelve_days; |
| 2 | + |
| 3 | +pure string recite(int startVerse, int endVerse) |
| 4 | +{ |
| 5 | + // implement this function |
| 6 | +} |
| 7 | + |
| 8 | +unittest |
| 9 | +{ |
| 10 | + immutable int allTestsEnabled = 0; |
| 11 | + |
| 12 | + // Verse-first day a partridge in a pear tree |
| 13 | + { |
| 14 | + string expected = |
| 15 | + "On the first day of Christmas my true love gave to me: a Partridge in a Pear Tree."; |
| 16 | + assert(recite(1, 1) == expected); |
| 17 | + } |
| 18 | + |
| 19 | + static if (allTestsEnabled) |
| 20 | + { |
| 21 | + // Verse-second day two turtle doves |
| 22 | + { |
| 23 | + string expected = |
| 24 | + "On the second day of Christmas my true love gave to me: two Turtle Doves, and a Partridge in a Pear Tree."; |
| 25 | + assert(recite(2, 2) == expected); |
| 26 | + } |
| 27 | + |
| 28 | + // Verse-third day three french hens |
| 29 | + { |
| 30 | + string expected = |
| 31 | + "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."; |
| 32 | + assert(recite(3, 3) == expected); |
| 33 | + } |
| 34 | + |
| 35 | + // Verse-fourth day four calling birds |
| 36 | + { |
| 37 | + string expected = |
| 38 | + "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."; |
| 39 | + assert(recite(4, 4) == expected); |
| 40 | + } |
| 41 | + |
| 42 | + // Verse-fifth day five gold rings |
| 43 | + { |
| 44 | + string expected = |
| 45 | + "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."; |
| 46 | + assert(recite(5, 5) == expected); |
| 47 | + } |
| 48 | + |
| 49 | + // Verse-sixth day six geese-a-laying |
| 50 | + { |
| 51 | + string expected = |
| 52 | + "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."; |
| 53 | + assert(recite(6, 6) == expected); |
| 54 | + } |
| 55 | + |
| 56 | + // Verse-seventh day seven swans-a-swimming |
| 57 | + { |
| 58 | + string expected = |
| 59 | + "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."; |
| 60 | + assert(recite(7, 7) == expected); |
| 61 | + } |
| 62 | + |
| 63 | + // Verse-eighth day eight maids-a-milking |
| 64 | + { |
| 65 | + string expected = |
| 66 | + "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."; |
| 67 | + assert(recite(8, 8) == expected); |
| 68 | + } |
| 69 | + |
| 70 | + // Verse-ninth day nine ladies dancing |
| 71 | + { |
| 72 | + string expected = |
| 73 | + "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."; |
| 74 | + assert(recite(9, 9) == expected); |
| 75 | + } |
| 76 | + |
| 77 | + // Verse-tenth day ten lords-a-leaping |
| 78 | + { |
| 79 | + string expected = |
| 80 | + "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."; |
| 81 | + assert(recite(10, 10) == expected); |
| 82 | + } |
| 83 | + |
| 84 | + // Verse-eleventh day eleven pipers piping |
| 85 | + { |
| 86 | + string expected = |
| 87 | + "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."; |
| 88 | + assert(recite(11, 11) == expected); |
| 89 | + } |
| 90 | + |
| 91 | + // Verse-twelfth day twelve drummers drumming |
| 92 | + { |
| 93 | + string expected = |
| 94 | + "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."; |
| 95 | + assert(recite(12, 12) == expected); |
| 96 | + } |
| 97 | + |
| 98 | + // Lyrics-recites first three verses of the song |
| 99 | + { |
| 100 | + string expected = |
| 101 | + "On the first day of Christmas my true love gave to me: a Partridge in a Pear Tree.\n" ~ |
| 102 | + "On the second day of Christmas my true love gave to me: two Turtle Doves, and a Partridge in a Pear Tree.\n" ~ |
| 103 | + "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."; |
| 104 | + assert(recite(1, 3) == expected); |
| 105 | + } |
| 106 | + |
| 107 | + // Lyrics-recites three verses from the middle of the song |
| 108 | + { |
| 109 | + string expected = |
| 110 | + "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" ~ |
| 111 | + "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" ~ |
| 112 | + "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."; |
| 113 | + assert(recite(4, 6) == expected); |
| 114 | + } |
| 115 | + |
| 116 | + // Lyrics-recites the whole song |
| 117 | + { |
| 118 | + string expected = |
| 119 | + "On the first day of Christmas my true love gave to me: a Partridge in a Pear Tree.\n" ~ |
| 120 | + "On the second day of Christmas my true love gave to me: two Turtle Doves, and a Partridge in a Pear Tree.\n" ~ |
| 121 | + "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" ~ |
| 122 | + "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" ~ |
| 123 | + "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" ~ |
| 124 | + "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" ~ |
| 125 | + "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" ~ |
| 126 | + "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" ~ |
| 127 | + "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" ~ |
| 128 | + "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" ~ |
| 129 | + "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" ~ |
| 130 | + "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."; |
| 131 | + assert(recite(1, 12) == expected); |
| 132 | + } |
| 133 | + } |
| 134 | +} |
0 commit comments