|
3 | 3 | import org.junit.Test;
|
4 | 4 |
|
5 | 5 | import static org.junit.Assert.assertEquals;
|
6 |
| - |
| 6 | +import static org.junit.Assert.assertArrayEquals; |
7 | 7 | public class ColorTest {
|
8 | 8 |
|
9 |
| - private static int[][] colors = { |
| 9 | + private static final int[][] COLORS_ID_TO_RGB = { |
10 | 10 | {0, 0, 0},
|
11 | 11 | {0, 0, 0},
|
12 | 12 | {0, 0, 0},
|
@@ -265,14 +265,58 @@ public class ColorTest {
|
265 | 265 | {255, 255, 255}
|
266 | 266 | };
|
267 | 267 |
|
| 268 | + // Amount of colors expected per ID for all colors generated by |
| 269 | + // R=0..256, G=0..256, B=0..256 . If the Color::getBestIdFor is not |
| 270 | + // correctly implemented, this will probably mismatch. |
| 271 | + static final int[] COLORS_RGB_TO_ID_BUCKETS = { |
| 272 | + 1152, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 28608, 13184, |
| 273 | + 14592, 30464, 17408, 33344, 13056, 57344, 27200, 16512, 47808, |
| 274 | + 65152, 42176, 38080, 54784, 75584, 60352, 70016, 59200, 89792, |
| 275 | + 36992, 42880, 50944, 72320, 2688, 16960, 27968, 24000, 21952, |
| 276 | + 55104, 36992, 35392, 51712, 118016, 64320, 330624, 391424, 279040, |
| 277 | + 70912, 133056, 128000, 134144, 77376, 18368, 31104, 56960, 53184, |
| 278 | + 32000, 3584, 5312, 8448, 11712, 9728, 12416, 15168, 12608, 22720, |
| 279 | + 20736, 26240, 47040, 31168, 54080, 41536, 60288, 58496, 97792, |
| 280 | + 104896, 93312, 124352, 81152, 6976, 10048, 9920, 14592, 44224, |
| 281 | + 8640, 24256, 6016, 13696, 38592, 22592, 73408, 41728, 15360, |
| 282 | + 117696, 88704, 75776, 98752, 65216, 35840, 114304, 38912, 206464, |
| 283 | + 179008, 80640, 25984, 94464, 268160, 255552, 58048, 80448, 381376, |
| 284 | + 9856, 16576, 42304, 48640, 100736, 247808, 183040, 79616, 165120, |
| 285 | + 47296, 227712, 85312, 55424, 67136, 108864, 135808, 194304, 35328, |
| 286 | + 31680, 21632, 3072, 5120, 7040, 7936, 11392, 18048, 9984, 25536, |
| 287 | + 19328, 38208, 31104, 36992, 65728, 81408, 108800, 139456, 304512, |
| 288 | + 387648, 75264, 127360, 244608, 508160, 57344, 142464, 71936, |
| 289 | + 294848, 1439616, 181632, 392832, 230848, 1664, 3264, 2304, 7552, |
| 290 | + 24448, 38912, 128384, 281920, 53248, 84736, 42304, 65664, 42560, |
| 291 | + 3072, 12672, 31744, 26624, 80000, 308480, 243328, 305792, 218752, |
| 292 | + 220032, 253568, 11840, 31424, 45888, 62016, 82368, 70912, 100352, |
| 293 | + 130560, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 294 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 295 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 |
| 296 | + }; |
| 297 | + |
268 | 298 | @Test
|
269 |
| - public void checkAllColors() { |
| 299 | + public void checkAllColorsIdToRGB() { |
270 | 300 | for (int id=0; id < 256; id++) {
|
271 | 301 | Color c = new Color(id);
|
272 |
| - assertEquals(colors[id][0], c.red()); |
273 |
| - assertEquals(colors[id][1], c.green()); |
274 |
| - assertEquals(colors[id][2], c.blue()); |
| 302 | + assertEquals(COLORS_ID_TO_RGB[id][0], c.red()); |
| 303 | + assertEquals(COLORS_ID_TO_RGB[id][1], c.green()); |
| 304 | + assertEquals(COLORS_ID_TO_RGB[id][2], c.blue()); |
| 305 | + } |
| 306 | + } |
| 307 | + |
| 308 | + @Test |
| 309 | + public void checkAllColorsRGBToId() { |
| 310 | + final int[] buckets = new int[256]; |
| 311 | + for (int r=0; r < 256; r++) { |
| 312 | + for (int g=0; g < 256; g++) { |
| 313 | + for (int b=0; b < 256; b++) { |
| 314 | + Color c = new Color(r, g, b); |
| 315 | + buckets[c.id] += 1; |
| 316 | + } |
| 317 | + } |
275 | 318 | }
|
| 319 | + assertArrayEquals(COLORS_RGB_TO_ID_BUCKETS, buckets); |
276 | 320 | }
|
277 | 321 |
|
278 | 322 | @Test
|
|
0 commit comments