-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathlongest_word.test.js
44 lines (37 loc) · 1.45 KB
/
longest_word.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
const longestWord = require('./longest_word');
describe('longestWord()', () => {
test('returns longest word at start of sentence', () => {
expect(longestWord('thethethe quick brown fox jumped')).toBe(
'thethethe'
);
});
test('returns longest word at end of sentence', () => {
expect(longestWord('the quick brown fox jumpedjumped')).toBe(
'jumpedjumped'
);
});
test('returns longest word in middle of sentence', () => {
expect(longestWord('the quick brownbrownbrown fox jumped')).toBe(
'brownbrownbrown'
);
});
test('returns first longest word if there are multiple of equal length', () => {
expect(longestWord('the quick brown fox jump')).toBe('quick');
});
test('works with capital letters', () => {
expect(longestWord('THE QUICK BROWNBROWNBROWN FOX JUMPED')).toBe(
'BROWNBROWNBROWN'
);
});
test('works with mixed case letters', () => {
expect(longestWord('the quick Brown fox jump')).toBe('quick');
expect(longestWord('the Quick Brown fox jump')).toBe('Quick');
expect(longestWord('the Quick brown fox jump')).toBe('Quick');
expect(longestWord('THE QUICK BRown fox jump')).toBe('QUICK');
});
test('ignores non alphanumeric characters', () => {
expect(
longestWord('the$%!#$.quick*brown fox jump*!#$!@$!$!!%!00an')
).toBe('quick');
});
});