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