|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+import org.junit.Test;
|
|
|
2
|
+import org.junit.runner.RunWith;
|
|
|
3
|
+import org.junit.runners.Parameterized;
|
|
|
4
|
+
|
|
|
5
|
+import java.util.Arrays;
|
|
|
6
|
+import java.util.Collection;
|
|
|
7
|
+
|
|
|
8
|
+import static org.junit.Assert.assertEquals;
|
|
|
9
|
+
|
|
|
10
|
+@RunWith(Parameterized.class)
|
|
|
11
|
+public class PigLatinTest {
|
|
|
12
|
+
|
|
|
13
|
+ private String input;
|
|
|
14
|
+ private String expectedOutput;
|
|
|
15
|
+
|
|
|
16
|
+ @Parameterized.Parameters
|
|
|
17
|
+ public static Collection<Object[]> data() {
|
|
|
18
|
+ return Arrays.asList(new Object[][]{
|
|
|
19
|
+ // Ay is added to words that start with vowels
|
|
|
20
|
+ {"apple", "appleay"},
|
|
|
21
|
+ {"ear", "earay"},
|
|
|
22
|
+ {"igloo", "iglooay"},
|
|
|
23
|
+ {"object", "objectay"},
|
|
|
24
|
+ {"under", "underay"},
|
|
|
25
|
+
|
|
|
26
|
+ // First letter and ay are moved to the end of words that start with consonants
|
|
|
27
|
+ {"pig", "igpay"},
|
|
|
28
|
+ {"koala", "oalakay"},
|
|
|
29
|
+ {"yellow", "ellowyay"},
|
|
|
30
|
+ {"xenon", "enonxay"},
|
|
|
31
|
+
|
|
|
32
|
+ // Ch is treated like a single consonant
|
|
|
33
|
+ {"chair", "airchay"},
|
|
|
34
|
+
|
|
|
35
|
+ // Qu is treated like a single consonant
|
|
|
36
|
+ {"queen", "eenquay"},
|
|
|
37
|
+
|
|
|
38
|
+ // Qu and a single preceding consonant are treated like a single consonant
|
|
|
39
|
+ {"square", "aresquay"},
|
|
|
40
|
+
|
|
|
41
|
+ // Th is treated like a single consonant
|
|
|
42
|
+ {"therapy", "erapythay"},
|
|
|
43
|
+
|
|
|
44
|
+ // Thr is treated like a single consonant
|
|
|
45
|
+ {"thrush", "ushthray"},
|
|
|
46
|
+
|
|
|
47
|
+ // Sch is treated like a single consonant
|
|
|
48
|
+ {"school", "oolschay"},
|
|
|
49
|
+
|
|
|
50
|
+ // Yt is treated like a single vowel
|
|
|
51
|
+ {"yttria", "yttriaay"},
|
|
|
52
|
+
|
|
|
53
|
+ // Xr is treated like a single vowel
|
|
|
54
|
+ {"xray", "xrayay"},
|
|
|
55
|
+
|
|
|
56
|
+ // Phrases are translated
|
|
|
57
|
+ {"quick fast run", "ickquay astfay unray"}
|
|
|
58
|
+ });
|
|
|
59
|
+ }
|
|
|
60
|
+
|
|
|
61
|
+ public PigLatinTest(String input, String expectedOutput) {
|
|
|
62
|
+ this.input = input;
|
|
|
63
|
+ this.expectedOutput = expectedOutput;
|
|
|
64
|
+ }
|
|
|
65
|
+
|
|
|
66
|
+ @Test
|
|
|
67
|
+ public void test() {
|
|
|
68
|
+ assertEquals(expectedOutput, PigLatin.translate(input));
|
|
|
69
|
+ }
|
|
|
70
|
+}
|