|
1 | 1 | suite('p5.ColorConversion', function() { |
2 | 2 | var rgba = [1, 0, 0.4, 0.8]; |
3 | 3 | var hsla = [336/360, 1, 0.5, 0.8]; |
| 4 | + var hslaWithMaxHue = [1, 1, 0.5, 0.6]; |
4 | 5 | var hsba = [336/360, 1, 1, 0.8]; |
5 | | - var one; |
| 6 | + var hsbaWithMaxHue = [1, 1, 1, 0.6]; |
| 7 | + var result; |
6 | 8 |
|
7 | 9 | suite('rgbaToHSBA', function() { |
8 | 10 | test('rgba converts to hsba', function() { |
9 | | - one = p5.ColorConversion._rgbaToHSBA(rgba); |
| 11 | + result = p5.ColorConversion._rgbaToHSBA(rgba); |
10 | 12 | assert.deepEqual([ |
11 | | - Math.round(one[0] * 360), |
12 | | - Math.round(one[1] * 100), |
13 | | - Math.round(one[2] * 100), |
14 | | - one[3] |
| 13 | + Math.round(result[0] * 360), |
| 14 | + Math.round(result[1] * 100), |
| 15 | + Math.round(result[2] * 100), |
| 16 | + result[3] |
15 | 17 | ], [336, 100, 100, 0.8]); |
16 | 18 | }); |
17 | 19 | }); |
18 | 20 |
|
19 | 21 | suite('hsbaToRGBA', function() { |
20 | 22 | test('hsba converts to rgba', function() { |
21 | | - one = p5.ColorConversion._hsbaToRGBA(hsba); |
| 23 | + result = p5.ColorConversion._hsbaToRGBA(hsba); |
22 | 24 | assert.deepEqual([ |
23 | | - Math.round(one[0] * 255), |
24 | | - Math.round(one[1] * 255), |
25 | | - Math.round(one[2] * 255), |
26 | | - Math.round(one[3] * 255) |
| 25 | + Math.round(result[0] * 255), |
| 26 | + Math.round(result[1] * 255), |
| 27 | + Math.round(result[2] * 255), |
| 28 | + Math.round(result[3] * 255) |
27 | 29 | ], [255, 0, 102, 204]); |
28 | 30 | }); |
| 31 | + |
| 32 | + test('handles maximum hue value', function() { |
| 33 | + result = p5.ColorConversion._hsbaToRGBA(hsbaWithMaxHue); |
| 34 | + assert.deepEqual([ |
| 35 | + Math.round(result[0] * 255), |
| 36 | + Math.round(result[1] * 255), |
| 37 | + Math.round(result[2] * 255), |
| 38 | + Math.round(result[3] * 255) |
| 39 | + ], [255, 0, 0, 153]); |
| 40 | + }); |
29 | 41 | }); |
30 | 42 |
|
31 | 43 | suite('hslaToRGBA', function() { |
32 | 44 | test('hsla converts to rgba', function() { |
33 | | - one = p5.ColorConversion._hslaToRGBA(hsla); |
| 45 | + result = p5.ColorConversion._hslaToRGBA(hsla); |
34 | 46 | assert.deepEqual([ |
35 | | - Math.round(one[0] * 255), |
36 | | - Math.round(one[1] * 255), |
37 | | - Math.round(one[2] * 255), |
38 | | - Math.round(one[3] * 255) |
| 47 | + Math.round(result[0] * 255), |
| 48 | + Math.round(result[1] * 255), |
| 49 | + Math.round(result[2] * 255), |
| 50 | + Math.round(result[3] * 255) |
39 | 51 | ], [255, 0, 102, 204]); |
40 | 52 | }); |
| 53 | + |
| 54 | + test('handles maximum hue value', function() { |
| 55 | + result = p5.ColorConversion._hslaToRGBA(hslaWithMaxHue); |
| 56 | + assert.deepEqual([ |
| 57 | + Math.round(result[0] * 255), |
| 58 | + Math.round(result[1] * 255), |
| 59 | + Math.round(result[2] * 255), |
| 60 | + Math.round(result[3] * 255) |
| 61 | + ], [255, 0, 0, 153]); |
| 62 | + }); |
41 | 63 | }); |
42 | 64 |
|
43 | 65 | suite('rgbaToHSLA', function() { |
44 | 66 | test('rgba converts to hsla', function() { |
45 | | - one = p5.ColorConversion._rgbaToHSLA(rgba); |
| 67 | + result = p5.ColorConversion._rgbaToHSLA(rgba); |
46 | 68 | assert.deepEqual([ |
47 | | - Math.round(one[0] * 360), |
48 | | - Math.round(one[1] * 100), |
49 | | - Math.round(one[2] * 100), |
50 | | - one[3] |
| 69 | + Math.round(result[0] * 360), |
| 70 | + Math.round(result[1] * 100), |
| 71 | + Math.round(result[2] * 100), |
| 72 | + result[3] |
51 | 73 | ], [336, 100, 50, 0.8]); |
52 | 74 | }); |
53 | 75 | }); |
54 | 76 |
|
55 | 77 | suite('hslaToHSBA', function() { |
56 | 78 | test('hsla converts to hsba', function() { |
57 | | - one = p5.ColorConversion._hslaToHSBA(hsla); |
| 79 | + result = p5.ColorConversion._hslaToHSBA(hsla); |
58 | 80 | assert.deepEqual([ |
59 | | - Math.round(one[0] * 360), |
60 | | - Math.round(one[1] * 100), |
61 | | - Math.round(one[2] * 100), |
62 | | - one[3] |
| 81 | + Math.round(result[0] * 360), |
| 82 | + Math.round(result[1] * 100), |
| 83 | + Math.round(result[2] * 100), |
| 84 | + result[3] |
63 | 85 | ], [336, 100, 100, 0.8]); |
64 | 86 | }); |
65 | 87 | }); |
66 | 88 |
|
67 | 89 | suite('hsbaToHSLA', function() { |
68 | 90 | test('hsba converts to hsla', function() { |
69 | | - one = p5.ColorConversion._hsbaToHSLA(hsba); |
| 91 | + result = p5.ColorConversion._hsbaToHSLA(hsba); |
70 | 92 | assert.deepEqual([ |
71 | | - Math.round(one[0] * 360), |
72 | | - Math.round(one[1] * 100), |
73 | | - Math.round(one[2] * 100), |
74 | | - one[3] |
| 93 | + Math.round(result[0] * 360), |
| 94 | + Math.round(result[1] * 100), |
| 95 | + Math.round(result[2] * 100), |
| 96 | + result[3] |
75 | 97 | ], [336, 100, 50, 0.8]); |
76 | 98 | }); |
77 | 99 | }); |
|
0 commit comments