hedgehogqa / hedgehogqa/fsharp-hedgehog
Difficulty writing properties of a Gen
- Dominant language
- F#
- Stars
- 284
- Forks
- 31
- PR merge metrics
- No merged PRs in 30d
Description
Heya,
I'm writing tests against some custom generators that I've written. I want to make a kind of an assertion like "For a generator, the outcome should be x and it should shrink by f".
I started off using `Gen.generateTree` but quickly realised that I couldn't write properties based on that, as it returns a Tree not a Gen of Tree. Simply lifting the result with `Gen.constant` allows you to write a property but the generated tree never has any variance across tests.
The following appears to give me the behaviour I'm after, it definitely has variance over size but I'm not sure if there's extra work needed to get variance over the seed (as I'm not 100% sure how the layers hang together, do we need to get the next seed after each gen?):
```
let meta (g : Gen<'a>) : Gen> =
let seed = Seed.random ()
Gen.sized <| fun n ->
Gen.toRandom g
|> Random.run seed n
|> Gen.constant
```
Happy to PR with tests if people think this is a good idea for the core library.
Cheers ✌️
Contributor guide
Assessment
This issue has not been assessed yet.