X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fschemes%2FFeatureColourTest.java;h=85c3f8b1c31858501e3872a22a0dadb640ec40ea;hb=refs%2Fheads%2Fbug%2FJAL-2876byLabelThreshold;hp=fd4997105a8928523af14c9a1bd8641e06633c37;hpb=604cbee405a837565ba1a74aa9bddd62aed685ab;p=jalview.git diff --git a/test/jalview/schemes/FeatureColourTest.java b/test/jalview/schemes/FeatureColourTest.java index fd49971..85c3f8b 100644 --- a/test/jalview/schemes/FeatureColourTest.java +++ b/test/jalview/schemes/FeatureColourTest.java @@ -22,18 +22,30 @@ package jalview.schemes; import static org.testng.AssertJUnit.assertEquals; import static org.testng.AssertJUnit.assertFalse; +import static org.testng.AssertJUnit.assertNull; import static org.testng.AssertJUnit.assertTrue; import static org.testng.AssertJUnit.fail; import jalview.datamodel.SequenceFeature; +import jalview.gui.JvOptionPane; +import jalview.util.ColorUtils; import jalview.util.Format; import java.awt.Color; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; public class FeatureColourTest { + + @BeforeClass(alwaysRun = true) + public void setUpJvOptionPane() + { + JvOptionPane.setInteractiveMode(false); + JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); + } + @Test(groups = { "Functional" }) public void testCopyConstructor() { @@ -73,75 +85,26 @@ public class FeatureColourTest } @Test(groups = { "Functional" }) - public void testIsColored_simpleColour() - { - FeatureColour fc = new FeatureColour(Color.RED); - assertTrue(fc.isColored(new SequenceFeature())); - } - - @Test(groups = { "Functional" }) - public void testIsColored_colourByLabel() - { - FeatureColour fc = new FeatureColour(); - fc.setColourByLabel(true); - assertTrue(fc.isColored(new SequenceFeature())); - } - - @Test(groups = { "Functional" }) - public void testIsColored_aboveThreshold() - { - // graduated colour range from score 20 to 100 - FeatureColour fc = new FeatureColour(Color.WHITE, Color.BLACK, 20f, - 100f); - - // score 0 is adjusted to bottom of range - SequenceFeature sf = new SequenceFeature("type", "desc", 0, 20, 0f, - null); - assertTrue(fc.isColored(sf)); - assertEquals(Color.WHITE, fc.getColor(sf)); - - // score 120 is adjusted to top of range - sf.setScore(120f); - assertEquals(Color.BLACK, fc.getColor(sf)); - - // value below threshold is still rendered - // setting threshold has no effect yet... - fc.setThreshold(60f); - sf.setScore(36f); - assertTrue(fc.isColored(sf)); - assertEquals(new Color(204, 204, 204), fc.getColor(sf)); - - // now apply threshold: - fc.setAboveThreshold(true); - assertFalse(fc.isColored(sf)); - // colour is still returned though ?!? - assertEquals(new Color(204, 204, 204), fc.getColor(sf)); - - sf.setScore(84); // above threshold now - assertTrue(fc.isColored(sf)); - assertEquals(new Color(51, 51, 51), fc.getColor(sf)); - } - - @Test(groups = { "Functional" }) - public void testGetColor_simpleColour() + public void testGetColour_simpleColour() { FeatureColour fc = new FeatureColour(Color.RED); - assertEquals(Color.RED, fc.getColor(new SequenceFeature())); + assertEquals(Color.RED, + fc.getColour(new SequenceFeature("Cath", "", 1, 2, 0f, null))); } @Test(groups = { "Functional" }) - public void testGetColor_colourByLabel() + public void testGetColour_colourByLabel() { FeatureColour fc = new FeatureColour(); fc.setColourByLabel(true); SequenceFeature sf = new SequenceFeature("type", "desc", 0, 20, 1f, null); - Color expected = UserColourScheme.createColourFromName("desc"); - assertEquals(expected, fc.getColor(sf)); + Color expected = ColorUtils.createColourFromName("desc"); + assertEquals(expected, fc.getColour(sf)); } @Test(groups = { "Functional" }) - public void testGetColor_Graduated() + public void testGetColour_Graduated() { // graduated colour from score 0 to 100, gray(128, 128, 128) to red(255, 0, // 0) @@ -154,24 +117,39 @@ public class FeatureColourTest float green = 128 / 255f + 3 / 4f * (0 - 128) / 255f; float blue = 128 / 255f + 3 / 4f * (0 - 128) / 255f; Color expected = new Color(red, green, blue); - assertEquals(expected, fc.getColor(sf)); + assertEquals(expected, fc.getColour(sf)); } @Test(groups = { "Functional" }) - public void testGetColor_belowThreshold() + public void testGetColour_aboveBelowThreshold() { // gradient from [50, 150] from WHITE(255, 255, 255) to BLACK(0, 0, 0) FeatureColour fc = new FeatureColour(Color.WHITE, Color.BLACK, 50f, 150f); SequenceFeature sf = new SequenceFeature("type", "desc", 0, 20, 70f, null); + + /* + * feature with score of Float.NaN is always assigned minimum colour + */ + SequenceFeature sf2 = new SequenceFeature("type", "desc", 0, 20, + Float.NaN, null); + fc.setThreshold(100f); // ignore for now - assertTrue(fc.isColored(sf)); - assertEquals(new Color(204, 204, 204), fc.getColor(sf)); + assertEquals(new Color(204, 204, 204), fc.getColour(sf)); + assertEquals(Color.white, fc.getColour(sf2)); fc.setAboveThreshold(true); // feature lies below threshold - assertFalse(fc.isColored(sf)); - assertEquals(new Color(204, 204, 204), fc.getColor(sf)); + assertNull(fc.getColour(sf)); + assertEquals(Color.white, fc.getColour(sf2)); + + fc.setBelowThreshold(true); + fc.setThreshold(70f); + assertNull(fc.getColour(sf)); // feature score == threshold - hidden + assertEquals(Color.white, fc.getColour(sf2)); + fc.setThreshold(69f); + assertNull(fc.getColour(sf)); // feature score > threshold - hidden + assertEquals(Color.white, fc.getColour(sf2)); } /** @@ -362,4 +340,33 @@ public class FeatureColourTest fc = FeatureColour.parseJalviewFeatureColour(descriptor); assertTrue(fc.isGraduatedColour()); } + + @Test(groups = { "Functional" }) + public void testGetColour_colourByLabel_withThreshold() + { + FeatureColour fc = new FeatureColour(); + fc.setColourByLabel(true); + SequenceFeature sf = new SequenceFeature("type", "desc", 0, 20, 1f, + null); + fc.setThreshold(0); + Color expected = ColorUtils.createColourFromName("desc"); + assertEquals(expected, fc.getColour(sf)); + + // score (1f) is above threshold + fc.setAboveThreshold(true); + assertEquals(expected, fc.getColour(sf)); + + // score is not above threshold + fc.setThreshold(2f); + assertNull(fc.getColour(sf)); + + // score is not below threshold + fc.setThreshold(0f); + fc.setBelowThreshold(true); + assertNull(fc.getColour(sf)); + + // score is below threshold + fc.setThreshold(3f); + assertEquals(expected, fc.getColour(sf)); + } }