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