-
Notifications
You must be signed in to change notification settings - Fork 156
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
Update docs with new Arbitrary
API based on ArbMap
#644
Comments
Have a look at ArbMap which now contains the mapping type to Arb instance explicitly. On 14 Sep 2023, at 23:06, Lewis Campbell ***@***.***> wrote:
Reading https://fscheck.github.io/FsCheck//TestData.html
It says:
"Arb.from<'a> returns the registered Arbitrary instance for the given type 'a"
But that's not available.
open FsCheck.FSharp
open Laterbase.Core
open System
Console.Clear ()
let genBytes = Arb.from<byte>
Nor is it in the API docs
https://fscheck.github.io/FsCheck/reference/fscheck-fsharp-arb.html
I'm basically trying to re-write the 2.0 function in 3.0, and I'm at a bit of a loss.
Arb.generate<byte> |> Gen.arrayOfLength 16
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
Per #638, I have a: module ArbMap =
let defGen<'t> = ArbMap.defaults |> ArbMap.generate<'t> That I sprinkle around The changes are listed in https://github.com/fscheck/FsCheck/blob/master/FsCheck%20Release%20Notes.md 🤔 (I found it by searching for |
What would help me - as someone new to the library in general - is a very basic example of how to use the built in generators to build your own generators.
This is equivalent to the old Arb.generate? |
Yes - it's equivalent. See this PR for some code that uses it https://github.com/jet/equinox/pull/412/files In general I'd recommend downloading the FsCheck solution and doing a text search within in - there's some examples and you also get to see the relationships. The changelog linked above actually does detail the transitions quite well if you read it carefully, but I've been in your shoes wondering where all the cheese has gone and when the yaks are going to part ways and let you move on, so I can definitely empathise... |
I also learned/realised/figured out recently that the best/typical way to decorate the generation is by having a "factory" Arb that takes the
https://stackoverflow.com/a/77982678/11635 cc @kurtschelfthout It took me ages to work this out as I don't believe the docs mention it in the samples. For people trying to use FsCheck via FsCheck.Xunit/Nunit (and without reading the source), I suspect the way that the Factory signature for an Arb works (and that you can build an ArbMap by adding them singly, adding a factory singly, scan a type (and that both signatures work in that context)) is far from obvious as it stands. But I do appreciate that you said no to the ArbMap.defGen thing I have above - ultimately that's a misleading local maximum; I'll be replacing it with the factory technique intead in my normal usage |
I know this is far from obvious. Besides the obvious problem that the documentation is out of date, the problem of automatic generation is actually pretty thorny. Because you often want to customize the generation of a type that's nested inside some other types, and has yet other types as parameters. So you could say I started with the idea of "just put all the types in a Type -> generator map, but then realized that doesn't quite work for common use cases like collections |
Arbitrary
API based on ArbMap
Reading https://fscheck.github.io/FsCheck//TestData.html
It says:
"Arb.from<'a> returns the registered Arbitrary instance for the given type 'a"
But that's not available, this won't compile.
Nor is it in the API docs
https://fscheck.github.io/FsCheck/reference/fscheck-fsharp-arb.html
I'm basically trying to re-write the 2.0 function in 3.0, and I'm at a bit of a loss.
The text was updated successfully, but these errors were encountered: