summaryrefslogtreecommitdiff
path: root/src/protein/protein.test.js
blob: 61c4896c43df1216c4f6f00d3dac822d6fb434b4 (plain)
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
'use strict';

import { compare } from './protein';

test('compare size-1 proteins', () => {
	expect(compare([0], [0])).toBe(1);
	expect(compare([0], [1])).toBe(0);
	expect(compare([1], [0])).toBe(0);
	expect(compare([1], [1])).toBe(1);
});


test('compare larger proteins', () => {
	expect(compare([0,0], [0,0])).toBe(1);
	expect(compare([1,1], [1,1])).toBe(1);
	expect(compare([0,1], [1,1])).toBeCloseTo(0.5);
	expect(compare([0,1,0], [1,1,1])).toBeCloseTo(1/3);
	expect(compare([0,1,0,1], [1,1,1,1])).toBeCloseTo(0.5);
	expect(compare([0,1,0,1], [0,1,1,1])).toBeCloseTo(0.75);
	expect(compare([0,1,0,1], [0,1,1,0])).toBeCloseTo(0.5);
	expect(compare([0,1,0,0], [0,1,1,0])).toBeCloseTo(0.75);
	expect(compare([0,1,1,0], [0,1,1,0])).toBeCloseTo(1);
});


test('comparisons between differently-sized proteins throw', () => {
	expect(() => compare([0], [0, 0])).toThrow();
	expect(() => compare([0, 0], [0])).toThrow();
});