Coder Social home page Coder Social logo

ptumati / objectmutator Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 7 KB

A node.js package to allow you apply the Counting Rule to Javascript object properties to generate mutations of an object for genetic algorithms or API endpoint testing

JavaScript 100.00%

objectmutator's Introduction

Object Mutator

A small library that lets you generate mutations of a Javascript object at the property level. (See http://www.tumati.com/objectmutator-js-generating-all-or-some-subset-of-combinations-an-object-at-the-property-or-key-value-pair-level/.)

Usage

Documentation is lacking, but here's a quick example of usage:

let chromosome = {
    a: 0,
    b: 0,
    c: 0,
    d: "Unmutated property"
};

let mutationGroup = [
    { gene: "a", start: 5, checkRange: (i) => (i <= 10 ), step: (i) => i+1 },
    { gene: "b", start: 20, checkRange: (i) => ( i <= 30 ), step: (i) => i+2 },
    { gene: "c", start: -1, checkRange: (i) => ( i <= 3 ), step: (i) => i+1 }
];

let filteredMutationBag = new Mutator( chromosome, mutationGroup, (mutation) => { 
    return( mutation.a > 7 ) 
});
console.log( filteredMutationBag.mutations );

The mutations property above would contain every combination of 'chromosome' where:

    - 'a' ranges from 5 to 10, stepping by 1 *
    - 'b' ranges from 20 to 30, stepping by 2
    - 'c' ranges from -1 to 3, stepping by 1
    - 'd' remains the same in every object as it was passed in using the chromosome parameter

(* 'a' eventually gets filtered by the 'cullFunction', where the values that were generated 
with a from 5 to 7 are dropped.  This is just an example!  The cullFunction is useful for making 
sure that, in a new generation of objects, that certain objects are removed because of invalid 
relationships between properties.)

Tests

npm test

Contributing

In lieu of a formal style guide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.

objectmutator's People

Contributors

ptumati avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.