gpt4 book ai didi

c# - 流利的断言 : Compare two numeric collections approximately

转载 作者:太空狗 更新时间:2023-10-29 22:32:52 24 4
gpt4 key购买 nike

我有两个 double 组。有没有一种方法可以使用 FluentAssertions 通过 .BeApproximately() 技术逐个元素地比较数组?

一个范围值对于整个数组就足够了。

例子:

double[] source = { 10.01, 8.01, 6.01 };
double[] target = { 10.0, 8.0, 6.0 };

// THE FOLLOWING IS NOT IMPLEMENTED
target.Should().BeApproximately(source, 0.01);

是否有替代方法?

最佳答案

通用集合断言有一个重载,它采用一个 Func,您可以在比较期间使用它来应用任何谓词。有了它,您可以执行以下操作:

source.Should().Equal(target, (left, right) => AreEqualApproximately(left, right, 0.01));

您唯一需要做的就是自己创建该方法。

关于c# - 流利的断言 : Compare two numeric collections approximately,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17054636/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com