caolan / caolan/nodeunit

approx and deepApprox to safely compare numbers

未关闭
#218 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
JavaScript
星标
1.9k
派生
359
PR 合并指标
30 天内没有已合并 PR

描述

Testing equallity of numbers is a tricky business because of possible round of errors in floating point numbers. For example the following test will unexpectedly fail as the result of the left expression is `0.22000000000000003` and not `0.22`.

``` js
test.equal(2.2 / 10, 0.22);
```

It would be great to have functions like `approx` and `deepApprox` to safely compare numbers and objects/arrays containing numbers against each other. The function should compare whether the difference between the two numbers is at least a predefined factor epsilon smaller than the values itself (I guess there will be some edge cases when one of the values is zero, NaN, or Inf).

贡献指南

这个仓库没有索引到贡献指南

调研方向

首先查看 nodeunit 现有的基于 assert 的比较 API。定义 approx 和 deepApprox 应如何比较数字、对象和数组,包括所述的 epsilon 行为,以及 zero、NaN 和 Infinity 的边界情况。当这些函数及其预期比较行为都已完成规范定义并由测试覆盖时,即视为完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript
领域
testing-qa
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
停滞
描述清晰度
基本清楚
新手友好度
25/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。