From 2e5afb948380ab39a45cbed0fd288d05d6dadd16 Mon Sep 17 00:00:00 2001 From: Pavan Tumati Date: Mon, 4 Dec 2017 19:34:33 -0600 Subject: [PATCH] Cosmetic -- Removed biological term jargon to make the interface seem more general --- lib/ObjectMutator.js | 36 +++++++++++++++++++----------------- test/test.js | 12 ++++++------ 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/lib/ObjectMutator.js b/lib/ObjectMutator.js index 465bb86..2f3fa76 100644 --- a/lib/ObjectMutator.js +++ b/lib/ObjectMutator.js @@ -1,6 +1,8 @@ /** - * @fileOverview - * File contains the definitions for the Mutator class + * @fileOverview File contains the definitions for the Mutator class + * @author Pavan Tumati 0 ) { let subMutations = internalGenerateMutations( mutationGroupClone ); nextGeneration.push.apply( nextGeneration, subMutations.map( (submutation ) => { - submutation[ frameGene.gene ] = i; + submutation[ frameObject.targetKey ] = i; return submutation; })); } else { let mutation = {}; - mutation[ frameGene.gene ] = i; + mutation[ frameObject.targetKey ] = i; nextGeneration.push( mutation ); } } @@ -52,8 +54,8 @@ class Mutator { }; this.mutations = (typeof( cullFunction ) === 'function') ? - generateMutations( chromosome, mutationGroup ).filter( cullFunction ) : - generateMutations( chromosome, mutationGroup ); + generateMutations( baseObject, mutationGroup ).filter( cullFunction ) : + generateMutations( baseObject, mutationGroup ); } /** @@ -62,10 +64,10 @@ class Mutator { * * @param {mutationGroup} Mutation group that needs to be checked */ - assertGenesToMutatePresent( mutationGroup ) { + assertKeysToMutatePresent( mutationGroup ) { mutationGroup.forEach(element => { - if( !this.chromosome.hasOwnProperty( element.gene ) ) - throw Error( `Missing gene ${ element.gene }` ); + if( !this.baseObject.hasOwnProperty( element.targetKey ) ) + throw Error( `Missing gene ${ element.targetKey }` ); }); } }; diff --git a/test/test.js b/test/test.js index 8195d3e..8ebeeb6 100644 --- a/test/test.js +++ b/test/test.js @@ -4,7 +4,7 @@ let {expect} = require('chai'); let Mutator = require( '../index.js' ); describe( '#Mutator', function() { - let chromosome = { + let baseObject = { a: 0, b: 0, c: 0, @@ -12,14 +12,14 @@ describe( '#Mutator', function() { }; let mutationGroup = [ - { gene: "a", start: 5, checkRange: (i) => (i < 10 ), step: (i) => i+1 }, - { gene: "b", start: 10, checkRange: (i) => ( i < 20 ), step: (i) => i+2 }, - { gene: "c", start: -10, checkRange: (i) => ( i < 0 ), step: (i) => i+1 } + { targetKey: "a", start: 5, checkRange: (i) => (i < 10 ), step: (i) => i+1 }, + { targetKey: "b", start: 10, checkRange: (i) => ( i < 20 ), step: (i) => i+2 }, + { targetKey: "c", start: -10, checkRange: (i) => ( i < 0 ), step: (i) => i+1 } ]; it( 'should leave unmutated properties untouched', function() { let expectedTotal = 5 * 5 * 10; - let mutationBag = new Mutator( chromosome, mutationGroup ); + let mutationBag = new Mutator( baseObject, mutationGroup ); let result = 0; mutationBag.mutations.forEach(element => { if( element.d === 'Unmutated property' ) result++; @@ -30,7 +30,7 @@ describe( '#Mutator', function() { // TODO: Can do better on this test it( 'should filter out unwanted mutations', function() { - let mutationBag = new Mutator( chromosome, mutationGroup, (mutation) => { + let mutationBag = new Mutator( baseObject, mutationGroup, (mutation) => { return( mutation.a >= 7 ) });