fix: use rounding to fix floating point comparison

This commit is contained in:
Oliver Eyton-Williams
2019-07-19 20:17:30 +02:00
committed by mrugesh
parent ae7b2c2034
commit 55b5d22d68

View File

@ -26,15 +26,15 @@ tests:
- text: <code>gamma(.1)</code> should return a number.
testString: assert(typeof gamma(.1)=='number','<code>gamma(.1)</code> should return a number.')
- text: <code>gamma(.1)</code> should return <code>9.513507698668736</code>.
testString: assert.equal(gamma(.1), 9.513507698668736,'<code>gamma(.1)</code> should return <code>9.513507698668736</code>.')
testString: assert.equal(round(gamma(.1)), round(9.513507698668736),'<code>gamma(.1)</code> should return <code>9.513507698668736</code>.')
- text: <code>gamma(.2)</code> should return <code>4.590843711998803</code>.
testString: assert.equal(gamma(.2), 4.590843711998803,'<code>gamma(.2)</code> should return <code>4.590843711998803</code>.')
testString: assert.equal(round(gamma(.2)), round(4.590843711998803),'<code>gamma(.2)</code> should return <code>4.590843711998803</code>.')
- text: <code>gamma(.3)</code> should return <code>2.9915689876875904</code>.
testString: assert.equal(gamma(.3), 2.9915689876875904,'<code>gamma(.3)</code> should return <code>2.9915689876875904</code>.')
testString: assert.equal(round(gamma(.3)), round(2.9915689876875904),'<code>gamma(.3)</code> should return <code>2.9915689876875904</code>.')
- text: <code>gamma(.4)</code> should return <code>2.218159543757687</code>.
testString: assert.equal(gamma(.4), 2.218159543757687,'<code>gamma(.4)</code> should return <code>2.218159543757687</code>.')
testString: assert.equal(round(gamma(.4)), round(2.218159543757687),'<code>gamma(.4)</code> should return <code>2.218159543757687</code>.')
- text: <code>gamma(.5)</code> should return <code>1.7724538509055159</code>.
testString: assert.equal(gamma(.5), 1.7724538509055159,'<code>gamma(.5)</code> should return <code>1.7724538509055159</code>.')
testString: assert.equal(round(gamma(.5)), round(1.7724538509055159),'<code>gamma(.5)</code> should return <code>1.7724538509055159</code>.')
```
@ -53,6 +53,17 @@ function gamma(x) {
</div>
### After Test
<div id='js-teardown'>
```js
function round(x) {
return Number(x).toPrecision(13);
}
```
</div>
</section>
## Solution