generate a deterministic uuids using fast-check
See original GitHub issue💬 Question and Help
I have the following code which I thought would generate a new uuid each time but in a deterministic fashion:
fc.configureGlobal({ seed: 0 });
export const generateUUID4 = (): string => {
const Uuids = fc.sample(fc.uuidV(4), { numRuns: 1000 });
const arb = fc
.infiniteStream(fc.integer({ min: 0, max: 1000 }).noBias().noShrink())
.map((s) => Uuids[s.next().value]);
return fc.sample(arb)[0];
};
But this returns the same uuid
each time.
The only way I can get it working is like this which is horrific with a global variable:
fc.configureGlobal({ seed: 0 });
const Uuids = fc.sample(fc.uuidV(4), { numRuns: 1000 });
let UuidCounter = 0;
export const generateUUID4 = (): string => {
const next = Uuids[UuidCounter];
UuidCounter++;
return next;
};
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
fast-check/Arbitraries.md at main - GitHub
This documentation lists all the built-in arbitraries provided by fast-check . Please note that you can still create your own ones by either...
Read more >Generate valid, deterministic UUIDs for tests - Stack Overflow
I am aware that UUIDs are by nature random and non-deterministic, and that this is good. That assumption is wrong.
Read more >Unit tests for ORM with fast-check | Stas Shakirov
In this article, I am going to show how to use fast-check library to test ... Now we can generate any number of...
Read more >[Solved]-Generate valid, deterministic UUIDs for tests-ruby
What you're trying to do seems like a testing anti-pattern. You could theoretically do what you want by using Version-1 UUIDs with a...
Read more >The Magic of Generative Testing: Fast-Check in JavaScript
Generative testing (aka property testing), popularized by the Haskell library QuickCheck, is a technique of:- specifying invariant laws your ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@dubzzz thank you for taking the time to answer. I am not using your lib as intended but these are great answers.
Fast-check is totally awesome and I love how you are using generators. Generators are seriously underused in js.
Thank you, sir! This is great
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.