michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: "use strict"; michael@0: michael@0: function test() { michael@0: ok(isApprox(TiltMath.radians(30), 0.523598775), michael@0: "The radians() function didn't calculate the value correctly."); michael@0: michael@0: ok(isApprox(TiltMath.degrees(0.5), 28.64788975), michael@0: "The degrees() function didn't calculate the value correctly."); michael@0: michael@0: ok(isApprox(TiltMath.map(0.5, 0, 1, 0, 100), 50), michael@0: "The map() function didn't calculate the value correctly."); michael@0: michael@0: is(TiltMath.isPowerOfTwo(32), true, michael@0: "The isPowerOfTwo() function didn't return the expected value."); michael@0: michael@0: is(TiltMath.isPowerOfTwo(33), false, michael@0: "The isPowerOfTwo() function didn't return the expected value."); michael@0: michael@0: ok(isApprox(TiltMath.nextPowerOfTwo(31), 32), michael@0: "The nextPowerOfTwo() function didn't calculate the 1st value correctly."); michael@0: michael@0: ok(isApprox(TiltMath.nextPowerOfTwo(32), 32), michael@0: "The nextPowerOfTwo() function didn't calculate the 2nd value correctly."); michael@0: michael@0: ok(isApprox(TiltMath.nextPowerOfTwo(33), 64), michael@0: "The nextPowerOfTwo() function didn't calculate the 3rd value correctly."); michael@0: michael@0: ok(isApprox(TiltMath.clamp(5, 1, 3), 3), michael@0: "The clamp() function didn't calculate the 1st value correctly."); michael@0: michael@0: ok(isApprox(TiltMath.clamp(5, 3, 1), 3), michael@0: "The clamp() function didn't calculate the 2nd value correctly."); michael@0: michael@0: ok(isApprox(TiltMath.saturate(5), 1), michael@0: "The saturate() function didn't calculate the 1st value correctly."); michael@0: michael@0: ok(isApprox(TiltMath.saturate(-5), 0), michael@0: "The saturate() function didn't calculate the 2nd value correctly."); michael@0: michael@0: ok(isApproxVec(TiltMath.hex2rgba("#f00"), [1, 0, 0, 1]), michael@0: "The hex2rgba() function didn't calculate the 1st rgba values correctly."); michael@0: michael@0: ok(isApproxVec(TiltMath.hex2rgba("#f008"), [1, 0, 0, 0.53]), michael@0: "The hex2rgba() function didn't calculate the 2nd rgba values correctly."); michael@0: michael@0: ok(isApproxVec(TiltMath.hex2rgba("#ff0000"), [1, 0, 0, 1]), michael@0: "The hex2rgba() function didn't calculate the 3rd rgba values correctly."); michael@0: michael@0: ok(isApproxVec(TiltMath.hex2rgba("#ff0000aa"), [1, 0, 0, 0.66]), michael@0: "The hex2rgba() function didn't calculate the 4th rgba values correctly."); michael@0: michael@0: ok(isApproxVec(TiltMath.hex2rgba("rgba(255, 0, 0, 0.5)"), [1, 0, 0, 0.5]), michael@0: "The hex2rgba() function didn't calculate the 5th rgba values correctly."); michael@0: michael@0: ok(isApproxVec(TiltMath.hex2rgba("rgb(255, 0, 0)"), [1, 0, 0, 1]), michael@0: "The hex2rgba() function didn't calculate the 6th rgba values correctly."); michael@0: }