我有一个矩阵结构和自定义比较方法:
static bool AlmostEquals(ref Matrix a, ref Matrix b);
static bool AlmostEquals(ref Matrix a, ref Matrix b, float epsilon);
对Fluent Assertion的正确调用是什么让这种比较起作用?
答案 0 :(得分:2)
AlmostEquals(ref a, ref b).Should().BeTrue("because matrices a and b are almost equal");
AlmostEquals(ref a, ref b, epsilon).Should().BeTrue("because matrices a and b are almost equal");
您甚至可以将有关矩阵和epsilon的一些信息添加到消息中,如
AlmostEquals(ref a, ref b, epsilon).Should().BeTrue("because matrices a and b are almost equal with {0} precision", epsilon);
可能你需要引入一个本地bool变量来使FluentAssertions工作(我没有安装它)并为它赋值 AlmostEquals 然后对boolean变量运行断言