刚开始看 FsCheck,写了几个测试,现在我想知道什么是编写更复杂的任意值的好策略。是否在任意好的方法中注册任意项?像这样的东西
public class DiscountAmountArbitrator
{
public static Arbitrary<DiscountAmount> DiscountAmounts()
{
Arb.Register<AmountArbitrary>();
var toReturn = (from a in Arb.Generate<Amount>()
select new DiscountAmount(a))
.ToArbitrary();
return toReturn;
}
}
public class AmountArbitrary
{
public static Arbitrary<Amount> Amounts()
{
return Arb.Generate<decimal>().Where(x => x > 0)
.Select(x => new Amount(x))
.ToArbitrary();
}
}