c# - 配置流利的断言精度以比较小数

标签 c# fluent-assertions

我正在使用 fluent-assertions 和存储严重小数类型的 sqlite 编写单元测试。

我希望ALL 我的十进制比较忽略 float 部分。

有办法吗?

谢谢!

最佳答案

FluentAssertions 允许对十进制/ float 值进行近似断言。

The following method is specifically designed for floating point or decimal variables.

float value = 3.1415927F;
value.Should().BeApproximately(3.14F, 0.01F);

This will verify that the value of the float is between 3.139 and 3.141.

引用FluentAssertions Documentation: Numeric types and everything else that implements IComparable<T>

关于c# - 配置流利的断言精度以比较小数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57384306/

相关文章:

c# - DateTimeStyles.RoundtripKind 枚举是什么意思?

c# - 使用 ShouldBeEquivalentTo 并处理不同的名称

c# - FluentAssertions : ShouldBeEquivalentTo vs Should(). Be() vs Should().BeEquivalentTo()?

c# - 流利的断言 Should().Should().BeEquivalentTo 忽略被排除的成员

c# - 在运行时以编程方式重写映射规则

c# - 在 View 中显示字典值

c# - 一种使 Asp.net 网页更像 Rails MVC 的方法?

c# - 转换动态 Dapper 查询

c# - 使用 `ShouldBeEquivalentTo` 、 `ShouldAllBeEquivalentTo` 和 `BeEquivalentTo`

c# - 如何使用 FluentAssertions 断言属性的默认值?