SIGN IN SIGN UP

Algorithms and Data Structures implemented in JavaScript for beginners, following best practices.

0 0 57 JavaScript
import { checkWordOccurrence } from '../CheckWordOccurrence'
2020-10-05 17:03:56 -03:00
describe('checkWordOccurrence', () => {
2020-10-05 23:52:21 -03:00
it('expects throw on insert wrong string', () => {
2020-10-06 00:08:52 -03:00
const value = 123
expect(() => checkWordOccurrence(value)).toThrow()
})
2020-10-05 23:52:21 -03:00
it('expect throw on insert wrong param for case sensitive', () => {
2020-10-06 00:08:52 -03:00
const value = 'hello'
expect(() => checkWordOccurrence(value, value)).toThrow()
})
2020-10-05 23:52:21 -03:00
it('check occurrence with case sensitive', () => {
2020-10-06 00:08:52 -03:00
const stringToTest = 'A Mad World'
const charsOccurrences = checkWordOccurrence(stringToTest, true)
const expectResult = { A: 1, M: 1, a: 1, d: 2, W: 1, l: 1, o: 1, r: 1 }
const occurrencesObjectKeys = Object.keys(charsOccurrences)
const expectObjectKeys = Object.keys(expectResult)
expect(occurrencesObjectKeys.length).toBe(expectObjectKeys.length)
2020-10-05 23:52:21 -03:00
expectObjectKeys.forEach(key => {
2020-10-06 00:08:52 -03:00
expect(expectResult[key]).toBe(charsOccurrences[key])
})
})
2020-10-05 23:52:21 -03:00
it('check occurrence with case insensitive', () => {
2020-10-06 00:08:52 -03:00
const stringToTest = 'A Mad World'
const charsOccurrences = checkWordOccurrence(stringToTest, false)
const expectResult = { A: 2, D: 2, L: 1, M: 1, O: 1, R: 1, W: 1 }
const occurrencesObjectKeys = Object.keys(charsOccurrences)
const expectObjectKeys = Object.keys(expectResult)
expect(occurrencesObjectKeys.length).toBe(expectObjectKeys.length)
2020-10-05 23:52:21 -03:00
expectObjectKeys.forEach(key => {
2020-10-06 00:08:52 -03:00
expect(expectResult[key]).toBe(charsOccurrences[key])
})
})
})