1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/tilt/test/browser_tilt_math01.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,59 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 +"use strict"; 1.7 + 1.8 +function test() { 1.9 + ok(isApprox(TiltMath.radians(30), 0.523598775), 1.10 + "The radians() function didn't calculate the value correctly."); 1.11 + 1.12 + ok(isApprox(TiltMath.degrees(0.5), 28.64788975), 1.13 + "The degrees() function didn't calculate the value correctly."); 1.14 + 1.15 + ok(isApprox(TiltMath.map(0.5, 0, 1, 0, 100), 50), 1.16 + "The map() function didn't calculate the value correctly."); 1.17 + 1.18 + is(TiltMath.isPowerOfTwo(32), true, 1.19 + "The isPowerOfTwo() function didn't return the expected value."); 1.20 + 1.21 + is(TiltMath.isPowerOfTwo(33), false, 1.22 + "The isPowerOfTwo() function didn't return the expected value."); 1.23 + 1.24 + ok(isApprox(TiltMath.nextPowerOfTwo(31), 32), 1.25 + "The nextPowerOfTwo() function didn't calculate the 1st value correctly."); 1.26 + 1.27 + ok(isApprox(TiltMath.nextPowerOfTwo(32), 32), 1.28 + "The nextPowerOfTwo() function didn't calculate the 2nd value correctly."); 1.29 + 1.30 + ok(isApprox(TiltMath.nextPowerOfTwo(33), 64), 1.31 + "The nextPowerOfTwo() function didn't calculate the 3rd value correctly."); 1.32 + 1.33 + ok(isApprox(TiltMath.clamp(5, 1, 3), 3), 1.34 + "The clamp() function didn't calculate the 1st value correctly."); 1.35 + 1.36 + ok(isApprox(TiltMath.clamp(5, 3, 1), 3), 1.37 + "The clamp() function didn't calculate the 2nd value correctly."); 1.38 + 1.39 + ok(isApprox(TiltMath.saturate(5), 1), 1.40 + "The saturate() function didn't calculate the 1st value correctly."); 1.41 + 1.42 + ok(isApprox(TiltMath.saturate(-5), 0), 1.43 + "The saturate() function didn't calculate the 2nd value correctly."); 1.44 + 1.45 + ok(isApproxVec(TiltMath.hex2rgba("#f00"), [1, 0, 0, 1]), 1.46 + "The hex2rgba() function didn't calculate the 1st rgba values correctly."); 1.47 + 1.48 + ok(isApproxVec(TiltMath.hex2rgba("#f008"), [1, 0, 0, 0.53]), 1.49 + "The hex2rgba() function didn't calculate the 2nd rgba values correctly."); 1.50 + 1.51 + ok(isApproxVec(TiltMath.hex2rgba("#ff0000"), [1, 0, 0, 1]), 1.52 + "The hex2rgba() function didn't calculate the 3rd rgba values correctly."); 1.53 + 1.54 + ok(isApproxVec(TiltMath.hex2rgba("#ff0000aa"), [1, 0, 0, 0.66]), 1.55 + "The hex2rgba() function didn't calculate the 4th rgba values correctly."); 1.56 + 1.57 + ok(isApproxVec(TiltMath.hex2rgba("rgba(255, 0, 0, 0.5)"), [1, 0, 0, 0.5]), 1.58 + "The hex2rgba() function didn't calculate the 5th rgba values correctly."); 1.59 + 1.60 + ok(isApproxVec(TiltMath.hex2rgba("rgb(255, 0, 0)"), [1, 0, 0, 1]), 1.61 + "The hex2rgba() function didn't calculate the 6th rgba values correctly."); 1.62 +}