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