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

The type System.IComparable is not handled automatically by FsCheck #443

Closed
jackfoxy opened this issue Jun 24, 2018 · 8 comments
Closed

Comments

@jackfoxy
Copy link
Contributor

Message returned trying to compare type System.IComparable

This would be a useful supported comparison.

@jackfoxy
Copy link
Contributor Author

I think the following code produces a generator, but I was trying it on Expecto which does not support registering a type generator, so I still got the error message from tests.

gen{
            let! t = 
                Arb.generate<'T> 
                |> Gen.filter (fun x ->
                        match x :> obj with 
                        | :? System.IComparable -> true 
                        | _ -> false )
            return t :> System.IComparable }

I'll try to create a PR soon.

@kurtschelfthout
Copy link
Member

I’m not convinced it’s a good idea to add this. What is the concrete use case?

Wouldn’t it be simpler to generate a concrete type that you know is comparable eg int?

@jackfoxy
Copy link
Contributor Author

Here's the concrete use case:
fsprojects/FSharpx.Collections#115

I'm converting tests in this project from Nunit to Expecto, at the same time I upgraded F# support from 4.0. The nunit/fscheck tests passed with System.IComparable.

But amongst updated F#, different testing framework, and more recent version of FsCheck, it's hard to know exactly why the tests now fail.

I could just write equivalent tests without System.IComparable.

I am not the original author of these tests. I would never have written them this way, however the original author thought things through in his own way, and it is desirable to keep a diversity of test styles in the project. My motivation has been only to convert, not alter any existing tests.

@kurtschelfthout
Copy link
Member

There is a ComparableGenerator in that code that probably is not being registered with FsCheck after the move to expecto. I’m not super familiar with expecto, but hopefully, as with other extensions, you can tell it to add that to the default generators. For example, in FsCheck you can add that type via the Config, and in FsCheck.Xunit you can add it via PropertyAttribute.

@jackfoxy
Copy link
Contributor Author

jackfoxy commented Jul 1, 2018

@kurtschelfthout Unfortunately register does not work in Expecto, and probably never will. I think there is an open issue. I'll look at trying to add it in the config, as you suggest.

@jackfoxy
Copy link
Contributor Author

jackfoxy commented Jul 1, 2018

I'm trying to find some way to cons it to the arbitrary list in the config

let comparableConfig = {config10k with arbitrary = ComparableGenerator::config10k.arbitrary}

but the build errors with "No constructors are available for the type 'ComparableGenerator<'a>".
Adding a unit contstructor just raises other errors

@kurtschelfthout
Copy link
Member

In the original code it doesn't look like the comparable generator is being registered either.

I think you have problems that are wholly unrelated to FsCheck or Expecto. E.g. see the warnings in the build output:

/home/travis/build/fsprojects/FSharpx.Collections/tests/FSharpx.Collections.Experimental.Tests/SkewBinomialHeapTest.fs(128,20): warning FS0064: This construct causes code to be less generic than indicated by the type annotations. The type variable 'T has been constrained to be type 'IComparable'. [/home/travis/build/fsprojects/FSharpx.Collections/tests/FSharpx.Collections.Experimental.Tests/FSharpx.Collections.Experimental.Tests.fsproj]
e/travis/build/fsprojects/FSharpx.Collections/tests/FSharpx.Collections.Tests/bin/Release/net47/FSharpx.Collections.Tests.exe
ental.Tests -> /home/travis/build/fsprojects/FSharpx.Collections/tests/FSharpx.Collections.Experimental.Tests/bin/Release/net47/FSharpx.Collections.Experimental.Tests.exe
Consider app.config remapping of assembly "FSharp.Core, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" from Version "4.3.1.0" [] to Version "4.5.0.0" [/home/travis/build/fsprojects/FSharpx.Collections/packages/FSharp.Core/lib/net45/FSharp.Core.dll] to solve conflict and get rid of warning.
/usr/share/dotnet/sdk/2.1.300/Microsoft.Common.CurrentVersion.targets(2106,5): warning MSB3276: Found conflicts between different versions of the same dependent assembly. Please set the "AutoGenerateBindingRedirects" property to true in the project file. For more information, see http://go.microsoft.com/fwlink/?LinkId=294190. [/home/travis/build/fsprojects/FSharpx.Collections/docs/content/csharp/csharp.csproj]
csharp -> /home/travis/build/fsprojects/FSharpx.Collections/docs/content/csharp/bin/Release/csharp.exe
Build succeeded.
/home/travis/build/fsprojects/FSharpx.Collections/tests/FSharpx.Collections.Experimental.Tests/SkewBinomialHeapTest.fs(128,20): warning FS0064: This construct causes code to be less generic than indicated by the type annotations. The type variable 'T has been constrained to be type 'IComparable'. [/home/travis/build/fsprojects/FSharpx.Collections/tests/FSharpx.Collections.Experimental.Tests/FSharpx.Collections.Experimental.Tests.fsproj]

@kurtschelfthout
Copy link
Member

Closing due to inactivity.

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