js/src/tests/ecma_6/Math/20.2.2.ToNumber.js

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:b240f66a3dc6
1 /*
2 * Any copyright is dedicated to the Public Domain.
3 * http://creativecommons.org/licenses/publicdomain/
4 */
5
6 /*
7 * ECMA-262 6th Edition / Draft November 8, 2013
8 *
9 * 20.2.2 Function Properties of the Math Object
10 */
11
12 /*
13 * This custom object will allow us to check if valueOf() is called
14 */
15
16 TestNumber.prototype = new Number();
17
18 function TestNumber(value) {
19 this.value = value;
20 this.valueOfCalled = false;
21 }
22
23 TestNumber.prototype = {
24 valueOf: function() {
25 this.valueOfCalled = true;
26 return this.value;
27 }
28 }
29
30 // Verify that each TestNumber's flag is set after calling Math func
31 function test(func /*, args */) {
32 var args = Array.prototype.slice.call(arguments, 1);
33 func.apply(null, args);
34
35 for (var i = 0; i < args.length; ++i)
36 assertEq(args[i].valueOfCalled, true);
37 }
38
39 // Note that we are not testing these functions' return values
40 // We only test whether valueOf() is called for each argument
41
42 // 1. Test Math.atan2()
43 var x = new TestNumber(1);
44 test(Math.atan2, x);
45
46 var x = new TestNumber(1);
47 var y = new TestNumber(2);
48 test(Math.atan2, y, x);
49
50 // Remove comment block once patch for bug 896264 is approved
51 /*
52 // 2. Test Math.hypot()
53 var x = new TestNumber(1);
54 test(Math.hypot, x);
55
56 var x = new TestNumber(1);
57 var y = new TestNumber(2);
58 test(Math.hypot, x, y);
59
60 var x = new TestNumber(1);
61 var y = new TestNumber(2);
62 var z = new TestNumber(3);
63 test(Math.hypot, x, y, z);
64 */
65
66 // Remove comment block once patch for bug 808148 is approved
67 /*
68 // 3. Test Math.imul()
69 var x = new TestNumber(1);
70 test(Math.imul, x);
71
72 var x = new TestNumber(1);
73 var y = new TestNumber(2);
74 test(Math.imul, x, y);
75 */
76
77 // 4. Test Math.max()
78 var x = new TestNumber(1);
79 test(Math.max, x);
80
81 var x = new TestNumber(1);
82 var y = new TestNumber(2);
83 test(Math.max, x, y);
84
85 var x = new TestNumber(1);
86 var y = new TestNumber(2);
87 var z = new TestNumber(3);
88 test(Math.max, x, y, z);
89
90 // 5. Test Math.min()
91 var x = new TestNumber(1);
92 test(Math.min, x);
93
94 var x = new TestNumber(1);
95 var y = new TestNumber(2);
96 test(Math.min, x, y);
97
98 var x = new TestNumber(1);
99 var y = new TestNumber(2);
100 var z = new TestNumber(3);
101 test(Math.min, x, y, z);
102
103 // 6. Test Math.pow()
104 var x = new TestNumber(1);
105 test(Math.pow, x);
106
107 var x = new TestNumber(1);
108 var y = new TestNumber(2);
109 test(Math.pow, x, y);
110
111 reportCompare(0, 0, "ok");
112

mercurial