chance-generators
Advanced tools
Comparing version 1.16.0 to 1.17.0
@@ -91,3 +91,3 @@ --- | ||
### identity | ||
### constant | ||
@@ -97,5 +97,5 @@ Always generates the given value. | ||
```js | ||
let { identity } = new Generators(42) | ||
let { constant } = new Generators(42) | ||
let constantNumberGenerator = identity(42) | ||
let constantNumberGenerator = constant(42) | ||
@@ -102,0 +102,0 @@ expect(constantNumberGenerator, 'when called', 'to equal', 42) |
@@ -143,3 +143,3 @@ /*global define*/ | ||
} else { | ||
return that.identity(data) | ||
return that.constant(data) | ||
} | ||
@@ -153,3 +153,3 @@ | ||
if (data.length === 0) { | ||
return that.identity(data) | ||
return that.constant(data) | ||
} | ||
@@ -179,7 +179,7 @@ | ||
pickone: function (generator, data) { | ||
return that.identity(data) | ||
return that.constant(data) | ||
}, | ||
pickset: function (generator, data) { | ||
if (data.length === 0) { | ||
return that.identity(data) | ||
return that.constant(data) | ||
} | ||
@@ -209,3 +209,3 @@ | ||
if (!shrinkable) { | ||
return that.identity(data) | ||
return that.constant(data) | ||
} | ||
@@ -248,3 +248,3 @@ | ||
} else { | ||
return that.identity(data) | ||
return that.constant(data) | ||
} | ||
@@ -263,3 +263,3 @@ }, | ||
if (data.length === 0) { | ||
return that.identity(data) | ||
return that.constant(data) | ||
} else if (typeof limits.length === 'undefined') { | ||
@@ -270,3 +270,3 @@ limits.length = that.integer({ min: 0, max: data.length }) | ||
} else { | ||
return that.identity(data) | ||
return that.constant(data) | ||
} | ||
@@ -316,3 +316,3 @@ | ||
g.shrink = function (data) { | ||
return that.identity(data) | ||
return that.constant(data) | ||
} | ||
@@ -339,4 +339,4 @@ } | ||
that.identity = generatorFunction('identity', [], function (data) { | ||
var identityGenerator = generatorFunction('identity', [data], function () { | ||
that.identity = that.constant = generatorFunction('constant', [], function (data) { | ||
var identityGenerator = generatorFunction('constant', [data], function () { | ||
return data | ||
@@ -346,3 +346,3 @@ }) | ||
identityGenerator.map = function (fn) { | ||
return that.identity(unwrap(fn(data))) | ||
return that.constant(unwrap(fn(data))) | ||
} | ||
@@ -349,0 +349,0 @@ |
{ | ||
"name": "chance-generators", | ||
"version": "1.16.0", | ||
"version": "1.17.0", | ||
"description": "Random generators based on changejs", | ||
@@ -5,0 +5,0 @@ "main": "lib/chance-generators.js", |
@@ -262,2 +262,21 @@ /*global describe, it*/ | ||
describe('constant', () => { | ||
it('generate the given value', () => { | ||
expect(chance.constant({ foo: 'bar' }), 'when called', 'to equal', { | ||
foo: 'bar' | ||
}) | ||
}) | ||
it('always generates the given value', () => { | ||
const value = { foo: 'bar' } | ||
for (var i = 0; i < 5; i += 1) { | ||
expect(chance.constant(value), 'when called', 'to be', value) | ||
} | ||
}) | ||
it('does not unwrap generators', () => { | ||
expect(chance.constant(chance.integer), 'when called', 'to be a function') | ||
}) | ||
}) | ||
describe('identity', () => { | ||
@@ -264,0 +283,0 @@ it('generate the given value', () => { |
30542
632