nick8325 / nick8325/quickcheck

Generate value only once possible with xorshift random generator?

Open
#341 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Haskell
Stars
790
Forks
130
Avg merge
16h 41m
Merged PRs (30d)
2

Description

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with QuickCheck's Test-QuickCheck-Gen Gen type and the TFGen implementation using the RandomGen interface, then compare the xorshift RandomGen documentation linked in the issue. Determine whether an alternate generator can be used without custom Arbitrary instances while retaining shrinking. Done should be a documented, working usage path or a clearly scoped API change.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
testing
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.