Skip to content

Instantly share code, notes, and snippets.

@dubzzz
Created July 2, 2020 18:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dubzzz/1e66958bfc9928d887adfbd5d0cc151d to your computer and use it in GitHub Desktop.
Save dubzzz/1e66958bfc9928d887adfbd5d0cc151d to your computer and use it in GitHub Desktop.
miniFc.tuple = (...itemGenerators) => {
return {
generate(mrng) {
return itemGenerators.map(g => g.generate(mrng));
},
*shrink(value) {
for (let index = 0 ; index !== itemGenerators.length ; ++index) {
const currentGenerator = itemGenerators[index];
const currentValue = value[index];
for (const shrunkValue of currentGenerator.shrink(currentValue)) {
yield [...value.slice(0, index), shrunkValue, ...value.slice(index + 1)];
}
}
}
}
}
// You can check the output by calling:
// > [...miniFc.tuple(miniFc.integer(0, 100), miniFc.integer(0, 100), miniFc.integer(0, 100)).shrink([4, 3, 4])]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment