From 2f65d04253b50737f2313be5ee88b662c9cde19e Mon Sep 17 00:00:00 2001 From: Andinus Date: Sat, 4 Sep 2021 23:07:40 +0530 Subject: JS: Hamming: Add solution --- javascript/hamming/hamming.spec.js | 47 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 javascript/hamming/hamming.spec.js (limited to 'javascript/hamming/hamming.spec.js') 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') + ); + }); +}); -- cgit 1.4.1-2-gfad0