我有一个FsCheck属性,如下所示:
[Property]
public Property ConversionCanBeInversedForAllUnits(double input, string unit1, string unit2)
{ ... }FsCheck会给它提供随机值。我希望将字符串的输入限制为某个固定集合的成员。
显而易见的解决方案是:
[Property]
public Property ConversionCanBeInversedForAllUnits(double input, int unit1Int, int unit2Int)
{
string unit1 = units[unit1Int % units.Lenght];
string unit2 = units[unit2Int % units.Lenght];
input = math.clamp(min, input, max);
}我不认为这样使用是刻意的。
第二次尝试没有成功。首先,我添加了一些类
public class MyTestDataCreator
{
private static string[] lengthUnits = new string[] { "m", "mm" };
public static Arbitrary<string> lenghtunits()
{
// Does not compile.
return FsCheck.Gen.Choose(0, lengthUnits.Length).Select(index => lengthUnits[index]);
}
public Gen<double> DoubleGen()
{
return FsCheck.Gen.Choose(0, 1000);
}
}并将该属性更改为
[Property(Arbitrary = new Type[] { typeof(MyTestDataCreator) })]这就给我留下了一个例外
Message: System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation.
---- System.Exception : No instances found on type Prop.MyTestDataCreator. Check that the type is public and has public static members with the right signature.这就引出了一个问题:什么是正确的签名?
发布于 2019-12-13 17:22:36
lengthunits()有正确的签名:返回一个Arbitrary实例和一个不带参数的方法。
尝试通过在Gen<T>上调用ToArbitrary()将其转换为Arbitrary<T>。
如果你想写缩略器,Arbitrary会变得很有用。任意=生成器+收缩器。
https://stackoverflow.com/questions/59311673
复制相似问题