mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-07 11:08:54 +08:00
algorithm: percentage of letter (#1261)
This commit is contained in:
16
String/test/PercentageOfLetters.test.js
Normal file
16
String/test/PercentageOfLetters.test.js
Normal file
@ -0,0 +1,16 @@
|
||||
import { percentageOfLetter } from '../PercentageOfLetters'
|
||||
|
||||
describe('Percentage of Letters in a String', () => {
|
||||
test('Calculate percent for lower case', () => {
|
||||
expect(percentageOfLetter('foobar', 'o')).toEqual(33)
|
||||
expect(percentageOfLetter('aaabcd', 'a')).toEqual(50)
|
||||
})
|
||||
test('Calculate percent for upper case', () => {
|
||||
expect(percentageOfLetter('foobar', 'o')).toEqual(33)
|
||||
expect(percentageOfLetter('aAabcd', 'a')).toEqual(50)
|
||||
})
|
||||
test('Throwing an exception', () => {
|
||||
expect(() => percentageOfLetter(100, 'string')).toThrow()
|
||||
expect(() => percentageOfLetter('string', true)).toThrow()
|
||||
})
|
||||
})
|
Reference in New Issue
Block a user