chance-generators
Advanced tools
Comparing version 1.10.0 to 1.11.0
@@ -111,3 +111,3 @@ /*global define*/ | ||
if (value < 0) { | ||
if (value < 0 && value < (currentLimits.max || 0)) { | ||
var max = currentLimits.max || 0 | ||
@@ -118,3 +118,3 @@ limits = { | ||
} | ||
} else if (value > 0) { | ||
} else if (value > 0 && value > (currentLimits.min || 0)) { | ||
var min = currentLimits.min || 0 | ||
@@ -145,3 +145,8 @@ limits = { | ||
return createGenerator('pickset', [data, count]) | ||
var dataGenerator = generator.args[0] | ||
if (dataGenerator.shrink) { | ||
return createGenerator('pickset', [data.map(dataGenerator.shrink), count]) | ||
} else { | ||
return createGenerator('pickset', [data, count]) | ||
} | ||
}, | ||
@@ -166,2 +171,4 @@ pick: function (generator, data) { | ||
count = count.shrink(data.length) | ||
} else { | ||
return that.identity(data) | ||
} | ||
@@ -183,5 +190,7 @@ | ||
var shapeGenerators = generator.args[0] | ||
var shrunk = false; | ||
var newShape = Object.keys(shapeGenerators).reduce(function (result, key) { | ||
var entry = shapeGenerators[key] | ||
if (entry && typeof entry.shrink === 'function') { | ||
shrunk = true | ||
result[key] = entry.shrink(data[key]) | ||
@@ -195,9 +204,9 @@ } else { | ||
return createGenerator('shape', [newShape]) | ||
if (shrunk) { | ||
return createGenerator('shape', [newShape]) | ||
} else { | ||
return that.identity(data) | ||
} | ||
}, | ||
string: function (generator, data) { | ||
if (data.length === 0) { | ||
return that.identity(data) | ||
} | ||
var currentLimits = generator.args[0] || {} | ||
@@ -209,2 +218,4 @@ var limits = copy(currentLimits) | ||
limits.length = limits.length.shrink(data.length) | ||
} else { | ||
return that.identity(data) | ||
} | ||
@@ -211,0 +222,0 @@ |
{ | ||
"name": "chance-generators", | ||
"version": "1.10.0", | ||
"version": "1.11.0", | ||
"description": "Random generators based on changejs", | ||
@@ -5,0 +5,0 @@ "main": "lib/chance-generators.js", |
@@ -151,8 +151,6 @@ /*global describe, it*/ | ||
var generator = chance.n(chance.string, chance.integer({ min: 2, max: 4 })) | ||
for (var i = 0; i < 3; i += 1) { | ||
var generatedValue = generator() | ||
generator = generator.shrink(generatedValue) | ||
expect(generator, 'when called', 'to have items satisfying', | ||
'to be contained by', generatedValue) | ||
while (generator.shrink) { | ||
generator = generator.shrink(generator()) | ||
} | ||
expect(generator, 'when called', 'to have length', 2) | ||
}) | ||
@@ -340,3 +338,3 @@ }) | ||
for (var i = 0; i < 10; i += 1) { | ||
while (generator.shrink) { | ||
generator = generator.shrink(generator()) | ||
@@ -343,0 +341,0 @@ } |
28129
565