diff --git a/Ciphers/CaesarsCipher.js b/Ciphers/CaesarCipher.js similarity index 95% rename from Ciphers/CaesarsCipher.js rename to Ciphers/CaesarCipher.js index 2eed471a5..8a942564e 100644 --- a/Ciphers/CaesarsCipher.js +++ b/Ciphers/CaesarCipher.js @@ -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 diff --git a/Ciphers/test/CaesarCipher.test.js b/Ciphers/test/CaesarCipher.test.js new file mode 100644 index 000000000..b3d9eff9d --- /dev/null +++ b/Ciphers/test/CaesarCipher.test.js @@ -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') + }) +}) diff --git a/Ciphers/test/CaesarsCipher.test.js b/Ciphers/test/CaesarsCipher.test.js deleted file mode 100644 index d78fe5cfc..000000000 --- a/Ciphers/test/CaesarsCipher.test.js +++ /dev/null @@ -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') - }) -})