31 lines
No EOL
1.4 KiB
JavaScript
31 lines
No EOL
1.4 KiB
JavaScript
import { caesarCipher } from "./caesarCipher.js";
|
|
|
|
// function that takes a string and a shift factor and returns it with each character “shifted”
|
|
test ('Function throws error if either argument is missing', () => {
|
|
expect(() => caesarCipher()).toThrow('Invalid inputs!');
|
|
expect(() => caesarCipher(null, 8)).toThrow('Invalid inputs!');
|
|
expect(() => caesarCipher('fish')).toThrow('Invalid inputs!');
|
|
});
|
|
test ('Function throws error if shift factor is not a number', () => {
|
|
expect(() => caesarCipher('string', {})).toThrow('Invalid inputs!');
|
|
});
|
|
test ('Function throws error on non-String input', () => {
|
|
expect(() => caesarCipher([8], 8)).toThrow('Invalid inputs!');
|
|
});
|
|
test ('Function throws error on blank String input', () => {
|
|
expect(() => caesarCipher('', 8)).toThrow('Invalid inputs!');
|
|
});
|
|
test ('Function returns String when passed valid input String', () => {
|
|
const tester = caesarCipher('string', 8);
|
|
expect(tester).toEqual(expect.any(String));
|
|
});
|
|
test ('Function returns factor-shifted String', () => {
|
|
const tester = caesarCipher('string', 13);
|
|
const tester2 = caesarCipher('string', 2);
|
|
expect(tester).toBe('fgevat');
|
|
expect(tester2).toBe('uvtkpi');
|
|
});
|
|
test ('Function returns factor-shifted String when given negative factor', () => {
|
|
const tester = caesarCipher('abba', -15);
|
|
expect(tester).toBe('lmml');
|
|
}); |