Test migration to jest by hand
Apparently using regular expressions is way easier.
This commit is contained in:
11
test/isAnagram/isAnagram.js
Normal file
11
test/isAnagram/isAnagram.js
Normal file
@ -0,0 +1,11 @@
|
||||
const isAnagram = (str1, str2) => {
|
||||
const normalize = str =>
|
||||
str
|
||||
.toLowerCase()
|
||||
.replace(/[^a-z0-9]/gi, '')
|
||||
.split('')
|
||||
.sort()
|
||||
.join('');
|
||||
return normalize(str1) === normalize(str2);
|
||||
};
|
||||
module.exports = isAnagram;
|
||||
21
test/isAnagram/isAnagram.test.js
Normal file
21
test/isAnagram/isAnagram.test.js
Normal file
@ -0,0 +1,21 @@
|
||||
const expect = require('expect');
|
||||
const isAnagram = require('./isAnagram.js');
|
||||
|
||||
|
||||
test('isAnagram is a Function', () => {
|
||||
expect(isAnagram).toBeInstanceOf(Function);
|
||||
});
|
||||
test('Checks valid anagram', () => {
|
||||
expect(isAnagram('iceman', 'cinema')).toBeTruthy();
|
||||
});
|
||||
test('Works with spaces', () => {
|
||||
expect(isAnagram('rail safety', 'fairy tales')).toBeTruthy();
|
||||
});
|
||||
test('Ignores case', () => {
|
||||
expect(isAnagram('roast beef', 'eat for BSE')).toBeTruthy();
|
||||
});
|
||||
test('Ignores special characters', () => {
|
||||
expect(isAnagram('Regera Dowdy', 'E. G. Deadworry')).toBeTruthy();
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user