|
1 | | -import caesarCipher from '../CaesarCipher' |
2 | | - |
3 | | -describe('Testing the caesarsCipher function', () => { |
4 | | - it('Test - 1, Testing for invalid types', () => { |
5 | | - expect(() => caesarCipher(false, 3)).toThrow() |
6 | | - expect(() => caesarCipher('false', -1)).toThrow() |
7 | | - expect(() => caesarCipher('true', null)).toThrow() |
8 | | - }) |
9 | | - |
10 | | - it('Test - 2, Testing for valid string and rotation', () => { |
11 | | - expect(caesarCipher('middle-Outz', 2)).toBe('okffng-Qwvb') |
12 | | - expect(caesarCipher('abcdefghijklmnopqrstuvwxyz', 3)).toBe( |
13 | | - 'defghijklmnopqrstuvwxyzabc' |
14 | | - ) |
15 | | - expect(caesarCipher('Always-Look-on-the-Bright-Side-of-Life', 5)).toBe( |
16 | | - 'Fqbfdx-Qttp-ts-ymj-Gwnlmy-Xnij-tk-Qnkj' |
17 | | - ) |
18 | | - expect( |
19 | | - caesarCipher('THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG', 23) |
20 | | - ).toBe('QEB NRFZH YOLTK CLU GRJMP LSBO QEB IXWV ALD') |
| 1 | +import { caesarCipher } from '../CaesarCipher.js' |
| 2 | + |
| 3 | +describe('caesarCipher', () => { |
| 4 | + test('shifts letters by 1', () => { |
| 5 | + expect(caesarCipher('ABC', 1)).toBe('BCD') |
| 6 | + }) |
| 7 | + |
| 8 | + test('wraps around Z to A', () => { |
| 9 | + expect(caesarCipher('XYZ', 3)).toBe('ABC') |
| 10 | + }) |
| 11 | + |
| 12 | + test('preserves case', () => { |
| 13 | + expect(caesarCipher('Hello', 13)).toBe('Uryyb') |
| 14 | + }) |
| 15 | + |
| 16 | + test('preserves spaces and punctuation', () => { |
| 17 | + expect(caesarCipher('Hello World!', 13)).toBe('Uryyb Jbeyq!') |
| 18 | + }) |
| 19 | + |
| 20 | + test('shift of 0 returns same string', () => { |
| 21 | + expect(caesarCipher('ABC', 0)).toBe('ABC') |
| 22 | + }) |
| 23 | + |
| 24 | + test('shift of 26 returns same string', () => { |
| 25 | + expect(caesarCipher('ABC', 26)).toBe('ABC') |
| 26 | + }) |
| 27 | + |
| 28 | + test('negative shift works', () => { |
| 29 | + expect(caesarCipher('BCD', -1)).toBe('ABC') |
| 30 | + }) |
| 31 | + |
| 32 | + test('decryption reverses encryption', () => { |
| 33 | + const original = 'Hello World' |
| 34 | + expect(caesarCipher(caesarCipher(original, 13), -13)).toBe(original) |
| 35 | + }) |
| 36 | + |
| 37 | + test('throws TypeError for non-string input', () => { |
| 38 | + expect(() => caesarCipher(123, 1)).toThrow(TypeError) |
| 39 | + }) |
| 40 | + |
| 41 | + test('throws TypeError for non-integer shift', () => { |
| 42 | + expect(() => caesarCipher('ABC', 1.5)).toThrow(TypeError) |
21 | 43 | }) |
22 | 44 | }) |
0 commit comments