X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Futil%2FColorUtilsTest.java;h=9a5d093046e385741c2b5e2b9bda83f24837dd4b;hb=7b10124f09af29607ea0150726ad5d63da09fdaf;hp=42a47169d0c7f6b0b8c9f1bcfd39cc962ee04c04;hpb=c19d2a91ca05e052e3408bf5852d88eb5d0608f1;p=jalview.git diff --git a/test/jalview/util/ColorUtilsTest.java b/test/jalview/util/ColorUtilsTest.java index 42a4716..9a5d093 100644 --- a/test/jalview/util/ColorUtilsTest.java +++ b/test/jalview/util/ColorUtilsTest.java @@ -1,6 +1,6 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9.0b2) - * Copyright (C) 2015 The Jalview Authors + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors * * This file is part of Jalview. * @@ -22,14 +22,25 @@ package jalview.util; import static org.testng.AssertJUnit.assertEquals; import static org.testng.AssertJUnit.assertNull; +import static org.testng.AssertJUnit.assertSame; + +import jalview.gui.JvOptionPane; import java.awt.Color; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; public class ColorUtilsTest { + @BeforeClass(alwaysRun = true) + public void setUpJvOptionPane() + { + JvOptionPane.setInteractiveMode(false); + JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); + } + Color paleColour = new Color(97, 203, 111); // pale green Color midColour = new Color(135, 57, 41); // mid red @@ -72,4 +83,87 @@ public class ColorUtilsTest assertEquals("#800080", ColorUtils.toTkCode(new Color(128, 0, 128))); // purple assertEquals("#00ff00", ColorUtils.toTkCode(new Color(0, 255, 0))); // lime } + + @Test(groups = { "Functional" }) + public void testGetGraduatedColour() + { + Color minColour = new Color(100, 100, 100); + Color maxColour = new Color(180, 200, 220); + + /* + * value half-way between min and max + */ + Color col = ColorUtils.getGraduatedColour(20f, 10f, minColour, 30f, + maxColour); + assertEquals(140, col.getRed()); + assertEquals(150, col.getGreen()); + assertEquals(160, col.getBlue()); + + /* + * value two-thirds of the way between min and max + */ + col = ColorUtils + .getGraduatedColour(30f, 10f, minColour, 40f, maxColour); + assertEquals(153, col.getRed()); + // Color constructor rounds float value to nearest int + assertEquals(167, col.getGreen()); + assertEquals(180, col.getBlue()); + + /* + * value = min + */ + col = ColorUtils + .getGraduatedColour(10f, 10f, minColour, 30f, maxColour); + assertEquals(minColour, col); + + /* + * value = max + */ + col = ColorUtils + .getGraduatedColour(30f, 10f, minColour, 30f, maxColour); + assertEquals(maxColour, col); + + /* + * value < min + */ + col = ColorUtils.getGraduatedColour(0f, 10f, minColour, 30f, maxColour); + assertEquals(minColour, col); + + /* + * value > max + */ + col = ColorUtils + .getGraduatedColour(40f, 10f, minColour, 30f, maxColour); + assertEquals(maxColour, col); + + /* + * min = max + */ + col = ColorUtils + .getGraduatedColour(40f, 10f, minColour, 10f, maxColour); + assertEquals(minColour, col); + } + + @Test(groups = { "Functional" }) + public void testBleachColour() + { + Color colour = new Color(155, 105, 55); + assertSame(colour, ColorUtils.bleachColour(colour, 0)); + assertEquals(Color.WHITE, ColorUtils.bleachColour(colour, 1)); + assertEquals(Color.WHITE, ColorUtils.bleachColour(colour, 2)); + assertEquals(new Color(175, 135, 95), + ColorUtils.bleachColour(colour, 0.2f)); + assertEquals(new Color(225, 210, 195), + ColorUtils.bleachColour(colour, 0.7f)); + + /* + * and some 'negative fade' + */ + assertEquals(Color.BLACK, ColorUtils.bleachColour(colour, -1)); + assertEquals(Color.BLACK, ColorUtils.bleachColour(colour, -2)); + assertEquals(new Color(124, 84, 44), + ColorUtils.bleachColour(colour, -0.2f)); + assertEquals(new Color(46, 31, 16), // with rounding down + ColorUtils.bleachColour(colour, -0.7f)); + } }