Created
July 2, 2020 18:02
-
-
Save dubzzz/1e66958bfc9928d887adfbd5d0cc151d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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