mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-06 01:18:23 +08:00
Rename to CaesarCipher (#1144)
This commit is contained in:
@ -6,7 +6,7 @@
|
|||||||
* @param {number} rotation - the number of rotation, expect real number ( > 0)
|
* @param {number} rotation - the number of rotation, expect real number ( > 0)
|
||||||
* @return {string} - decrypted string
|
* @return {string} - decrypted string
|
||||||
*/
|
*/
|
||||||
const caesarsCipher = (str, rotation) => {
|
const caesarCipher = (str, rotation) => {
|
||||||
if (typeof str !== 'string' || !Number.isInteger(rotation) || rotation < 0) {
|
if (typeof str !== 'string' || !Number.isInteger(rotation) || rotation < 0) {
|
||||||
throw new TypeError('Arguments are invalid')
|
throw new TypeError('Arguments are invalid')
|
||||||
}
|
}
|
||||||
@ -29,4 +29,4 @@ const caesarsCipher = (str, rotation) => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export default caesarsCipher
|
export default caesarCipher
|
16
Ciphers/test/CaesarCipher.test.js
Normal file
16
Ciphers/test/CaesarCipher.test.js
Normal 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')
|
||||||
|
})
|
||||||
|
})
|
@ -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')
|
|
||||||
})
|
|
||||||
})
|
|
Reference in New Issue
Block a user