I have the following code:
var gen = from x in Arb.Generate<int>()
from int y in Gen.Choose(5, 10)
where x > 5
select new tuple { Fst = x, Snd = y };
And I can run
Prop.ForAll<tuple>(c =>
Console.WriteLine($"{c.Fst}, {c.Snd}")
).Check(Configuration.Default);
I see all the ways to construct generators and define properties.
But I just don't find quickly enough how to use them together.
You need to register the custom generator with FsCheck. See FSCheck docs.
In short, create a class to keep your custom generators. Have a public static method returning an Arbitrary<T> where T is the type you are generating.
In your example, you would need to wrap your generator in a call to Arb.From(...).
public class MyGenerators {
public static Arbitrary<tuple> Tuple() {
return Arb.From(from x in Arb.Generate<int>()
from int y in Gen.Choose(5, 10)
where x > 5
select new tuple { Fst = x, Snd = y });
}
}
Finally, call Arb.Register<MyGenerators>() before running your test.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With