gpt4 book ai didi

c# - NUnit 检查数组的所有值(具有公差)

转载 作者:可可西里 更新时间:2023-11-01 08:19:48 24 4
gpt4 key购买 nike

在 NUnit 中,我可以执行以下操作:

Assert.That(1.05,Is.EqualTo(1.0).Within(0.1));

我也能做到:

Assert.That(new[]{1.0,2.0,3.0},Is.EquivalentTo(new[]{3.0,2.0,1.0}));

现在我想按照这些思路做点什么

Assert.That(new[]{1.05,2.05,3.05},
Is.EquivalentTo(new[]{3.0,2.0,1.0}).Within(0.1));

除了 Within 关键字在那种情况下不受支持。是否有解决方法或其他方法可以轻松做到这一点?

最佳答案

您可以设置 float 的默认容差:

GlobalSettings.DefaultFloatingPointTolerance = 0.1;
Assert.That(new[] {1.05, 2.05, 3.05}, Is.EquivalentTo(new[] {3.0, 2.0, 1.0}));

关于c# - NUnit 检查数组的所有值(具有公差),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6707801/

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