1
- import { checkAnagram } from '../CheckAnagram'
1
+ import { checkAnagramMap , checkAnagramRegex } from '../CheckAnagram'
2
2
3
- describe ( 'checkAnagram ' , ( ) => {
3
+ describe ( 'Testing checkAnagramRegex ' , ( ) => {
4
4
it . each `
5
5
inputOne | inputTwo
6
6
${ 123456 } | ${ 'abcd' }
@@ -10,79 +10,172 @@ describe('checkAnagram', () => {
10
10
${ 'abcd' } | ${ [ 1 , 2 , 3 , 4 , 5 , 6 ] }
11
11
${ 'abcd' } | ${ { test : 'test' } }
12
12
` (
13
- 'expects to return "Not string(s)" given values $inputOne and $inputTwo' ,
13
+ 'expects to throw the type Error given values $inputOne and $inputTwo' ,
14
14
( { inputOne, inputTwo } ) => {
15
- const SUT = checkAnagram ( inputOne , inputTwo )
16
- expect ( SUT ) . toBe ( 'Not string(s)' )
15
+ expect (
16
+ ( ) => checkAnagramRegex ( inputOne , inputTwo )
17
+ ) . toThrowError ( )
17
18
}
18
19
)
19
20
20
21
it ( 'expects to return false if the arguments have different lengths' , ( ) => {
21
- const SUT = checkAnagram ( 'abs' , 'abds' )
22
+ const SUT = checkAnagramRegex ( 'abs' , 'abds' )
22
23
expect ( SUT ) . toBe ( false )
23
24
} )
24
25
25
26
it ( 'expects to return false if the arguments are not anagrams' , ( ) => {
26
- const SUT = checkAnagram ( 'abcs' , 'abds' )
27
+ const SUT = checkAnagramRegex ( 'abcs' , 'abds' )
27
28
expect ( SUT ) . toBe ( false )
28
29
} )
29
30
30
31
it ( 'expects to return true if the arguments are anagrams' , ( ) => {
31
- const SUT = checkAnagram ( 'abcd' , 'bcad' )
32
+ const SUT = checkAnagramRegex ( 'abcd' , 'bcad' )
32
33
expect ( SUT ) . toBe ( true )
33
34
} )
34
35
35
36
it ( 'expects to return true if the arguments of length 1 and are the same letter' , ( ) => {
36
- const SUT = checkAnagram ( 'a' , 'a' )
37
+ const SUT = checkAnagramRegex ( 'a' , 'a' )
37
38
expect ( SUT ) . toBe ( true )
38
39
} )
39
40
40
41
it ( 'expects to return true if the arguments of are both empty strings' , ( ) => {
41
- const SUT = checkAnagram ( '' , '' )
42
+ const SUT = checkAnagramRegex ( '' , '' )
42
43
expect ( SUT ) . toBe ( true )
43
44
} )
44
45
45
46
it ( 'expects to return true if the arguments are anagrams with an odd length' , ( ) => {
46
- const SUT = checkAnagram ( 'abcde' , 'edcab' )
47
+ const SUT = checkAnagramRegex ( 'abcde' , 'edcab' )
47
48
expect ( SUT ) . toBe ( true )
48
49
} )
49
50
50
51
it ( 'expects to return true if the arguments are anagrams with an even length' , ( ) => {
51
- const SUT = checkAnagram ( 'abcdef' , 'fedcab' )
52
+ const SUT = checkAnagramRegex ( 'abcdef' , 'fedcab' )
52
53
expect ( SUT ) . toBe ( true )
53
54
} )
54
55
55
56
it ( 'expects to return false if either argument is an empty string while the other is not' , ( ) => {
56
- const SUT = checkAnagram ( '' , 'edcab' )
57
+ const SUT = checkAnagramRegex ( '' , 'edcab' )
57
58
expect ( SUT ) . toBe ( false )
58
- const SUT2 = checkAnagram ( 'edcab' , '' )
59
+ const SUT2 = checkAnagramRegex ( 'edcab' , '' )
59
60
expect ( SUT2 ) . toBe ( false )
60
61
} )
61
62
62
- it ( 'expects to return false if the arguments contain the same letters but have unequal case' , ( ) => {
63
- const SUT = checkAnagram ( 'ABDCE' , 'abcde' )
63
+ it ( 'expects to return true if the arguments contain the same letters but have unequal case' , ( ) => {
64
+ const SUT = checkAnagramRegex ( 'ABDCE' , 'abcde' )
65
+ expect ( SUT ) . toBe ( true )
66
+ const SUT2 = checkAnagramRegex ( 'AbCdE' , 'aBCdE' )
67
+ expect ( SUT2 ) . toBe ( true )
68
+ const SUT3 = checkAnagramRegex ( 'Eleven plus two' , 'Twelve plus one' )
69
+ expect ( SUT3 ) . toBe ( true )
70
+ } )
71
+
72
+ it ( 'expects to return true if the arguments are anagrams and contain number characters' , ( ) => {
73
+ const SUT = checkAnagramRegex ( 'a1b2' , '12ba' )
74
+ expect ( SUT ) . toBe ( true )
75
+ } )
76
+
77
+ it ( 'expects to return true if the arguments are anagrams and contain space characters' , ( ) => {
78
+ const SUT = checkAnagramRegex ( 'a1 b2' , '1 2ba' )
79
+ expect ( SUT ) . toBe ( true )
80
+ } )
81
+
82
+ it ( 'expects to return true if the arguments are anagrams and contain punctuation characters' , ( ) => {
83
+ const SUT = checkAnagramRegex ( 'a!1b@2' , '1@2ba!' )
84
+ expect ( SUT ) . toBe ( true )
85
+ } )
86
+
87
+ it ( 'expects to return false if the arguments contain the same letters but contain a different amount of space characters' , ( ) => {
88
+ const SUT = checkAnagramRegex ( 'ea cb' , 'e cba' )
64
89
expect ( SUT ) . toBe ( false )
65
- const SUT2 = checkAnagram ( 'AbCdE' , 'aBCdE' )
90
+ } )
91
+ } )
92
+
93
+ describe ( 'Testing checkAnagramMap' , ( ) => {
94
+ it . each `
95
+ inputOne | inputTwo
96
+ ${ 123456 } | ${ 'abcd' }
97
+ ${ [ 1 , 2 , 3 , 4 , 5 , 6 ] } | ${ 'abcd' }
98
+ ${ { test : 'test' } } | ${ 'abcd' }
99
+ ${ 'abcd' } | ${ 123456 }
100
+ ${ 'abcd' } | ${ [ 1 , 2 , 3 , 4 , 5 , 6 ] }
101
+ ${ 'abcd' } | ${ { test : 'test' } }
102
+ ` (
103
+ 'expects to throw the type Error given values $inputOne and $inputTwo' ,
104
+ ( { inputOne, inputTwo } ) => {
105
+ expect (
106
+ ( ) => checkAnagramMap ( inputOne , inputTwo )
107
+ ) . toThrowError ( )
108
+ }
109
+ )
110
+
111
+ it ( 'expects to return false if the arguments have different lengths' , ( ) => {
112
+ const SUT = checkAnagramMap ( 'abs' , 'abds' )
113
+ expect ( SUT ) . toBe ( false )
114
+ } )
115
+
116
+ it ( 'expects to return false if the arguments are not anagrams' , ( ) => {
117
+ const SUT = checkAnagramMap ( 'abcs' , 'abds' )
118
+ expect ( SUT ) . toBe ( false )
119
+ } )
120
+
121
+ it ( 'expects to return true if the arguments are anagrams' , ( ) => {
122
+ const SUT = checkAnagramMap ( 'abcd' , 'bcad' )
123
+ expect ( SUT ) . toBe ( true )
124
+ } )
125
+
126
+ it ( 'expects to return true if the arguments of length 1 and are the same letter' , ( ) => {
127
+ const SUT = checkAnagramMap ( 'a' , 'a' )
128
+ expect ( SUT ) . toBe ( true )
129
+ } )
130
+
131
+ it ( 'expects to return true if the arguments of are both empty strings' , ( ) => {
132
+ const SUT = checkAnagramMap ( '' , '' )
133
+ expect ( SUT ) . toBe ( true )
134
+ } )
135
+
136
+ it ( 'expects to return true if the arguments are anagrams with an odd length' , ( ) => {
137
+ const SUT = checkAnagramMap ( 'abcde' , 'edcab' )
138
+ expect ( SUT ) . toBe ( true )
139
+ } )
140
+
141
+ it ( 'expects to return true if the arguments are anagrams with an even length' , ( ) => {
142
+ const SUT = checkAnagramMap ( 'abcdef' , 'fedcab' )
143
+ expect ( SUT ) . toBe ( true )
144
+ } )
145
+
146
+ it ( 'expects to return false if either argument is an empty string while the other is not' , ( ) => {
147
+ const SUT = checkAnagramMap ( '' , 'edcab' )
148
+ expect ( SUT ) . toBe ( false )
149
+ const SUT2 = checkAnagramMap ( 'edcab' , '' )
66
150
expect ( SUT2 ) . toBe ( false )
67
151
} )
68
152
153
+ it ( 'expects to return true if the arguments contain the same letters but have unequal case' , ( ) => {
154
+ const SUT = checkAnagramMap ( 'ABDCE' , 'abcde' )
155
+ expect ( SUT ) . toBe ( true )
156
+ const SUT2 = checkAnagramMap ( 'AbCdE' , 'aBCdE' )
157
+ expect ( SUT2 ) . toBe ( true )
158
+ const SUT3 = checkAnagramMap ( 'Eleven plus two' , 'Twelve plus one' )
159
+ expect ( SUT3 ) . toBe ( true )
160
+ } )
161
+
69
162
it ( 'expects to return true if the arguments are anagrams and contain number characters' , ( ) => {
70
- const SUT = checkAnagram ( 'a1b2' , '12ba' )
163
+ const SUT = checkAnagramMap ( 'a1b2' , '12ba' )
71
164
expect ( SUT ) . toBe ( true )
72
165
} )
73
166
74
167
it ( 'expects to return true if the arguments are anagrams and contain space characters' , ( ) => {
75
- const SUT = checkAnagram ( 'a1 b2' , '1 2ba' )
168
+ const SUT = checkAnagramMap ( 'a1 b2' , '1 2ba' )
76
169
expect ( SUT ) . toBe ( true )
77
170
} )
78
171
79
172
it ( 'expects to return true if the arguments are anagrams and contain punctuation characters' , ( ) => {
80
- const SUT = checkAnagram ( 'a!1b@2' , '1@2ba!' )
173
+ const SUT = checkAnagramMap ( 'a!1b@2' , '1@2ba!' )
81
174
expect ( SUT ) . toBe ( true )
82
175
} )
83
176
84
177
it ( 'expects to return false if the arguments contain the same letters but contain a different amount of space characters' , ( ) => {
85
- const SUT = checkAnagram ( 'ea cb' , 'e cba' )
178
+ const SUT = checkAnagramMap ( 'ea cb' , 'e cba' )
86
179
expect ( SUT ) . toBe ( false )
87
180
} )
88
181
} )
0 commit comments