assertEquals("FFFF:0:FFFF", p.getColor((short)14).getHexString());
}
public void testFindSimilar() {
HSSFWorkbook book = new HSSFWorkbook();
HSSFPalette p = book.getCustomPalette();
/* first test the defaults */
assertTrue(
Arrays.equals(
new short[] {(short) 255, (short) 255, (short) 0}, // not [204, 255, 255]
p.findSimilarColor((byte) 204, (byte) 255, (byte) 0).getTriplet()
)
);
assertTrue(
Arrays.equals(
new short[] {(short) 153, (short) 204, (short) 0}, // not [128, 0, 0]
p.findSimilarColor((byte) 128, (byte) 255, (byte) 0).getTriplet()
)
);
assertTrue(
Arrays.equals(
new short[] {(short) 0, (short) 255, (short) 0}, // not [0, 51, 102]
p.findSimilarColor((byte) 0, (byte) 255, (byte) 102).getTriplet()
)
);
assertTrue(
Arrays.equals(
new short[] {(short) 0, (short) 102, (short) 204}, // not [255, 102, 0]
p.findSimilarColor((byte) 0, (byte) 102, (byte) 255).getTriplet()
)
);
assertTrue(
Arrays.equals(
new short[] {(short) 255, (short) 0, (short) 255}, // not [128, 0, 0]
p.findSimilarColor((byte) 128, (byte) 0, (byte) 255).getTriplet()
)
);
assertTrue(
Arrays.equals(
new short[] {(short) 255, (short) 0, (short) 255}, // not [255, 255, 153]
p.findSimilarColor((byte) 255, (byte) 0, (byte) 153).getTriplet()
)
);
// Add a few edge colours in
p.setColorAtIndex((short)8, (byte)-1, (byte)0, (byte)0);
p.setColorAtIndex((short)9, (byte)0, (byte)-1, (byte)0);
p.setColorAtIndex((short)10, (byte)0, (byte)0, (byte)-1);
// And some near a few of them
p.setColorAtIndex((short)11, (byte)-1, (byte)2, (byte)2);
p.setColorAtIndex((short)12, (byte)-2, (byte)2, (byte)10);
p.setColorAtIndex((short)13, (byte)-4, (byte)0, (byte)0);
p.setColorAtIndex((short)14, (byte)-8, (byte)0, (byte)0);
assertEquals(
"FFFF:0:0", p.getColor((short)8).getHexString()
);
// Now check we get the right stuff back
assertEquals(
p.getColor((short)8).getHexString(),
p.findSimilarColor((byte)-1, (byte)0, (byte)0).getHexString()
);
assertEquals(
p.getColor((short)8).getHexString(),
p.findSimilarColor((byte)-2, (byte)0, (byte)0).getHexString()
);
assertEquals(
p.getColor((short)8).getHexString(),
p.findSimilarColor((byte)-1, (byte)1, (byte)0).getHexString()
);
assertEquals(
p.getColor((short)11).getHexString(),
p.findSimilarColor((byte)-1, (byte)2, (byte)1).getHexString()
);
assertEquals(
p.getColor((short)12).getHexString(),
p.findSimilarColor((byte)-1, (byte)2, (byte)10).getHexString()
);
// And with ints not bytes
assertEquals(
p.getColor((short)11).getHexString(),
p.findSimilarColor(255, 2, 1).getHexString()
);
assertEquals(
p.getColor((short)12).getHexString(),
p.findSimilarColor(255, 2, 10).getHexString()
);
}