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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate built-in Range #621

Open
stijnmoreels opened this issue Nov 4, 2022 · 6 comments
Open

Generate built-in Range #621

stijnmoreels opened this issue Nov 4, 2022 · 6 comments

Comments

@stijnmoreels
Copy link
Member

stijnmoreels commented Nov 4, 2022

Hi! 馃憢
Was thinking of adding a built-in generator of the System.Range struct, as this would expand the default generator functionality.
Am currently using this:

let range = gen {
  let! min = Gen.choose (0, Int32.MaxValue)
  let! max = Gen.choose (min, Int32.MaxValue)
  return Range (min, max) }

To make sure that the minimum is always lower than the maximum. But, with some additional options, one could include Range.StartAt and Range.EndAt too.

Just a suggestion when using the awesome FsCheck library 馃槈 .

@kurtschelfthout
Copy link
Member

Related: there's also Interval

@stijnmoreels
Copy link
Member Author

Ah, shoot, didn't see that one. Maybe that would be ok, too.
I'll try that. Thx!

@stijnmoreels
Copy link
Member Author

Aha, found everything I needed. Thx for this! 馃憤

@stijnmoreels
Copy link
Member Author

Maybe an idea to create an extra generator that generate the built-in System.Range from an Interval?
But that may be overdoing it.

@kurtschelfthout
Copy link
Member

Maybe an idea to create an extra generator that generate the built-in System.Range from an Interval?

Yeah I think that makes sense. Or even extract the code and parametrize the contructor, could be slightly faster without creating an intermediate type.

For standard types like System.Range I think it certainly makes sense to have them built-in.

@stijnmoreels
Copy link
Member Author

stijnmoreels commented Nov 7, 2022

Great! Happy to pick this up, but the supported frameworks on the main project are still not in the range where the System.Range is supported (net452;netstandard2.0;netstandard1.6;netstandard1.0) so maybe this could be set up on-hold till we update FsCheck towards .NET 6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants