|
1 | 1 | import { checkWordOccurrence } from '../CheckWordOccurrence'
|
2 |
| -describe('checkWordOccurrence', () => { |
| 2 | + |
| 3 | +describe('Testing checkWordOccurrence', () => { |
3 | 4 | it('expects throw on insert wrong string', () => {
|
4 | 5 | const value = 123
|
| 6 | + |
5 | 7 | expect(() => checkWordOccurrence(value)).toThrow()
|
6 | 8 | })
|
| 9 | + |
7 | 10 | it('expect throw on insert wrong param for case sensitive', () => {
|
8 | 11 | const value = 'hello'
|
| 12 | + |
9 | 13 | expect(() => checkWordOccurrence(value, value)).toThrow()
|
10 | 14 | })
|
| 15 | + |
11 | 16 | it('check occurrence with case sensitive', () => {
|
12 |
| - const stringToTest = 'A Mad World' |
13 |
| - const charsOccurrences = checkWordOccurrence(stringToTest, true) |
14 |
| - const expectResult = { A: 1, M: 1, a: 1, d: 2, W: 1, l: 1, o: 1, r: 1 } |
15 |
| - const occurrencesObjectKeys = Object.keys(charsOccurrences) |
16 |
| - const expectObjectKeys = Object.keys(expectResult) |
17 |
| - expect(occurrencesObjectKeys.length).toBe(expectObjectKeys.length) |
18 |
| - expectObjectKeys.forEach(key => { |
19 |
| - expect(expectResult[key]).toBe(charsOccurrences[key]) |
20 |
| - }) |
| 17 | + const stringToTest = 'The quick brown fox jumps over the lazy dog' |
| 18 | + const expectResult = { The: 1, quick: 1, brown: 1, fox: 1, jumps: 1, over: 1, the: 1, lazy: 1, dog: 1 } |
| 19 | + |
| 20 | + expect(checkWordOccurrence(stringToTest)).toEqual(expectResult) |
21 | 21 | })
|
| 22 | + |
22 | 23 | it('check occurrence with case insensitive', () => {
|
23 |
| - const stringToTest = 'A Mad World' |
24 |
| - const charsOccurrences = checkWordOccurrence(stringToTest, false) |
25 |
| - const expectResult = { A: 2, D: 2, L: 1, M: 1, O: 1, R: 1, W: 1 } |
26 |
| - const occurrencesObjectKeys = Object.keys(charsOccurrences) |
27 |
| - const expectObjectKeys = Object.keys(expectResult) |
28 |
| - expect(occurrencesObjectKeys.length).toBe(expectObjectKeys.length) |
29 |
| - expectObjectKeys.forEach(key => { |
30 |
| - expect(expectResult[key]).toBe(charsOccurrences[key]) |
31 |
| - }) |
| 24 | + const stringToTest = 'The quick brown fox jumps over the lazy dog' |
| 25 | + const expectResult = { the: 2, quick: 1, brown: 1, fox: 1, jumps: 1, over: 1, lazy: 1, dog: 1 } |
| 26 | + |
| 27 | + expect(checkWordOccurrence(stringToTest, true)).toEqual(expectResult) |
32 | 28 | })
|
33 | 29 | })
|
0 commit comments