diff options
author | Andinus <andinus@nand.sh> | 2021-09-04 23:07:40 +0530 |
---|---|---|
committer | Andinus <andinus@nand.sh> | 2021-09-04 23:07:40 +0530 |
commit | 2f65d04253b50737f2313be5ee88b662c9cde19e (patch) | |
tree | 7fdf44764dfddab43373a21720b0d88175a50312 /javascript/hamming/hamming.spec.js | |
parent | 90e12a35bc1814e4d20ce14c84ef7405e15b1e04 (diff) | |
download | exercism-2f65d04253b50737f2313be5ee88b662c9cde19e.tar.gz |
JS: Hamming: Add solution
Diffstat (limited to 'javascript/hamming/hamming.spec.js')
-rw-r--r-- | javascript/hamming/hamming.spec.js | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/javascript/hamming/hamming.spec.js b/javascript/hamming/hamming.spec.js new file mode 100644 index 0000000..de445d3 --- /dev/null +++ b/javascript/hamming/hamming.spec.js @@ -0,0 +1,47 @@ +import { compute } from './hamming'; + +describe('Hamming', () => { + test('empty strands', () => { + expect(compute('', '')).toEqual(0); + }); + + test('single letter identical strands', () => { + expect(compute('A', 'A')).toEqual(0); + }); + + test('single letter different strands', () => { + expect(compute('G', 'T')).toEqual(1); + }); + + test('long identical strands', () => { + expect(compute('GGACTGAAATCTG', 'GGACTGAAATCTG')).toEqual(0); + }); + + test('long different strands', () => { + expect(compute('GGACGGATTCTG', 'AGGACGGATTCT')).toEqual(9); + }); + + test('disallow first strand longer', () => { + expect(() => compute('AATG', 'AAA')).toThrow( + new Error('left and right strands must be of equal length') + ); + }); + + test('disallow second strand longer', () => { + expect(() => compute('ATA', 'AGTG')).toThrow( + new Error('left and right strands must be of equal length') + ); + }); + + test('disallow left empty strand', () => { + expect(() => compute('', 'G')).toThrow( + new Error('left strand must not be empty') + ); + }); + + test('disallow right empty strand', () => { + expect(() => compute('G', '')).toThrow( + new Error('right strand must not be empty') + ); + }); +}); |