Rename to CaesarCipher (#1144)

This commit is contained in:
Omar Ferreiro
2022-10-08 16:17:04 +02:00
committed by GitHub
parent d0e61e1f69
commit 907b86c343
3 changed files with 18 additions and 18 deletions

View File

@ -6,7 +6,7 @@
* @param {number} rotation - the number of rotation, expect real number ( > 0)
* @return {string} - decrypted string
*/
const caesarsCipher = (str, rotation) => {
const caesarCipher = (str, rotation) => {
if (typeof str !== 'string' || !Number.isInteger(rotation) || rotation < 0) {
throw new TypeError('Arguments are invalid')
}
@ -29,4 +29,4 @@ const caesarsCipher = (str, rotation) => {
})
}
export default caesarsCipher
export default caesarCipher

View File

@ -0,0 +1,16 @@
import caesarCipher from '../CaesarCipher'
describe('Testing the caesarsCipher function', () => {
it('Test - 1, Testing for invalid types', () => {
expect(() => caesarCipher(false, 3)).toThrow()
expect(() => caesarCipher('false', -1)).toThrow()
expect(() => caesarCipher('true', null)).toThrow()
})
it('Test - 2, Testing for valid string and rotation', () => {
expect(caesarCipher('middle-Outz', 2)).toBe('okffng-Qwvb')
expect(caesarCipher('abcdefghijklmnopqrstuvwxyz', 3)).toBe('defghijklmnopqrstuvwxyzabc')
expect(caesarCipher('Always-Look-on-the-Bright-Side-of-Life', 5)).toBe('Fqbfdx-Qttp-ts-ymj-Gwnlmy-Xnij-tk-Qnkj')
expect(caesarCipher('THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG', 23)).toBe('QEB NRFZH YOLTK CLU GRJMP LSBO QEB IXWV ALD')
})
})

View File

@ -1,16 +0,0 @@
import caesarsCipher from '../CaesarsCipher'
describe('Testing the caesarsCipher function', () => {
it('Test - 1, Testing for invalid types', () => {
expect(() => caesarsCipher(false, 3)).toThrow()
expect(() => caesarsCipher('false', -1)).toThrow()
expect(() => caesarsCipher('true', null)).toThrow()
})
it('Test - 2, Testing for valid string and rotation', () => {
expect(caesarsCipher('middle-Outz', 2)).toBe('okffng-Qwvb')
expect(caesarsCipher('abcdefghijklmnopqrstuvwxyz', 3)).toBe('defghijklmnopqrstuvwxyzabc')
expect(caesarsCipher('Always-Look-on-the-Bright-Side-of-Life', 5)).toBe('Fqbfdx-Qttp-ts-ymj-Gwnlmy-Xnij-tk-Qnkj')
expect(caesarsCipher('THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG', 23)).toBe('QEB NRFZH YOLTK CLU GRJMP LSBO QEB IXWV ALD')
})
})