I'm trying to use FsCheck to write a basic property based test for a class that generates random DateTimeOffset
values in a given interval.
[Property]
public void ValueBetweenMinAndMax(DateTimeOffset min, DateTimeOffset max)
{
var sut = new DateTimeOffsetGenerator();
DateTimeOffset actual = sut.Next(min, max);
Assert.True(min <= actual);
Assert.True(max >= actual);
}
That test fails pretty quickly when min
> max
because I validate the input parameters of Next()
and throw an ArgumentException
in that case.
public DateTimeOffset Next(DateTimeOffset min, DateTimeOffset max)
{
if (min > max)
{
throw new ArgumentException(nameof(min));
}
// ...
}
I don't want to change the implementation to swap the input parameters. And I don't want to do that in the test method either.
Is there a way to teach FsCheck to generate the min
and max
values with the constraint that min
must never be greater that max
?
Samples in C# would be greatly appreciated because my knowledge about F# is not up to par.