source: Dev/branches/rest-dojo-ui/client/dojox/math/tests/math.js @ 256

Last change on this file since 256 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

File size: 1.5 KB
Line 
1dojo.provide("dojox.math.tests.math");
2
3dojo.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                // standard integer values
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                // almost integer
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                // geometric values
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                // invalid values
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})();
Note: See TracBrowser for help on using the repository browser.