package bwapi; import org.junit.Test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertArrayEquals; public class ColorTest { private static final int[][] COLORS_ID_TO_RGB = { {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {24, 36, 44}, {72, 36, 20}, {92, 44, 20}, {112, 48, 20}, {104, 60, 36}, {124, 64, 24}, {120, 76, 44}, {168, 8, 8}, {140, 84, 48}, {132, 96, 68}, {160, 84, 28}, {196, 76, 24}, {188, 104, 36}, {180, 112, 60}, {208, 100, 32}, {220, 148, 52}, {224, 148, 84}, {236, 196, 84}, {52, 68, 40}, {64, 108, 60}, {72, 108, 80}, {76, 128, 80}, {80, 140, 92}, {92, 160, 120}, {0, 0, 24}, {0, 16, 52}, {0, 8, 80}, {36, 52, 72}, {48, 64, 84}, {20, 52, 124}, {52, 76, 108}, {64, 88, 116}, {72, 104, 140}, {0, 112, 156}, {88, 128, 164}, {64, 104, 212}, {24, 172, 184}, {36, 36, 252}, {100, 148, 188}, {112, 168, 204}, {140, 192, 216}, {148, 220, 244}, {172, 220, 232}, {172, 252, 252}, {204, 248, 248}, {252, 252, 0}, {244, 228, 144}, {252, 252, 192}, {12, 12, 12}, {24, 20, 16}, {28, 28, 32}, {40, 40, 48}, {56, 48, 36}, {56, 60, 68}, {76, 64, 48}, {76, 76, 76}, {92, 80, 64}, {88, 88, 88}, {104, 104, 104}, {120, 132, 108}, {104, 148, 108}, {116, 164, 124}, {152, 148, 140}, {144, 184, 148}, {152, 196, 168}, {176, 176, 176}, {172, 204, 176}, {196, 192, 188}, {204, 224, 208}, {240, 240, 240}, {28, 16, 8}, {40, 24, 12}, {52, 16, 8}, {52, 32, 12}, {56, 16, 32}, {52, 40, 32}, {68, 52, 8}, {72, 48, 24}, {96, 0, 0}, {84, 40, 32}, {80, 64, 20}, {92, 84, 20}, {132, 4, 4}, {104, 76, 52}, {124, 56, 48}, {112, 100, 32}, {124, 80, 80}, {164, 52, 28}, {148, 108, 0}, {152, 92, 64}, {140, 128, 52}, {152, 116, 84}, {184, 84, 68}, {176, 144, 24}, {176, 116, 92}, {244, 4, 4}, {200, 120, 84}, {252, 104, 84}, {224, 164, 132}, {252, 148, 104}, {252, 204, 44}, {16, 252, 24}, {12, 0, 32}, {28, 28, 44}, {36, 36, 76}, {40, 44, 104}, {44, 48, 132}, {32, 24, 184}, {52, 60, 172}, {104, 104, 148}, {100, 144, 252}, {124, 172, 252}, {0, 228, 252}, {156, 144, 64}, {168, 148, 84}, {188, 164, 92}, {204, 184, 96}, {232, 216, 128}, {236, 196, 176}, {252, 252, 56}, {252, 252, 124}, {252, 252, 164}, {8, 8, 8}, {16, 16, 16}, {24, 24, 24}, {40, 40, 40}, {52, 52, 52}, {76, 60, 56}, {68, 68, 68}, {72, 72, 88}, {88, 88, 104}, {116, 104, 56}, {120, 100, 92}, {96, 96, 124}, {132, 116, 116}, {132, 132, 156}, {172, 140, 124}, {172, 152, 148}, {144, 144, 184}, {184, 184, 232}, {248, 140, 20}, {16, 84, 60}, {32, 144, 112}, {44, 180, 148}, {4, 32, 100}, {72, 28, 80}, {8, 52, 152}, {104, 48, 120}, {136, 64, 156}, {12, 72, 204}, {188, 184, 52}, {220, 220, 60}, {16, 0, 0}, {36, 0, 0}, {52, 0, 0}, {72, 0, 0}, {96, 24, 4}, {140, 40, 8}, {200, 24, 24}, {224, 44, 44}, {232, 32, 32}, {232, 80, 20}, {252, 32, 32}, {232, 120, 36}, {248, 172, 60}, {0, 20, 0}, {0, 40, 0}, {0, 68, 0}, {0, 100, 0}, {8, 128, 8}, {36, 152, 36}, {60, 156, 60}, {88, 176, 88}, {104, 184, 104}, {128, 196, 128}, {148, 212, 148}, {12, 20, 36}, {36, 60, 100}, {48, 80, 132}, {56, 92, 148}, {72, 116, 180}, {84, 132, 196}, {96, 148, 212}, {120, 180, 236}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {255, 255, 255} }; // Amount of colors expected per ID for all colors generated by // R=0..256, G=0..256, B=0..256 . If the Color::getBestIdFor is not // correctly implemented, this will probably mismatch. static final int[] COLORS_RGB_TO_ID_BUCKETS = { 1152, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 28608, 13184, 14592, 30464, 17408, 33344, 13056, 57344, 27200, 16512, 47808, 65152, 42176, 38080, 54784, 75584, 60352, 70016, 59200, 89792, 36992, 42880, 50944, 72320, 2688, 16960, 27968, 24000, 21952, 55104, 36992, 35392, 51712, 118016, 64320, 330624, 391424, 279040, 70912, 133056, 128000, 134144, 77376, 18368, 31104, 56960, 53184, 32000, 3584, 5312, 8448, 11712, 9728, 12416, 15168, 12608, 22720, 20736, 26240, 47040, 31168, 54080, 41536, 60288, 58496, 97792, 104896, 93312, 124352, 81152, 6976, 10048, 9920, 14592, 44224, 8640, 24256, 6016, 13696, 38592, 22592, 73408, 41728, 15360, 117696, 88704, 75776, 98752, 65216, 35840, 114304, 38912, 206464, 179008, 80640, 25984, 94464, 268160, 255552, 58048, 80448, 381376, 9856, 16576, 42304, 48640, 100736, 247808, 183040, 79616, 165120, 47296, 227712, 85312, 55424, 67136, 108864, 135808, 194304, 35328, 31680, 21632, 3072, 5120, 7040, 7936, 11392, 18048, 9984, 25536, 19328, 38208, 31104, 36992, 65728, 81408, 108800, 139456, 304512, 387648, 75264, 127360, 244608, 508160, 57344, 142464, 71936, 294848, 1439616, 181632, 392832, 230848, 1664, 3264, 2304, 7552, 24448, 38912, 128384, 281920, 53248, 84736, 42304, 65664, 42560, 3072, 12672, 31744, 26624, 80000, 308480, 243328, 305792, 218752, 220032, 253568, 11840, 31424, 45888, 62016, 82368, 70912, 100352, 130560, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; @Test public void checkAllColorsIdToRGB() { for (int id=0; id < 256; id++) { Color c = new Color(id); assertEquals(COLORS_ID_TO_RGB[id][0], c.red()); assertEquals(COLORS_ID_TO_RGB[id][1], c.green()); assertEquals(COLORS_ID_TO_RGB[id][2], c.blue()); } } @Test public void checkAllColorsRGBToId() { final int[] buckets = new int[256]; for (int r=0; r < 256; r++) { for (int g=0; g < 256; g++) { for (int b=0; b < 256; b++) { Color c = new Color(r, g, b); buckets[c.id] += 1; } } } assertArrayEquals(COLORS_RGB_TO_ID_BUCKETS, buckets); } @Test public void checkColorWithInvalidId() { assertEquals(255, new Color(-1).id); assertEquals(255, new Color(256).id); } @Test public void toStringTest() { assertEquals("Color.Black", Color.Black.toString()); assertEquals("Color.Black", new Color(0, 0, 0).toString()); assertEquals("Color.Black", new Color(Color.Black.id).toString()); assertEquals("Color.Orange", Color.Orange.toString()); assertEquals("Color.Purple", Color.Purple.toString()); assertEquals("Color{red=16, green=16, blue=16}", new Color(16, 16, 16).toString()); } }