summaryrefslogtreecommitdiff
path: root/src/genome/genome.test.js
blob: 853d1039a7679ff7ae3c12d5c049d43be02cae45 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
'use strict';

import { mutation_type, mutate } from './genome';


test('basic gene mutations', () => {
  expect(mutate([0, 1, 2], mutation_type.none, 0)).toEqual([0, 1, 2]);

  expect(mutate([0, 1, 2], mutation_type.source, 0.2)).toEqual([0, 1, 2]);
  expect(mutate([1, 1, 2], mutation_type.source, 0.2)).toEqual([0, 1, 2]);
  expect(mutate([0, 1, 2], mutation_type.source, 0.8)).toEqual([1, 1, 2]);

  expect(mutate([0, 1, 2], mutation_type.sink, 0.2)).toEqual([0, 0, 2]);
  expect(mutate([0, 1, 2], mutation_type.sink, 0.8)).toEqual([0, 2, 2]);
  expect(mutate([0, 0, 2], mutation_type.sink, 0.2)).toEqual([0, 0, 2]);

  expect(mutate([0, 1, 2], mutation_type.weight, 0.5)).toEqual([0, 1, 0]);
  expect(mutate([0, 1, 2], mutation_type.weight, 0.0)).toEqual([0, 1, -4]);
  expect(mutate([0, 1, 2], mutation_type.weight, 1.0)).toEqual([0, 1, 4]);
});