1
- import static org .assertj .core .api .Assertions .assertThat ;
2
-
3
1
import org .junit .jupiter .api .Disabled ;
4
2
import org .junit .jupiter .api .Test ;
5
3
6
4
import java .util .Arrays ;
7
5
import java .util .Collections ;
8
6
7
+ import static org .assertj .core .api .Assertions .assertThat ;
8
+
9
9
public class AnagramTest {
10
10
11
11
@ Test
12
12
public void testNoMatches () {
13
13
Anagram detector = new Anagram ("diaper" );
14
14
15
15
assertThat (
16
- detector .match (
17
- Arrays .asList ("hello" , "world" , "zombies" , "pants" )))
18
- .isEmpty ();
16
+ detector .match (
17
+ Arrays .asList ("hello" , "world" , "zombies" , "pants" )))
18
+ .isEmpty ();
19
19
}
20
20
21
21
@ Disabled ("Remove to run test" )
@@ -24,7 +24,7 @@ public void testDetectsTwoAnagrams() {
24
24
Anagram detector = new Anagram ("solemn" );
25
25
26
26
assertThat (detector .match (Arrays .asList ("lemons" , "cherry" , "melons" )))
27
- .containsExactlyInAnyOrder ("lemons" , "melons" );
27
+ .containsExactlyInAnyOrder ("lemons" , "melons" );
28
28
}
29
29
30
30
@ Disabled ("Remove to run test" )
@@ -41,25 +41,25 @@ public void testDetectLongerAnagram() {
41
41
Anagram detector = new Anagram ("listen" );
42
42
43
43
assertThat (
44
- detector .match (
45
- Arrays .asList ("enlists" , "google" , "inlets" , "banana" )))
46
- .containsExactlyInAnyOrder ("inlets" );
44
+ detector .match (
45
+ Arrays .asList ("enlists" , "google" , "inlets" , "banana" )))
46
+ .containsExactlyInAnyOrder ("inlets" );
47
47
}
48
48
49
49
@ Disabled ("Remove to run test" )
50
50
@ Test
51
51
public void testDetectMultipleAnagramsForLongerWord () {
52
52
Anagram detector = new Anagram ("allergy" );
53
53
assertThat (
54
- detector .match (
55
- Arrays .asList (
56
- "gallery" ,
57
- "ballerina" ,
58
- "regally" ,
59
- "clergy" ,
60
- "largely" ,
61
- "leading" )))
62
- .containsExactlyInAnyOrder ("gallery" , "regally" , "largely" );
54
+ detector .match (
55
+ Arrays .asList (
56
+ "gallery" ,
57
+ "ballerina" ,
58
+ "regally" ,
59
+ "clergy" ,
60
+ "largely" ,
61
+ "leading" )))
62
+ .containsExactlyInAnyOrder ("gallery" , "regally" , "largely" );
63
63
}
64
64
65
65
@ Disabled ("Remove to run test" )
@@ -68,7 +68,7 @@ public void testDetectsMultipleAnagramsWithDifferentCase() {
68
68
Anagram detector = new Anagram ("nose" );
69
69
70
70
assertThat (detector .match (Arrays .asList ("Eons" , "ONES" )))
71
- .containsExactlyInAnyOrder ("Eons" , "ONES" );
71
+ .containsExactlyInAnyOrder ("Eons" , "ONES" );
72
72
}
73
73
74
74
@ Disabled ("Remove to run test" )
@@ -77,7 +77,7 @@ public void testEliminateAnagramsWithSameChecksum() {
77
77
Anagram detector = new Anagram ("mass" );
78
78
79
79
assertThat (detector .match (Collections .singletonList ("last" )))
80
- .isEmpty ();
80
+ .isEmpty ();
81
81
}
82
82
83
83
@ Disabled ("Remove to run test" )
@@ -86,9 +86,9 @@ public void testCaseInsensitiveWhenBothAnagramAndSubjectStartWithUpperCaseLetter
86
86
Anagram detector = new Anagram ("Orchestra" );
87
87
88
88
assertThat (
89
- detector .match (
90
- Arrays .asList ("cashregister" , "Carthorse" , "radishes" )))
91
- .containsExactlyInAnyOrder ("Carthorse" );
89
+ detector .match (
90
+ Arrays .asList ("cashregister" , "Carthorse" , "radishes" )))
91
+ .containsExactlyInAnyOrder ("Carthorse" );
92
92
}
93
93
94
94
@ Disabled ("Remove to run test" )
@@ -97,9 +97,9 @@ public void testCaseInsensitiveWhenSubjectStartsWithUpperCaseLetter() {
97
97
Anagram detector = new Anagram ("Orchestra" );
98
98
99
99
assertThat (
100
- detector .match (
101
- Arrays .asList ("cashregister" , "carthorse" , "radishes" )))
102
- .containsExactlyInAnyOrder ("carthorse" );
100
+ detector .match (
101
+ Arrays .asList ("cashregister" , "carthorse" , "radishes" )))
102
+ .containsExactlyInAnyOrder ("carthorse" );
103
103
}
104
104
105
105
@ Disabled ("Remove to run test" )
@@ -108,9 +108,9 @@ public void testCaseInsensitiveWhenAnagramStartsWithUpperCaseLetter() {
108
108
Anagram detector = new Anagram ("orchestra" );
109
109
110
110
assertThat (
111
- detector .match (
112
- Arrays .asList ("cashregister" , "Carthorse" , "radishes" )))
113
- .containsExactlyInAnyOrder ("Carthorse" );
111
+ detector .match (
112
+ Arrays .asList ("cashregister" , "Carthorse" , "radishes" )))
113
+ .containsExactlyInAnyOrder ("Carthorse" );
114
114
}
115
115
116
116
@ Disabled ("Remove to run test" )
@@ -119,7 +119,7 @@ public void testIdenticalWordRepeatedIsNotAnagram() {
119
119
Anagram detector = new Anagram ("go" );
120
120
121
121
assertThat (detector .match (Collections .singletonList ("goGoGO" )))
122
- .isEmpty ();
122
+ .isEmpty ();
123
123
}
124
124
125
125
@ Disabled ("Remove to run test" )
@@ -128,7 +128,7 @@ public void testAnagramMustUseAllLettersExactlyOnce() {
128
128
Anagram detector = new Anagram ("tapper" );
129
129
130
130
assertThat (detector .match (Collections .singletonList ("patter" )))
131
- .isEmpty ();
131
+ .isEmpty ();
132
132
}
133
133
134
134
@ Disabled ("Remove to run test" )
@@ -137,7 +137,7 @@ public void testWordsAreNotAnagramsOfThemselvesCaseInsensitive() {
137
137
Anagram detector = new Anagram ("BANANA" );
138
138
139
139
assertThat (detector .match (Collections .singletonList ("BANANA" )))
140
- .isEmpty ();
140
+ .isEmpty ();
141
141
}
142
142
143
143
@ Disabled ("Remove to run test" )
@@ -146,7 +146,7 @@ public void testWordsAreNotAnagramsOfThemselvesEvenIfLetterCaseIsPartiallyDiffer
146
146
Anagram detector = new Anagram ("BANANA" );
147
147
148
148
assertThat (detector .match (Collections .singletonList ("Banana" )))
149
- .isEmpty ();
149
+ .isEmpty ();
150
150
}
151
151
152
152
@ Disabled ("Remove to run test" )
@@ -155,7 +155,7 @@ public void testWordsAreNotAnagramsOfThemselvesEvenIfLetterCaseIsCompletelyDiffe
155
155
Anagram detector = new Anagram ("BANANA" );
156
156
157
157
assertThat (detector .match (Collections .singletonList ("banana" )))
158
- .isEmpty ();
158
+ .isEmpty ();
159
159
}
160
160
161
161
@ Disabled ("Remove to run test" )
@@ -164,7 +164,24 @@ public void testWordsOtherThanThemselvesCanBeAnagrams() {
164
164
Anagram detector = new Anagram ("LISTEN" );
165
165
166
166
assertThat (detector .match (Arrays .asList ("LISTEN" , "Silent" )))
167
- .containsExactlyInAnyOrder ("Silent" );
167
+ .containsExactlyInAnyOrder ("Silent" );
168
168
}
169
169
170
+ @ Disabled ("Remove to run test" )
171
+ @ Test
172
+ public void testHandlesCaseOfGreekLetters () {
173
+ Anagram detector = new Anagram ("ΑΒΓ" );
174
+
175
+ assertThat (detector .match (Arrays .asList ("ΒΓΑ" , "ΒΓΔ" , "γβα" , "αβγ" )))
176
+ .containsExactlyInAnyOrder ("ΒΓΑ" , "γβα" );
177
+ }
178
+
179
+ @ Disabled ("Remove to run test" )
180
+ @ Test
181
+ public void testDifferentCharactersWithSameBytes () {
182
+ Anagram detector = new Anagram ("a⬂" );
183
+
184
+ assertThat (detector .match (Collections .singletonList ("€a" )))
185
+ .isEmpty ();
186
+ }
170
187
}
0 commit comments