Use custom FsCheck Arbitrary in testProperty
See original GitHub issueI have this code:
type 'a ClusteredList = ClusteredList of 'a list
let private clusteredListGen =
gen {
let! clusterValues = Arb.generate<int> |> Gen.listOf |> Gen.filter (fun x -> x.Length < 10)
let! res =
clusterValues
|> List.map (Gen.constant >> Gen.nonEmptyListOf)
|> List.fold (fun acc x -> gen {
let! acc = acc
let! x = x
return acc @ x })
(Gen.constant [])
return ClusteredList res
} |> Arb.fromGen
testCase "concat = original seq" <| fun _ ->
let prop (ClusteredList xs) =
xs |> Seq.groupClusteredBy id id |> Seq.collect snd |> Seq.toList = xs
Check.QuickThrowOnFailure (Prop.forAll clusteredListGen prop)
Is it possible to rewrite it with testProperty
? I tried:
let private clusteredListConfig = { FsCheckConfig.defaultConfig with arbitrary = FsCheckConfig.defaultConfig.arbitrary @ [??????] }
testPropertyWithConfig clusteredListConfig "test" <| fun _ -> ...
arbitrary
is a list of Type
s, I have a value of Arbitrary<_>
instance. Any ideas how to pass it to config?
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (8 by maintainers)
Top Results From Across the Web
Test data: generators, shrinkers and Arbitrary instances
Test data is produced by test data generators. FsCheck defines default generators for some often used types, but you can use your own,...
Read more >Generating custom data in FsCheck
First, I'll tackle how to generate a Style that isn't Legendary. You could use Gen.oneOf , but in this case I think it's...
Read more >Ad hoc Arbitraries with FsCheck.Xunit - ploeh blog
Another apparent solution is to define a custom Arbitrary for FsCheck.Xunit. The mechanism is to define a static class with your custom rule, ......
Read more >Arbitrary Version instances with FsCheck - ploeh blog
As the FsCheck documentation explains, you can create custom Generator by defining a static class that exposes members that return Arbitrary<'a> ...
Read more >Understanding FsCheck
Yes – you can control how each test and shrink is displayed by writing your own custom functions, and telling FsCheck to use...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Meta: I’m not going to contribute to more fragmentation by supporting a library that seemingly doesn’t send pull requests towards FsCheck. If it wants to remodel FsCheck then that should be a pull request first, being rejected (like this project was with Fuchu).
On topic: so the only difference there is really
Prop.ForAll
versusproperty {}
– because the generators can be used and consumed with a workflow builder in FsCheck as well? That the sample uses operators instead of a workflow builder doesn’t change that (but does make the two snippets read very differently)Closing this as Arbitrary is not recommended and won’t be support in future FsCheck.
I’ve added an explanation to the docs and the following issues explain in detail in #201 and fscheck/FsCheck#413.