Bläddra i källkod

Merge pull request #239 from FridaTveit/TwelveDaysExercise

twelve-days: add to track
Stuart Kent 9 år sedan
förälder
incheckning
54afd5d7f4

+ 6
- 0
config.json Visa fil

@@ -54,6 +54,7 @@
54 54
     "custom-set",
55 55
     "wordy",
56 56
     "palindrome-products",
57
+    "twelve-days",
57 58
     "sublist"
58 59
   ],
59 60
   "exercises": [
@@ -308,6 +309,11 @@
308 309
       "topics": []
309 310
     },
310 311
     {
312
+      "slug": "twelve-days",
313
+      "difficulty": 1,
314
+      "topics": []
315
+    },
316
+    {
311 317
       "slug": "sublist",
312 318
       "difficulty": 1,
313 319
       "topics": []

+ 2
- 0
exercises/settings.gradle Visa fil

@@ -52,3 +52,5 @@ include 'triangle'
52 52
 include 'trinary'
53 53
 include 'word-count'
54 54
 include 'wordy'
55
+include 'twelve-days'
56
+

+ 17
- 0
exercises/twelve-days/build.gradle Visa fil

@@ -0,0 +1,17 @@
1
+apply plugin: "java"
2
+apply plugin: "eclipse"
3
+apply plugin: "idea"
4
+
5
+repositories {
6
+    mavenCentral()
7
+}
8
+
9
+dependencies {
10
+    testCompile "junit:junit:4.12"
11
+}
12
+test {
13
+    testLogging {
14
+        exceptionFormat = 'full'
15
+        events = ["passed", "failed", "skipped"]
16
+    }
17
+}

+ 46
- 0
exercises/twelve-days/src/example/java/TwelveDays.java Visa fil

@@ -0,0 +1,46 @@
1
+public class TwelveDays {
2
+    private static String[] days = new String[] {"first", "second", "third", "fourth", "fifth", "sixth", "seventh",
3
+        "eighth", "ninth", "tenth", "eleventh", "twelfth"};
4
+    private static String[] gifts = new String[] {
5
+            "a Partridge in a Pear Tree.",
6
+            "two Turtle Doves, ",
7
+            "three French Hens, ",
8
+            "four Calling Birds, ",
9
+            "five Gold Rings, ",
10
+            "six Geese-a-Laying, ",
11
+            "seven Swans-a-Swimming, ",
12
+            "eight Maids-a-Milking, ",
13
+            "nine Ladies Dancing, ",
14
+            "ten Lords-a-Leaping, ",
15
+            "eleven Pipers Piping, ",
16
+            "twelve Drummers Drumming, "
17
+    };
18
+
19
+    public static String verse(int verseNumber) {
20
+        return constructVerse(verseNumber);
21
+    }
22
+
23
+    public static String verses(int verseNumberStart, int verseNumberEnd) {
24
+        StringBuilder stringBuilder = new StringBuilder(constructVerse(verseNumberStart));
25
+        for (int i = verseNumberStart + 1; i <= verseNumberEnd; i++) {
26
+            stringBuilder.append("\n");
27
+            stringBuilder.append(constructVerse(i));
28
+        }
29
+        return stringBuilder.toString();
30
+    }
31
+
32
+    public static String sing() {
33
+        return verses(1, 12);
34
+    }
35
+
36
+    private static String constructVerse(int verseNumber) {
37
+        StringBuilder stringBuilder = new StringBuilder("On the " + days[verseNumber - 1]
38
+                + " day of Christmas my true love gave to me, ");
39
+        for (int i = verseNumber; i > 0; i--) {
40
+            if (verseNumber != 1 && i == 1) stringBuilder.append("and ");
41
+            stringBuilder.append(gifts[i - 1]);
42
+        }
43
+        stringBuilder.append("\n");
44
+        return stringBuilder.toString();
45
+    }
46
+}

+ 0
- 0
exercises/twelve-days/src/main/java/.keep Visa fil


+ 172
- 0
exercises/twelve-days/src/test/java/TwelveDaysTest.java Visa fil

@@ -0,0 +1,172 @@
1
+import org.junit.Ignore;
2
+import org.junit.Test;
3
+
4
+import static org.junit.Assert.assertEquals;
5
+
6
+public class TwelveDaysTest {
7
+
8
+    @Test
9
+    public void testVerseOne() {
10
+        String expectedVerseOne = "On the first day of Christmas my true love gave to me, " +
11
+                "a Partridge in a Pear Tree.\n";
12
+        assertEquals(expectedVerseOne, TwelveDays.verse(1));
13
+    }
14
+
15
+    @Ignore
16
+    @Test
17
+    public void testVerseTwo() {
18
+        String expectedVerseTwo = "On the second day of Christmas my true love gave to me, two Turtle Doves, " +
19
+                "and a Partridge in a Pear Tree.\n";
20
+        assertEquals(expectedVerseTwo, TwelveDays.verse(2));
21
+    }
22
+
23
+    @Ignore
24
+    @Test
25
+    public void testVerseThree() {
26
+        String expectedVerseThree = "On the third day of Christmas my true love gave to me, three French Hens, " +
27
+                "two Turtle Doves, and a Partridge in a Pear Tree.\n";
28
+        assertEquals(expectedVerseThree, TwelveDays.verse(3));
29
+    }
30
+
31
+    @Ignore
32
+    @Test
33
+    public void testVerseFour() {
34
+        String expectedVerseFour = "On the fourth day of Christmas my true love gave to me, four Calling Birds, " +
35
+                "three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\n";
36
+        assertEquals(expectedVerseFour, TwelveDays.verse(4));
37
+    }
38
+
39
+    @Ignore
40
+    @Test
41
+    public void testVerseFive() {
42
+        String expectedVerseFive = "On the fifth day of Christmas my true love gave to me, five Gold Rings, " +
43
+                "four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\n";
44
+        assertEquals(expectedVerseFive, TwelveDays.verse(5));
45
+    }
46
+
47
+    @Ignore
48
+    @Test
49
+    public void testVerseSix() {
50
+        String expectedVerseSix = "On the sixth day of Christmas my true love gave to me, six Geese-a-Laying, " +
51
+                "five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, " +
52
+                "and a Partridge in a Pear Tree.\n";
53
+        assertEquals(expectedVerseSix, TwelveDays.verse(6));
54
+    }
55
+
56
+    @Ignore
57
+    @Test
58
+    public void testVerseSeven() {
59
+        String expectedVerseSeven = "On the seventh day of Christmas my true love gave to me, " +
60
+                "seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, " +
61
+                "two Turtle Doves, and a Partridge in a Pear Tree.\n";
62
+        assertEquals(expectedVerseSeven, TwelveDays.verse(7));
63
+    }
64
+
65
+    @Ignore
66
+    @Test
67
+    public void testVerseEight() {
68
+        String expectedVerseEight = "On the eighth day of Christmas my true love gave to me, eight Maids-a-Milking," +
69
+                " seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, " +
70
+                "three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\n";
71
+        assertEquals(expectedVerseEight, TwelveDays.verse(8));
72
+    }
73
+
74
+    @Ignore
75
+    @Test
76
+    public void testVerseNine() {
77
+        String expectedVerseNine = "On the ninth day of Christmas my true love gave to me, nine Ladies Dancing, " +
78
+                "eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, " +
79
+                "four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\n";
80
+        assertEquals(expectedVerseNine, TwelveDays.verse(9));
81
+    }
82
+
83
+    @Ignore
84
+    @Test
85
+    public void testVerseTen() {
86
+        String expectedVerseTen = "On the tenth day of Christmas my true love gave to me, ten Lords-a-Leaping, " +
87
+                "nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, " +
88
+                "five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, " +
89
+                "and a Partridge in a Pear Tree.\n";
90
+        assertEquals(expectedVerseTen, TwelveDays.verse(10));
91
+    }
92
+
93
+    @Ignore
94
+    @Test
95
+    public void testVerseEleven() {
96
+        String expectedVerseEleven = "On the eleventh day of Christmas my true love gave to me, " +
97
+                "eleven Pipers Piping, ten Lords-a-Leaping, nine Ladies Dancing, eight Maids-a-Milking, " +
98
+                "seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, " +
99
+                "three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\n";
100
+        assertEquals(expectedVerseEleven, TwelveDays.verse(11));
101
+    }
102
+
103
+    @Ignore
104
+    @Test
105
+    public void testVerseTwelve() {
106
+        String expectedVerseTwelve = "On the twelfth day of Christmas my true love gave to me, " +
107
+                "twelve Drummers Drumming, eleven Pipers Piping, ten Lords-a-Leaping, nine Ladies Dancing, " +
108
+                "eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, " +
109
+                "four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\n";
110
+        assertEquals(expectedVerseTwelve, TwelveDays.verse(12));
111
+    }
112
+
113
+    @Ignore
114
+    @Test
115
+    public void testMultipleVerses() {
116
+        String expectedVerseOneToThree = "On the first day of Christmas my true love gave to me, " +
117
+                "a Partridge in a Pear Tree.\n\n" +
118
+                "On the second day of Christmas my true love gave to me, two Turtle Doves, " +
119
+                "and a Partridge in a Pear Tree.\n\n" +
120
+                "On the third day of Christmas my true love gave to me, three French Hens, two Turtle Doves, " +
121
+                "and a Partridge in a Pear Tree.\n";
122
+        assertEquals(expectedVerseOneToThree, TwelveDays.verses(1, 3));
123
+    }
124
+
125
+    @Ignore
126
+    @Test
127
+    public void testSingWholeSong() {
128
+        String expectedSong = "On the first day of Christmas my true love gave to me, a Partridge in a Pear Tree.\n" +
129
+                "\n" +
130
+                "On the second day of Christmas my true love gave to me, two Turtle Doves, " +
131
+                "and a Partridge in a Pear Tree.\n" +
132
+                "\n" +
133
+                "On the third day of Christmas my true love gave to me, three French Hens, two Turtle Doves, " +
134
+                "and a Partridge in a Pear Tree.\n" +
135
+                "\n" +
136
+                "On the fourth day of Christmas my true love gave to me, four Calling Birds, three French Hens, " +
137
+                "two Turtle Doves, and a Partridge in a Pear Tree.\n" +
138
+                "\n" +
139
+                "On the fifth day of Christmas my true love gave to me, five Gold Rings, four Calling Birds, " +
140
+                "three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\n" +
141
+                "\n" +
142
+                "On the sixth day of Christmas my true love gave to me, six Geese-a-Laying, five Gold Rings, " +
143
+                "four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\n" +
144
+                "\n" +
145
+                "On the seventh day of Christmas my true love gave to me, seven Swans-a-Swimming, " +
146
+                "six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, " +
147
+                "and a Partridge in a Pear Tree.\n" +
148
+                "\n" +
149
+                "On the eighth day of Christmas my true love gave to me, eight Maids-a-Milking, " +
150
+                "seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, " +
151
+                "three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\n" +
152
+                "\n" +
153
+                "On the ninth day of Christmas my true love gave to me, nine Ladies Dancing, eight Maids-a-Milking," +
154
+                " seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, " +
155
+                "three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\n" +
156
+                "\n" +
157
+                "On the tenth day of Christmas my true love gave to me, ten Lords-a-Leaping, nine Ladies Dancing," +
158
+                " eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, " +
159
+                "four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\n" +
160
+                "\n" +
161
+                "On the eleventh day of Christmas my true love gave to me, eleven Pipers Piping, " +
162
+                "ten Lords-a-Leaping, nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, " +
163
+                "six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, " +
164
+                "and a Partridge in a Pear Tree.\n" +
165
+                "\n" +
166
+                "On the twelfth day of Christmas my true love gave to me, twelve Drummers Drumming, " +
167
+                "eleven Pipers Piping, ten Lords-a-Leaping, nine Ladies Dancing, eight Maids-a-Milking, " +
168
+                "seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, " +
169
+                "three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.\n";
170
+        assertEquals(expectedSong, TwelveDays.sing());
171
+    }
172
+}