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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/ecma_6/Math/20.2.2.ToNumber.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,112 @@
     1.4 +/*
     1.5 + * Any copyright is dedicated to the Public Domain.
     1.6 + * http://creativecommons.org/licenses/publicdomain/
     1.7 + */
     1.8 +
     1.9 +/*
    1.10 + *   ECMA-262 6th Edition / Draft November 8, 2013
    1.11 + *
    1.12 + *   20.2.2 Function Properties of the Math Object
    1.13 + */
    1.14 +
    1.15 +/*
    1.16 + * This custom object will allow us to check if valueOf() is called
    1.17 + */
    1.18 +
    1.19 +TestNumber.prototype = new Number();
    1.20 +
    1.21 +function TestNumber(value) {
    1.22 +    this.value = value;
    1.23 +    this.valueOfCalled = false;
    1.24 +}
    1.25 +
    1.26 +TestNumber.prototype = {
    1.27 +    valueOf: function() {
    1.28 +        this.valueOfCalled = true;
    1.29 +        return this.value;
    1.30 +    }
    1.31 +}
    1.32 +
    1.33 +// Verify that each TestNumber's flag is set after calling Math func
    1.34 +function test(func /*, args */) {
    1.35 +    var args = Array.prototype.slice.call(arguments, 1);
    1.36 +    func.apply(null, args);
    1.37 +
    1.38 +    for (var i = 0; i < args.length; ++i)
    1.39 +        assertEq(args[i].valueOfCalled, true);
    1.40 +}
    1.41 +
    1.42 +// Note that we are not testing these functions' return values
    1.43 +// We only test whether valueOf() is called for each argument
    1.44 +
    1.45 +// 1. Test Math.atan2()
    1.46 +var x = new TestNumber(1);
    1.47 +test(Math.atan2, x);
    1.48 +
    1.49 +var x = new TestNumber(1);
    1.50 +var y = new TestNumber(2);
    1.51 +test(Math.atan2, y, x);
    1.52 +
    1.53 +// Remove comment block once patch for bug 896264 is approved
    1.54 +/*
    1.55 +// 2. Test Math.hypot()
    1.56 +var x = new TestNumber(1);
    1.57 +test(Math.hypot, x);
    1.58 +
    1.59 +var x = new TestNumber(1);
    1.60 +var y = new TestNumber(2);
    1.61 +test(Math.hypot, x, y);
    1.62 +
    1.63 +var x = new TestNumber(1);
    1.64 +var y = new TestNumber(2);
    1.65 +var z = new TestNumber(3);
    1.66 +test(Math.hypot, x, y, z);
    1.67 +*/
    1.68 +
    1.69 +// Remove comment block once patch for bug 808148 is approved
    1.70 +/*
    1.71 +// 3. Test Math.imul()
    1.72 +var x = new TestNumber(1);
    1.73 +test(Math.imul, x);
    1.74 +
    1.75 +var x = new TestNumber(1);
    1.76 +var y = new TestNumber(2);
    1.77 +test(Math.imul, x, y);
    1.78 +*/
    1.79 +
    1.80 +// 4. Test Math.max()
    1.81 +var x = new TestNumber(1);
    1.82 +test(Math.max, x);
    1.83 +
    1.84 +var x = new TestNumber(1);
    1.85 +var y = new TestNumber(2);
    1.86 +test(Math.max, x, y);
    1.87 +
    1.88 +var x = new TestNumber(1);
    1.89 +var y = new TestNumber(2);
    1.90 +var z = new TestNumber(3);
    1.91 +test(Math.max, x, y, z);
    1.92 +
    1.93 +// 5. Test Math.min()
    1.94 +var x = new TestNumber(1);
    1.95 +test(Math.min, x);
    1.96 +
    1.97 +var x = new TestNumber(1);
    1.98 +var y = new TestNumber(2);
    1.99 +test(Math.min, x, y);
   1.100 +
   1.101 +var x = new TestNumber(1);
   1.102 +var y = new TestNumber(2);
   1.103 +var z = new TestNumber(3);
   1.104 +test(Math.min, x, y, z);
   1.105 +
   1.106 +// 6. Test Math.pow()
   1.107 +var x = new TestNumber(1);
   1.108 +test(Math.pow, x);
   1.109 +
   1.110 +var x = new TestNumber(1);
   1.111 +var y = new TestNumber(2);
   1.112 +test(Math.pow, x, y);
   1.113 +
   1.114 +reportCompare(0, 0, "ok");
   1.115 +

mercurial