FsCheck icon indicating copy to clipboard operation
FsCheck copied to clipboard

Generate built-in `Range`

Open stijnmoreels opened this issue 2 years ago • 6 comments

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 😉 .

stijnmoreels avatar Nov 04 '22 06:11 stijnmoreels

Related: there's also Interval

kurtschelfthout avatar Nov 04 '22 22:11 kurtschelfthout

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

stijnmoreels avatar Nov 07 '22 04:11 stijnmoreels

Aha, found everything I needed. Thx for this! 👍

stijnmoreels avatar Nov 07 '22 05:11 stijnmoreels

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

stijnmoreels avatar Nov 07 '22 09:11 stijnmoreels

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.

kurtschelfthout avatar Nov 07 '22 09:11 kurtschelfthout

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.

stijnmoreels avatar Nov 07 '22 11:11 stijnmoreels