browser/devtools/tilt/test/browser_tilt_math01.js

Thu, 15 Jan 2015 15:55:04 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:55:04 +0100
branch
TOR_BUG_9701
changeset 9
a63d609f5ebe
permissions
-rw-r--r--

Back out 97036ab72558 which inappropriately compared turds to third parties.

     1 /* Any copyright is dedicated to the Public Domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     3 "use strict";
     5 function test() {
     6   ok(isApprox(TiltMath.radians(30), 0.523598775),
     7     "The radians() function didn't calculate the value correctly.");
     9   ok(isApprox(TiltMath.degrees(0.5), 28.64788975),
    10     "The degrees() function didn't calculate the value correctly.");
    12   ok(isApprox(TiltMath.map(0.5, 0, 1, 0, 100), 50),
    13     "The map() function didn't calculate the value correctly.");
    15   is(TiltMath.isPowerOfTwo(32), true,
    16     "The isPowerOfTwo() function didn't return the expected value.");
    18   is(TiltMath.isPowerOfTwo(33), false,
    19     "The isPowerOfTwo() function didn't return the expected value.");
    21   ok(isApprox(TiltMath.nextPowerOfTwo(31), 32),
    22     "The nextPowerOfTwo() function didn't calculate the 1st value correctly.");
    24   ok(isApprox(TiltMath.nextPowerOfTwo(32), 32),
    25     "The nextPowerOfTwo() function didn't calculate the 2nd value correctly.");
    27   ok(isApprox(TiltMath.nextPowerOfTwo(33), 64),
    28     "The nextPowerOfTwo() function didn't calculate the 3rd value correctly.");
    30   ok(isApprox(TiltMath.clamp(5, 1, 3), 3),
    31     "The clamp() function didn't calculate the 1st value correctly.");
    33   ok(isApprox(TiltMath.clamp(5, 3, 1), 3),
    34     "The clamp() function didn't calculate the 2nd value correctly.");
    36   ok(isApprox(TiltMath.saturate(5), 1),
    37     "The saturate() function didn't calculate the 1st value correctly.");
    39   ok(isApprox(TiltMath.saturate(-5), 0),
    40     "The saturate() function didn't calculate the 2nd value correctly.");
    42   ok(isApproxVec(TiltMath.hex2rgba("#f00"), [1, 0, 0, 1]),
    43     "The hex2rgba() function didn't calculate the 1st rgba values correctly.");
    45   ok(isApproxVec(TiltMath.hex2rgba("#f008"), [1, 0, 0, 0.53]),
    46     "The hex2rgba() function didn't calculate the 2nd rgba values correctly.");
    48   ok(isApproxVec(TiltMath.hex2rgba("#ff0000"), [1, 0, 0, 1]),
    49     "The hex2rgba() function didn't calculate the 3rd rgba values correctly.");
    51   ok(isApproxVec(TiltMath.hex2rgba("#ff0000aa"), [1, 0, 0, 0.66]),
    52     "The hex2rgba() function didn't calculate the 4th rgba values correctly.");
    54   ok(isApproxVec(TiltMath.hex2rgba("rgba(255, 0, 0, 0.5)"), [1, 0, 0, 0.5]),
    55     "The hex2rgba() function didn't calculate the 5th rgba values correctly.");
    57   ok(isApproxVec(TiltMath.hex2rgba("rgb(255, 0, 0)"), [1, 0, 0, 1]),
    58     "The hex2rgba() function didn't calculate the 6th rgba values correctly.");
    59 }

mercurial