'use strict'; import { mutation_type, mutate, is_valid, } 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, 1]); expect(mutate([0, 1, 2], mutation_type.weight, 0.0)).toEqual([0, 1, -1]); expect(mutate([0, 1, 2], mutation_type.weight, 1.0)).toEqual([0, 1, 3]); }); test('genome validation', () => { expect(is_valid(0, 0, [ [ 0, 0, 1.0 ] ])).toBe(true); expect(is_valid(2, 1, [ [ 0, 2, 1 ] ])).toBe(true); expect(is_valid(2, 1, [ [ 0, 1, 1 ] ])).toBe(false); expect(is_valid(2, 1, [ [ 0, 2, 5 ] ])).toBe(false); });