odin-default-js-exercises/archive/archived_caesar/solution/caesar-solution.spec.js

24 lines
707 B
JavaScript
Raw Normal View History

2023-02-01 23:53:54 +00:00
const caesar = require('./caesar-solution');
2022-02-20 19:07:44 +00:00
2023-02-01 23:53:54 +00:00
test('works with single letters', () => {
expect(caesar('A', 1)).toBe('B');
2022-02-20 19:07:44 +00:00
});
2023-02-01 23:58:58 +00:00
test('works with words', () => {
2023-02-01 23:53:54 +00:00
expect(caesar('Aaa', 1)).toBe('Bbb');
2022-02-20 19:07:44 +00:00
});
2023-02-01 23:58:58 +00:00
test('works with phrases', () => {
2023-02-01 23:53:54 +00:00
expect(caesar('Hello, World!', 5)).toBe('Mjqqt, Btwqi!');
2022-02-20 19:07:44 +00:00
});
2023-02-01 23:58:58 +00:00
test('works with negative shift', () => {
2023-02-01 23:53:54 +00:00
expect(caesar('Mjqqt, Btwqi!', -5)).toBe('Hello, World!');
2022-02-20 19:07:44 +00:00
});
2023-02-01 23:58:58 +00:00
test('wraps', () => {
2023-02-01 23:53:54 +00:00
expect(caesar('Z', 1)).toBe('A');
2022-02-20 19:07:44 +00:00
});
2023-02-01 23:58:58 +00:00
test('works with large shift factors', () => {
2023-02-01 23:53:54 +00:00
expect(caesar('Hello, World!', 75)).toBe('Ebiil, Tloia!');
2022-02-20 19:07:44 +00:00
});
2023-02-01 23:58:58 +00:00
test('works with large negative shift factors', () => {
2023-02-01 23:53:54 +00:00
expect(caesar('Hello, World!', -29)).toBe('Ebiil, Tloia!');
2022-02-20 19:07:44 +00:00
});