| 1 |
dojo.provide("dojox.math.tests.math"); |
| 2 |
|
| 3 |
dojo.require("dojox.math"); |
| 4 |
|
| 5 |
(function(){ |
| 6 |
function approx(r){ |
| 7 |
return Math.floor(r * (1 << 30)) / (1 << 30); |
| 8 |
} |
| 9 |
tests.register("dojox.math.tests.factorial", [ |
| 10 |
|
| 11 |
function fact0(t){ t.assertEqual(1, dojox.math.factorial(0)); }, |
| 12 |
function fact1(t){ t.assertEqual(1, dojox.math.factorial(1)); }, |
| 13 |
function fact2(t){ t.assertEqual(2, dojox.math.factorial(2)); }, |
| 14 |
function fact5(t){ t.assertEqual(120, dojox.math.factorial(5)); }, |
| 15 |
|
| 16 |
function fact5minus(t){ t.assertEqual(approx(119.999804750496600), approx(dojox.math.factorial(5-1/1048576))); }, |
| 17 |
function fact5plus(t){ t.assertEqual(approx(120.000195249840876), approx(dojox.math.factorial(5+1/1048576))); }, |
| 18 |
|
| 19 |
function factNeg1half(t){ t.assertEqual(Math.sqrt(Math.PI), dojox.math.factorial(-0.5)); }, |
| 20 |
function factPos1half(t){ t.assertEqual(approx(Math.sqrt(Math.PI)/2), approx(dojox.math.factorial(0.5))); }, |
| 21 |
function factNeg3halves(t){ t.assertEqual(approx(-Math.sqrt(Math.PI)*2), approx(dojox.math.factorial(-1.5))); }, |
| 22 |
function factNeg5halves(t){ t.assertEqual(approx(Math.sqrt(Math.PI)*4/3), approx(dojox.math.factorial(-2.5))); }, |
| 23 |
function factPos5halves(t){ t.assertEqual(approx(Math.sqrt(Math.PI)*15/8), approx(dojox.math.factorial(2.5))); }, |
| 24 |
|
| 25 |
function factNeg1(t){ t.assertEqual(NaN, dojox.math.factorial(-1)); }, |
| 26 |
function factNeg2(t){ t.assertEqual(NaN, dojox.math.factorial(-2)); } |
| 27 |
]); |
| 28 |
|
| 29 |
})(); |