Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate value only once possible with xorshift random generator? #341

Open
codygman opened this issue Apr 1, 2022 · 0 comments
Open

Generate value only once possible with xorshift random generator? #341

codygman opened this issue Apr 1, 2022 · 0 comments

Comments

@codygman
Copy link

codygman commented Apr 1, 2022

I'm in a situation where test data is generated with Arbitrary and generate and is very useful, but not unique enough.

Part of this is due to shrinking I believe, which I've tried to disable where I can.

Using resize for values like UUID seems to help in some places... but things are still flaky.

Due to tests taking too long and not enough time to fix it another way, we had to introduce a shared database which creates test pollution and necessitates uniqueness of arbitrary values.

Even without test pollution though, some of the arbitrary data is used in data types that are inserted to a database containing Uniqueness constraints.

Doing some research I came across this comment on Haskell QuickCheck Unique Random Number Generation:

The xorshift random generator has no repetitions by design. You could try it. (the statement above holds for the first 2^64 or so numbers. - source

That led me to Gen and I saw that it uses TFGen which uses the RandomGen interface.

The xorshift random generator implementation here also supports RandomGen so it seems possible to use xorshift to solve the problem I currently have without writing 100s of custom Arbitrary instances.

However, it's very unclear how I'd use Quickcheck with a different random number generator.

Another quick "fix" being disabling shrinking everywhere, but that could make tests take much longer again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant