question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use custom FsCheck Arbitrary in testProperty

See original GitHub issue

I 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 Types, I have a value of Arbitrary<_> instance. Any ideas how to pass it to config?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
hafcommented, Apr 10, 2017

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 versus property {} – 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)

0reactions
AnthonyLloydcommented, Dec 5, 2017

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found