RandomColors extends IndexedColorMapper { @Override public Paint get(int index) { Integer key = index; if (colorCache.containsKey(key)) { return colorCache.get(key); } boolean match; Color r; do { r = getRandomColor(); match = true; Iterator<Color> colors = colorCache.values().iterator(); for (int i=0; i<NUM_COMPARISONS && colors.hasNext(); i++) { Color prev = colors.next(); if (distanceSq(r, prev) < MIN_DIST*MIN_DIST) { match = false; break; } } } while (!match); colorCache.put(key, r); return r; } RandomColors();  RandomColors(long seed); @Override Paint get(int index); float[] getColorVariance(); void setColorVariance(float[] colorVariance);  }
@Test public void testCreationInt() { RandomColors c1 = new RandomColors(0); RandomColors c2 = new RandomColors(0); for (int i = 0; i <= 10; i++) { assertEquals(c1.get(i), c2.get(i)); } }
@Test public void testGet() { RandomColors c = new RandomColors(); int STEPS = 10; Paint[] actual = new Paint[STEPS]; for (int run = 0; run < 2; run++) { Paint prv = null; for (int i = 0; i < STEPS; i++) { Paint cur = c.get(i); if (run == 0) { actual[i] = cur; } else { assertEquals(actual[i], cur); } assertNotNull(cur); assertFalse(cur.equals(prv)); prv = cur; } } }