From 6aae1f6fb4cf289ecf5ed318b34c0e7df62bbf83 Mon Sep 17 00:00:00 2001 From: sanine-a Date: Tue, 1 Aug 2023 17:03:28 -0500 Subject: add mutation_type and mutate() --- src/genome/genome.test.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/genome/genome.test.js (limited to 'src/genome/genome.test.js') diff --git a/src/genome/genome.test.js b/src/genome/genome.test.js new file mode 100644 index 0000000..853d103 --- /dev/null +++ b/src/genome/genome.test.js @@ -0,0 +1,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]); +}); -- cgit v1.2.1