1
1
<?php
2
2
3
- /*
4
- * By adding type hints and enabling strict type checking, code can become
5
- * easier to read, self-documenting and reduce the number of potential bugs.
6
- * By default, type declarations are non-strict, which means they will attempt
7
- * to change the original type to match the type specified by the
8
- * type-declaration.
9
- *
10
- * In other words, if you pass a string to a function requiring a float,
11
- * it will attempt to convert the string value to a float.
12
- *
13
- * To enable strict mode, a single declare directive must be placed at the top
14
- * of the file.
15
- * This means that the strictness of typing is configured on a per-file basis.
16
- * This directive not only affects the type declarations of parameters, but also
17
- * a function's return type.
18
- *
19
- * For more info review the Concept on strict type checking in the PHP track
20
- * <link>.
21
- *
22
- * To disable strict typing, comment out the directive below.
23
- */
24
-
25
3
declare (strict_types=1 );
26
4
27
5
class AnagramTest extends PHPUnit \Framework \TestCase
@@ -31,108 +9,162 @@ public static function setUpBeforeClass(): void
31
9
require_once 'Anagram.php ' ;
32
10
}
33
11
12
+ /**
13
+ * uuid dd40c4d2-3c8b-44e5-992a-f42b393ec373
14
+ * @testdox No matches
15
+ */
34
16
public function testNoMatches (): void
35
17
{
36
18
$ this ->assertEquals ([], detectAnagrams ('diaper ' , ['hello ' , 'world ' , 'zombies ' , 'pants ' ]));
37
19
}
38
20
39
- public function testDetectsSimpleAnagram (): void
21
+ /**
22
+ * uuid 03eb9bbe-8906-4ea0-84fa-ffe711b52c8b
23
+ * @testdox Detects two anagrams
24
+ */
25
+ public function testDetectsTwoAnagrams (): void
40
26
{
41
- $ this ->assertEquals (['tan ' ], detectAnagrams ('ant ' , ['tan ' , 'stand ' , 'at ' ]));
42
- }
43
-
44
- public function testDoesNotDetectFalsePositives (): void
45
- {
46
- $ this ->assertEquals ([], detectAnagrams ('galea ' , ['eagle ' ]));
47
- }
48
-
49
- public function testDetectsMultipleAnagrams (): void
50
- {
51
- $ this ->assertEquals (['stream ' , 'maters ' ], detectAnagrams ('master ' , ['stream ' , 'pigeon ' , 'maters ' ]));
27
+ $ this ->assertEquals (
28
+ ['lemons ' , 'melons ' ],
29
+ detectAnagrams ('solemn ' , ['lemons ' , 'cherry ' , 'melons ' ])
30
+ );
52
31
}
53
32
33
+ /**
34
+ * uuid a27558ee-9ba0-4552-96b1-ecf665b06556
35
+ * @testdox Does not detect anagram subsets
36
+ */
54
37
public function testDoesNotDetectAnagramSubsets (): void
55
38
{
56
39
$ this ->assertEquals ([], detectAnagrams ('good ' , ['dog ' , 'goody ' ]));
57
40
}
58
41
42
+ /**
43
+ * uuid 64cd4584-fc15-4781-b633-3d814c4941a4
44
+ * @testdox Detects anagram
45
+ */
59
46
public function testDetectsAnagram (): void
60
47
{
61
48
$ this ->assertEquals (['inlets ' ], detectAnagrams ('listen ' , ['enlists ' , 'google ' , 'inlets ' , 'banana ' ]));
62
49
}
63
50
64
- public function testDetectsMultipleAnagrams2 (): void
51
+ /**
52
+ * uuid 99c91beb-838f-4ccd-b123-935139917283
53
+ * @testdox Detects three anagrams
54
+ */
55
+ public function testDetectsThreeAnagrams (): void
65
56
{
66
57
$ this ->assertEquals (
67
58
['gallery ' , 'regally ' , 'largely ' ],
68
59
detectAnagrams ('allergy ' , ['gallery ' , 'ballerina ' , 'regally ' , 'clergy ' , 'largely ' , 'leading ' ])
69
60
);
70
61
}
71
62
72
- public function testDoesNotDetectIdenticalWords (): void
63
+ /**
64
+ * uuid 78487770-e258-4e1f-a646-8ece10950d90
65
+ * @testdox Detects multiple anagrams with different case
66
+ */
67
+ public function testDetectsMultipleAnagramsWithDifferentCase (): void
73
68
{
74
- $ this ->assertEquals (['cron ' ], detectAnagrams ('corn ' , ['corn ' , 'dark ' , ' Corn ' , ' rank ' , ' CORN ' , ' cron ' , ' park ' ]));
69
+ $ this ->assertEquals (['Eons ' , ' ONES ' ], detectAnagrams ('nose ' , ['Eons ' , 'ONES ' ]));
75
70
}
76
71
72
+ /**
73
+ * uuid 1d0ab8aa-362f-49b7-9902-3d0c668d557b
74
+ * @testdox Does not detect non-anagrams with identical checksum
75
+ */
77
76
public function testDoesNotDetectNonAnagramsWithIdenticalChecksum (): void
78
77
{
79
78
$ this ->assertEquals ([], detectAnagrams ('mass ' , ['last ' ]));
80
79
}
81
80
81
+ /**
82
+ * uuid 9e632c0b-c0b1-4804-8cc1-e295dea6d8a8
83
+ * @testdox Detects anagrams case-insensitively
84
+ */
82
85
public function testDetectsAnagramsCaseInsensitively (): void
83
86
{
84
87
$ this ->assertEquals (['Carthorse ' ], detectAnagrams ('Orchestra ' , ['cashregister ' , 'Carthorse ' , 'radishes ' ]));
85
88
}
86
89
90
+ /**
91
+ * uuid b248e49f-0905-48d2-9c8d-bd02d8c3e392
92
+ * @testdox Detects anagrams using case-insensitive subject
93
+ */
87
94
public function testDetectsAnagramsUsingCaseInsensitiveSubject (): void
88
95
{
89
96
$ this ->assertEquals (['carthorse ' ], detectAnagrams ('Orchestra ' , ['cashregister ' , 'carthorse ' , 'radishes ' ]));
90
97
}
91
98
99
+ /**
100
+ * uuid 5c3d6a8d-7e0b-4b9e-9e1e-6c7d7f8b9c0c
101
+ * @testdox Detects anagrams using case-insensitive possible matches
102
+ */
92
103
public function testDetectsAnagramsUsingCaseInsensitvePossibleMatches (): void
93
104
{
94
105
$ this ->assertEquals (['Carthorse ' ], detectAnagrams ('orchestra ' , ['cashregister ' , 'Carthorse ' , 'radishes ' ]));
95
106
}
96
107
97
- public function testDoesNotDetectAWordAsItsOwnAnagram (): void
98
- {
99
- $ this ->assertEquals ([], detectAnagrams ('banana ' , ['Banana ' ]));
100
- }
101
-
108
+ /**
109
+ * uuid 630abb71-a94e-4715-8395-179ec1df9f91
110
+ * @testdox Does not detect an anagram if the original word is repeated
111
+ */
102
112
public function testDoesNotDetectAAnagramIfTheOriginalWordIsRepeated (): void
103
113
{
104
- $ this ->assertEquals ([], detectAnagrams ('go ' , ['go Go GO ' ]));
114
+ $ this ->assertEquals ([], detectAnagrams ('go ' , ['goGoGO ' ]));
105
115
}
106
116
117
+ /**
118
+ * uuid 9878a1c9-d6ea-4235-ae51-3ea2befd6842
119
+ * @testdox Anagrams must use all letters exactly once
120
+ */
107
121
public function testAnagramsMustUseAllLettersExactlyOnce (): void
108
122
{
109
123
$ this ->assertEquals ([], detectAnagrams ('tapper ' , ['patter ' ]));
110
124
}
111
125
112
- public function testEliminatesAnagramsWithTheSameChecksum (): void
126
+ /**
127
+ * uuid 68934ed0-010b-4ef9-857a-20c9012d1ebf
128
+ * @testdox Words are not anagrams of themselves
129
+ */
130
+ public function testWordsAreNotAnagramsOfThemselves (): void
113
131
{
114
- $ this ->assertEquals ([], detectAnagrams ('mass ' , ['last ' ]));
132
+ $ this ->assertEquals ([], detectAnagrams ('BANANA ' , ['BANANA ' ]));
115
133
}
116
134
117
- public function testDetectsUnicodeAnagrams (): void
135
+ /**
136
+ * uuid 589384f3-4c8a-4e7d-9edc-51c3e5f0c90e
137
+ * @testdox Words are not anagrams of themselves even if letter case is partially different
138
+ */
139
+ public function testWordsAreNotAnagramsOfThemselvesEvenIfLetterCaseIsPartiallyDifferent (): void
118
140
{
119
- $ this ->markTestSkipped ('This requires `mbstring` to be installed and thus is optional. ' );
120
- $ this ->assertEquals (['ΒΓΑ ' , 'γβα ' ], detectAnagrams ('ΑΒΓ ' , ['ΒΓΑ ' , 'ΒΓΔ ' , 'γβα ' ]));
141
+ $ this ->assertEquals ([], detectAnagrams ('BANANA ' , ['Banana ' ]));
121
142
}
122
143
123
- public function testEliminatesMisleadingUnicodeAnagrams (): void
144
+ /**
145
+ * uuid ba53e423-7e02-41ee-9ae2-71f91e6d18e6
146
+ * @testdox Words are not anagrams of themselves even if letter case is completely different
147
+ */
148
+ public function testWordsAreNotAnagramsOfThemselvesEvenIfLetterCaseIsCompletelyDifferent (): void
124
149
{
125
- $ this ->markTestSkipped ('This requires `mbstring` to be installed and thus is optional. ' );
126
- $ this ->assertEquals ([], detectAnagrams ('ΑΒΓ ' , ['ABΓ ' ]));
150
+ $ this ->assertEquals ([], detectAnagrams ('BANANA ' , ['banana ' ]));
127
151
}
128
152
129
- public function testCapitalWordIsNotOwnAnagram (): void
153
+ /**
154
+ * uuid 33d3f67e-fbb9-49d3-a90e-0beb00861da7
155
+ * @testdox Words other than themselves can be anagrams
156
+ */
157
+ public function testWordsOtherThanThemselvesCanBeAnagrams (): void
130
158
{
131
- $ this ->assertEquals ([], detectAnagrams ('BANANA ' , ['Banana ' ]));
159
+ $ this ->assertEquals ([' Silent ' ], detectAnagrams ('LISTEN ' , ['LISTEN ' , ' Silent ' ]));
132
160
}
133
161
134
- public function testAnagramsMustUseAllLettersExactlyOnce2 (): void
162
+ /**
163
+ * uuid a6854f66-eec1-4afd-a137-62ef2870c051
164
+ * @testdox Handles case of greek letters
165
+ */
166
+ public function testHandlesCaseOfGreekLetters (): void
135
167
{
136
- $ this ->assertEquals ([], detectAnagrams ( ' patter ' , [ ' tapper ' ]) );
168
+ $ this ->markTestSkipped ( ' This requires `mbstring` to be installed and thus is optional. ' );
137
169
}
138
170
}
0 commit comments