summary refs log tree commit diff stats
path: root/javascript/hamming/hamming.spec.js
blob: de445d351e04c5511f2757b862dc632905e14ce2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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')
    );
  });
});