Files
JavaScript/Ciphers/test/XORCipher.test.js
Fahim Faisaal c21ad2ca7a merge: Improved xorCipher (#965)
* feat: improved memoize function

used Map instead of object & used the JSON.stringfy method for generate a valid string as a key

* docs: modified documentation

* style: format with standard

* docs: modified stringify doc

* refactor: remove two repetition implementation

* feat: added validation, test codes

* chore: remove useless words

* feat: added types for jest

* chore: added link box

* feat: added new validation test casses & methods

* style: formated with standard

* feat: added parse method & test cases

* docs: added js docs

* chore: added default import export

* feat: imporved algorithm via replace method

* test: added two test cases

* feat: added jest type for suggestions

* feat: added `reduceRight` & `trim` method

* chore: added helper variable

* feat: added new rotation option

* Revert "chore: added helper variable"

This reverts commit 489544da0a3d479910fbea020d3be3d0d10681bf.

* remove: yarn lock

* chore: fix grammer

* feat: used replace method & added test case

* feat: remove revert

* chore: added new line
2022-03-29 22:03:26 +05:30

19 lines
712 B
JavaScript

import XORCipher from '../XORCipher'
describe('Testing XORCipher function', () => {
it('Test - 1, passing a non-string as an argument', () => {
expect(() => XORCipher(false, 0x345)).toThrow()
expect(() => XORCipher(true, 123)).toThrow()
expect(() => XORCipher(1n, 123n)).toThrow()
expect(() => XORCipher(false, 0.34)).toThrow()
expect(() => XORCipher({})).toThrow()
expect(() => XORCipher([])).toThrow()
})
it('Test - 2, passing a string & number as an argument', () => {
// NB: Node REPL might not output the null char '\x00' (charcode 0)
expect(XORCipher('test string', 32)).toBe('TEST\x00STRING')
expect(XORCipher('TEST\x00STRING', 32)).toBe('test string')
})
})