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

Gen registration and creation? #93

Closed
AnthonyLloyd opened this issue May 3, 2017 · 7 comments
Closed

Gen registration and creation? #93

AnthonyLloyd opened this issue May 3, 2017 · 7 comments

Comments

@AnthonyLloyd
Copy link

Do you plan on this kind of feature? Gen.type<'a> from already registered Gen types.

@moodmosaic
Copy link
Member

moodmosaic commented May 3, 2017

I find this a very interesting question.

The plan is to have the F# version in line with the Haskell one. In the Haskell version there are no Arbitrary instances (and therefore no orphans) and so there's no reason to deviate in F#.

Actually, in F#, things are even worse because there's currently no direct support for type classes, and you'd have to simulate them instead (like FsCheck doeswhich, in my opinion, was a design mistake).

Even Kurt Schelfthout, the author of FsCheck (that currently supports what you describe), was not sure if Arbitrary is worth keeping in FsCheck vNext.

To simulate the Arbitrary registration mechanism in F# Hedgehog, you may use a dictionary and write a reflection-based generator using TypeShape, similar to this one—but that can't be part of F# Hedgehog.

/cc @jystic

@AnthonyLloyd
Copy link
Author

AnthonyLloyd commented May 3, 2017

Yeah, I've never liked Arbitrary, it just gets in the way and seems a bit...arbitrary.

I was thinking something like Infers. Tutorial here (https://github.com/AnthonyLloyd/Infers/blob/master/Docs/Tutorial.md) but gone from repo.

I love the automatic shrinking by default but would need to be able to gen DUs etc automatically to be able to use it in testing.

@moodmosaic
Copy link
Member

I'd be nice to see an example of this using Infers 👍 Apart from that, I think we should close this issue. We can still add comments, and even reopen it in the future, if necessary.

@AnthonyLloyd
Copy link
Author

Sure

@moodmosaic
Copy link
Member

@AnthonyLloyd

I love the automatic shrinking by default but would need to be able to gen DUs etc automatically to be able to use it in testing.

I wrote an example in #133 (comment) where you can automatically generate DUs and pretty much any other type.

@AnthonyLloyd
Copy link
Author

Great. I love hedgehog and have been using it on a nested DU domain model.

Interestingly the automatic gen of this model from FsCheck is wrong for me because it generates each top level case with the same probability etc. I really need each leaf case to be generated with the same probability. So coded the gen.

I'd be interested in adding hedgehog to Expecto if the automatic gen was added and we were certain that FsCheck would never be refactored to work as hedgehog does without Arbitrary.

@moodmosaic
Copy link
Member

FWIW, @cmeeren provided an updated, configurable, version of arbitrary POCO generartion in #133 (comment).

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

2 participants