Explorar el Código

Change order and names of anagram tests

Changed names of tests to be consistent and changed the order
so that similar tests are grouped together. Added more tests
using the canonical data.
Frida Tveit hace 9 años
padre
commit
aad09a42f9
Se han modificado 1 ficheros con 41 adiciones y 13 borrados
  1. 41
    13
      exercises/anagram/src/test/java/AnagramTest.java

+ 41
- 13
exercises/anagram/src/test/java/AnagramTest.java Ver fichero

18
 
18
 
19
     @Ignore
19
     @Ignore
20
     @Test
20
     @Test
21
-    public void testSimpleAnagram() {
21
+    public void testDetectSimpleAnagram() {
22
         Anagram detector = new Anagram("ant");
22
         Anagram detector = new Anagram("ant");
23
         List<String> anagram = detector.match(Arrays.asList("tan", "stand", "at"));
23
         List<String> anagram = detector.match(Arrays.asList("tan", "stand", "at"));
24
         assertThat(anagram, hasItem("tan"));
24
         assertThat(anagram, hasItem("tan"));
27
 
27
 
28
     @Ignore
28
     @Ignore
29
     @Test
29
     @Test
30
+    public void testDetectLongerAnagram() {
31
+        Anagram detector = new Anagram("listen");
32
+        List<String> anagrams = detector.match(Arrays.asList("enlists", "google", "inlets", "banana"));
33
+        assertThat(anagrams, hasItem("inlets"));
34
+    }
35
+
36
+    @Ignore
37
+    @Test
30
     public void testDetectMultipleAnagrams() {
38
     public void testDetectMultipleAnagrams() {
31
         Anagram detector = new Anagram("master");
39
         Anagram detector = new Anagram("master");
32
         List<String> anagrams = detector.match(Arrays.asList("stream", "pigeon", "maters"));
40
         List<String> anagrams = detector.match(Arrays.asList("stream", "pigeon", "maters"));
35
 
43
 
36
     @Ignore
44
     @Ignore
37
     @Test
45
     @Test
46
+    public void testDetectMultipleAnagramsForLongerWord() {
47
+        Anagram detector = new Anagram("allergy");
48
+        List<String> anagrams = detector.match(Arrays.asList("gallery", "ballerina", "regally", "clergy", "largely", "leading"));
49
+        assertThat(anagrams, allOf(hasItem("gallery"), hasItem("largely"), hasItem("regally")));
50
+    }
51
+
52
+    @Ignore
53
+    @Test
38
     public void testDoesNotConfuseDifferentDuplicates() {
54
     public void testDoesNotConfuseDifferentDuplicates() {
39
         Anagram detector = new Anagram("galea");
55
         Anagram detector = new Anagram("galea");
40
-        List<String> anagrams = detector.match(Arrays.asList("eagle"));
41
-        assertTrue(anagrams.isEmpty());
56
+        assertTrue(detector.match(Arrays.asList("eagle")).isEmpty());
42
     }
57
     }
43
 
58
 
44
     @Ignore
59
     @Ignore
52
 
67
 
53
     @Ignore
68
     @Ignore
54
     @Test
69
     @Test
70
+    public void testCapitalWordIsNotAnagram() {
71
+        Anagram detector = new Anagram("BANANA");
72
+        assertTrue(detector.match(Arrays.asList("Banana")).isEmpty());
73
+    }
74
+
75
+    @Ignore
76
+    @Test
77
+    public void testIdenticalWordRepeatedIsNotAnagram() {
78
+        Anagram detector = new Anagram("go");
79
+        assertTrue(detector.match(Arrays.asList("go Go GO")).isEmpty());
80
+    }
81
+
82
+    @Ignore
83
+    @Test
55
     public void testEliminateAnagramsWithSameChecksum() {
84
     public void testEliminateAnagramsWithSameChecksum() {
56
         Anagram detector = new Anagram("mass");
85
         Anagram detector = new Anagram("mass");
57
         assertTrue(detector.match(Arrays.asList("last")).isEmpty());
86
         assertTrue(detector.match(Arrays.asList("last")).isEmpty());
66
 
95
 
67
     @Ignore
96
     @Ignore
68
     @Test
97
     @Test
69
-    public void testDetectAnagrams() {
70
-        Anagram detector = new Anagram("listen");
71
-        List<String> anagrams = detector.match(Arrays.asList("enlists", "google", "inlets", "banana"));
72
-        assertThat(anagrams, hasItem("inlets"));
98
+    public void testCaseInsensitiveWhenSubjectStartsWithUpperCaseLetter() {
99
+        Anagram detector = new Anagram("Orchestra");
100
+        List<String> anagrams = detector.match(Arrays.asList("cashregister", "carthorse", "radishes"));
101
+        assertThat(anagrams, hasItem("carthorse"));
73
     }
102
     }
74
 
103
 
75
     @Ignore
104
     @Ignore
76
     @Test
105
     @Test
77
-    public void testMultipleAnagrams() {
78
-        Anagram detector = new Anagram("allergy");
79
-        List<String> anagrams = detector.match(Arrays.asList("gallery", "ballerina", "regally", "clergy", "largely", "leading"));
80
-        assertThat(anagrams, allOf(hasItem("gallery"), hasItem("largely"), hasItem("regally")));
106
+    public void testCaseInsensitiveWhenAnagramStartsWithUpperCaseLetter() {
107
+        Anagram detector = new Anagram("orchestra");
108
+        List<String> anagrams = detector.match(Arrays.asList("cashregister", "Carthorse", "radishes"));
109
+        assertThat(anagrams, hasItem("Carthorse"));
81
     }
110
     }
82
 
111
 
83
     @Ignore
112
     @Ignore
84
     @Test
113
     @Test
85
-    public void testAnagramsAreCaseInsensitive() {
114
+    public void testCaseInsensitiveWhenBothAnagramAndSubjectStartWithUpperCaseLetter() {
86
         Anagram detector = new Anagram("Orchestra");
115
         Anagram detector = new Anagram("Orchestra");
87
         List<String> anagrams = detector.match(Arrays.asList("cashregister", "Carthorse", "radishes"));
116
         List<String> anagrams = detector.match(Arrays.asList("cashregister", "Carthorse", "radishes"));
88
         assertThat(anagrams, hasItem("Carthorse"));
117
         assertThat(anagrams, hasItem("Carthorse"));
89
     }
118
     }
90
-
91
 }
119
 }