微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何将“ Be近似”与在循环的每次迭代中更改的值一起使用? 说明完成复制问题的最小示例预期的行为:实际行为:版本

如何解决如何将“ Be近似”与在循环的每次迭代中更改的值一起使用? 说明完成复制问题的最小示例预期的行为:实际行为:版本

说明

  • 我要遍历2个列表
  • 我想比较列表中每个点的2个值
  • 我希望该值在彼此的0.1%之内

完成复制问题的最小示例

var sheetRows = new List<float> { -24.0,0.1,10};
var loads= new List<float> { -24.0,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,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 Framework 4.6.1或.NET Core 2.1。

运行NUnit的.NET Core 3.1

解决方法

您传递的精度为负值。那很可能行不通。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。