@@ -14,31 +14,17 @@ describe('anagram', function()
14
14
assert .are .same (sorted_clone (expected ), sorted_clone (actual ))
15
15
end
16
16
17
- it (' no result ' , function ()
17
+ it (' no matches ' , function ()
18
18
local detector = Anagram :new (' diaper' )
19
19
local result = detector :match ({ ' hello' , ' world' , ' zombies' , ' pants' })
20
20
local expected = {}
21
21
assert_lists_are_same (expected , result )
22
22
end )
23
23
24
- it (' detects simple anagram' , function ()
25
- local detector = Anagram :new (' ant' )
26
- local result = detector :match ({ ' tan' , ' stand' , ' at' })
27
- local expected = { ' tan' }
28
- assert_lists_are_same (expected , result )
29
- end )
30
-
31
- it (' does not detect false positives' , function ()
32
- local detector = Anagram :new (' galea' )
33
- local result = detector :match ({ ' eagle' })
34
- local expected = {}
35
- assert_lists_are_same (expected , result )
36
- end )
37
-
38
- it (' detects multiple anagrams' , function ()
39
- local detector = Anagram :new (' master' )
40
- local result = detector :match ({ ' stream' , ' pigeon' , ' maters' })
41
- local expected = { ' stream' , ' maters' }
24
+ it (' detects two anagrams' , function ()
25
+ local detector = Anagram :new (' solemn' )
26
+ local result = detector :match ({ ' lemons' , ' cherry' , ' melons' })
27
+ local expected = { ' lemons' , ' melons' }
42
28
assert_lists_are_same (expected , result )
43
29
end )
44
30
@@ -56,17 +42,87 @@ describe('anagram', function()
56
42
assert_lists_are_same (expected , result )
57
43
end )
58
44
59
- it (' detects multiple anagrams' , function ()
45
+ it (' detects three anagrams' , function ()
60
46
local detector = Anagram :new (' allergy' )
61
47
local result = detector :match ({ ' gallery' , ' ballerina' , ' regally' , ' clergy' , ' largely' , ' leading' })
62
48
local expected = { ' gallery' , ' regally' , ' largely' }
63
49
assert_lists_are_same (expected , result )
64
50
end )
65
51
52
+ it (' detects multiple anagrams with different case' , function ()
53
+ local detector = Anagram :new (' nose' )
54
+ local result = detector :match ({ ' Eons' , ' ONES' })
55
+ local expected = { ' Eons' , ' ONES' }
56
+ assert_lists_are_same (expected , result )
57
+ end )
58
+
59
+ it (' does not detect non-anagrams with identical checksum' , function ()
60
+ local detector = Anagram :new (' mass' )
61
+ local result = detector :match ({ ' last' })
62
+ local expected = {}
63
+ assert_lists_are_same (expected , result )
64
+ end )
65
+
66
66
it (' detects anagrams case-insensitively' , function ()
67
67
local detector = Anagram :new (' Orchestra' )
68
68
local result = detector :match ({ ' cashregister' , ' Carthorse' , ' radishes' })
69
69
local expected = { ' Carthorse' }
70
70
assert_lists_are_same (expected , result )
71
71
end )
72
+
73
+ it (' detects anagrams using case-insensitive subject' , function ()
74
+ local detector = Anagram :new (' Orchestra' )
75
+ local result = detector :match ({ ' cashregister' , ' carthorse' , ' radishes' })
76
+ local expected = { ' carthorse' }
77
+ assert_lists_are_same (expected , result )
78
+ end )
79
+
80
+ it (' detects anagrams using case-insensitive possible matches' , function ()
81
+ local detector = Anagram :new (' orchestra' )
82
+ local result = detector :match ({ ' cashregister' , ' Carthorse' , ' radishes' })
83
+ local expected = { ' Carthorse' }
84
+ assert_lists_are_same (expected , result )
85
+ end )
86
+
87
+ it (' does not detect an anagram if the original word is repeated' , function ()
88
+ local detector = Anagram :new (' go' )
89
+ local result = detector :match ({ ' goGoGO' })
90
+ local expected = {}
91
+ assert_lists_are_same (expected , result )
92
+ end )
93
+
94
+ it (' anagrams must use all letters exactly once' , function ()
95
+ local detector = Anagram :new (' tapper' )
96
+ local result = detector :match ({ ' patter' })
97
+ local expected = {}
98
+ assert_lists_are_same (expected , result )
99
+ end )
100
+
101
+ it (' words are not anagrams of themselves' , function ()
102
+ local detector = Anagram :new (' BANANA' )
103
+ local result = detector :match ({ ' BANANA' })
104
+ local expected = {}
105
+ assert_lists_are_same (expected , result )
106
+ end )
107
+
108
+ it (' words are not anagrams of themselves even if letter case is partially different' , function ()
109
+ local detector = Anagram :new (' BANANA' )
110
+ local result = detector :match ({ ' Banana' })
111
+ local expected = {}
112
+ assert_lists_are_same (expected , result )
113
+ end )
114
+
115
+ it (' words are not anagrams of themselves even if letter case is completely different' , function ()
116
+ local detector = Anagram :new (' BANANA' )
117
+ local result = detector :match ({ ' banana' })
118
+ local expected = {}
119
+ assert_lists_are_same (expected , result )
120
+ end )
121
+
122
+ it (' words other than themselves can be anagrams' , function ()
123
+ local detector = Anagram :new (' LISTEN' )
124
+ local result = detector :match ({ ' LISTEN' , ' Silent' })
125
+ local expected = { ' Silent' }
126
+ assert_lists_are_same (expected , result )
127
+ end )
72
128
end )
0 commit comments