【发布时间】:2021-01-01 02:11:21
【问题描述】:
说明
- 我正在迭代 2 个列表
- 我想比较列表中每个点的 2 个值
- 我希望该值在彼此的 0.1% 以内
完成重现问题的最小示例
var sheetRows = new List<float> { -24.0, 0.1, 10};
var loads= new List<float> { -24.0, 0.1, 10.05};
foreach ((var xl, var db) in sheetRows.Zip(loads, (n, w) => (n, w)))
{
xl.Should().BeApproximately(db, db*0.001f);
}
预期行为:
通过
实际行为:
Expected xl to approximate -24F +/- -0.024F, but -24F differed by 0F.
at FluentAssertions.Execution.LateBoundTestFramework.Throw(String message)
at FluentAssertions.Execution.TestFrameworkProvider.Throw(String message)
at FluentAssertions.Execution.DefaultAssertionStrategy.HandleFailure(String message)
at FluentAssertions.Execution.AssertionScope.FailWith(Func`1 failReasonFunc)
at FluentAssertions.Execution.AssertionScope.FailWith(Func`1 failReasonFunc)
at FluentAssertions.Execution.AssertionScope.FailWith(String message, Object[] args)
at FluentAssertions.NumericAssertionsExtensions.FailIfDifferenceOutsidePrecision[T](Boolean differenceWithinPrecision, NumericAssertions`1 parent, T expectedValue, T precision, T actualDifference, String because, Object[] becauseArgs)
at FluentAssertions.NumericAssertionsExtensions.BeApproximately(NumericAssertions`1 parent, Single expectedValue, Single precision, String because, Object[] becauseArgs)
at RoutingTests.UnitResponseModuleTests.U010_CheckTranslationAsync(Int64 sId, String sheetName, Int32 expected, Int32 excelRowCount) in C:\Users\sogscx\source\repos\Float\Compute\Test\RoutingTests\UnitResponseModuleTests.cs:line 480
at NUnit.Framework.Internal.TaskAwaitAdapter.GenericAdapter`1.BlockUntilCompleted()
版本
- 您使用的是哪个版本的 Fluent 断言?
最新的
- 您的目标是哪个 .NET 运行时和版本?例如。 .NET 框架 4.6.1 或 .NET Core 2.1。
.NET Core 3.1 运行 NUnit
【问题讨论】:
-
@DTul,我知道这行得通。我想要每个值的偏差。即浮点值只有 6 到 8 位,所以如果它是 10000 和另一个 0.001,那么每个 10% 是不同的!
标签: c# fluent-assertions