New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

binary-breeder

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

binary-breeder - npm Package Compare versions

Comparing version 0.1.2 to 0.1.3

10

lib/binary-breeder.js

@@ -27,2 +27,6 @@ 'use strict';

function validateParentChromosomes(parentChromosomes) {
if(!Array.isArray(parentChromosomes)) {
throw new Error('Parent chromosomes must be provided in an array.');
}
if(parentChromosomes.length !== 2) {

@@ -59,7 +63,3 @@ throw new Error('Exactly two parent chromosomes should be specified.');

if(Random.real(0, 0.999999)(Random.engines.nativeMath) < mutationChance) {
if(chromosome[i] === '0') {
mutatedChromosome += '1';
} else {
mutatedChromosome += '0';
}
mutatedChromosome += chromosome[i] === '0' ? '1' : '0';
} else {

@@ -66,0 +66,0 @@ mutatedChromosome += chromosome[i];

@@ -5,4 +5,5 @@ {

"license": "MIT",
"version": "0.1.2",
"version": "0.1.3",
"main": "lib/binary-breeder.js",
"description": "Breeds the specified number of offspring from two parent strings of binary digits with the possibility of random mutation.",
"devDependencies": {

@@ -9,0 +10,0 @@ "chai": "^3.2.0",

# binary-breeder
Breeds two strings of binary digits and breeds the requested number of offspring.
Breeds the specified number of offspring from two parent strings of binary digits with the possibility of random mutation.

@@ -40,2 +40,12 @@ [![npm](https://img.shields.io/npm/v/binary-breeder.svg)](https://www.npmjs.com/package/binary-breeder) [![Coverage Status](https://coveralls.io/repos/jhaugh42/binary-breeder/badge.svg?branch=master&service=github)](https://coveralls.io/github/jhaugh42/binary-breeder?branch=master) [![Build Status](https://travis-ci.org/jhaugh42/binary-breeder.svg?branch=master)](https://travis-ci.org/jhaugh42/binary-breeder)

var offspring = reproduce(parentChromosomes, numOffspring, mutationChance);
/*
sample output
[ '000010100110110100',
'110011001101100101',
'110010100111100101',
'000011001101110100',
'110011001101100101' ]
*/
```

@@ -22,2 +22,11 @@ 'use strict';

var BAD_INPUT_NON_ARRAYS = [
{name: 'integer', data: 12345},
{name: 'string of two zeros', data: '00'},
{name: 'string of two ones', data: '11'},
{name: 'decimal', data: 0.1},
{name: 'function', data: function(){}},
{name: 'object literal', data: {}}
];
BAD_CHROMOSOMES_NOT_TWO_ELEMENTS.forEach(function(inputChromosomes) {

@@ -60,2 +69,12 @@ it('should throw an Error when the length of the parent chromosome array is ' + inputChromosomes.length, function() {

});
BAD_INPUT_NON_ARRAYS.forEach(function(badInput) {
it('should throw an Error data type of the input chromosome is ' + badInput.name, function() {
function doTest() {
breed(badInput.data, 2, 0.0001);
}
expect(doTest).to.throw(Error);
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc