X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fschemes%2FFeatureColourTest.java;h=99542ae3532df95a7427f0bf0dff0e6726a9c01f;hb=bd7b3138379c2db8507fe7e8d25f5a921e2d9df7;hp=2eb718b68d86ab855ae22c620dd5f990bed8bcbe;hpb=007f2c0fa4563baa95d43da08b5e4edc99ddc9a0;p=jalview.git diff --git a/test/jalview/schemes/FeatureColourTest.java b/test/jalview/schemes/FeatureColourTest.java index 2eb718b..99542ae 100644 --- a/test/jalview/schemes/FeatureColourTest.java +++ b/test/jalview/schemes/FeatureColourTest.java @@ -523,11 +523,60 @@ public class FeatureColourTest assertFalse(fc.hasThreshold()); assertEquals(Color.RED, fc.getMinColour()); assertEquals(Color.GREEN, fc.getMaxColour()); + assertEquals(Color.RED, fc.getNoColour()); assertEquals(10f, fc.getMin()); assertEquals(20f, fc.getMax()); assertTrue(fc.isAutoScaled()); /* + * the same, with 'no value colour' specified as max + */ + fc = FeatureColour + .parseJalviewFeatureColour("red|green|novaluemax|10.0|20.0"); + assertEquals(Color.RED, fc.getMinColour()); + assertEquals(Color.GREEN, fc.getMaxColour()); + assertEquals(Color.GREEN, fc.getNoColour()); + assertEquals(10f, fc.getMin()); + assertEquals(20f, fc.getMax()); + + /* + * the same, with 'no value colour' specified as min + */ + fc = FeatureColour + .parseJalviewFeatureColour("red|green|novalueMin|10.0|20.0"); + assertEquals(Color.RED, fc.getMinColour()); + assertEquals(Color.GREEN, fc.getMaxColour()); + assertEquals(Color.RED, fc.getNoColour()); + assertEquals(10f, fc.getMin()); + assertEquals(20f, fc.getMax()); + + /* + * the same, with 'no value colour' specified as none + */ + fc = FeatureColour + .parseJalviewFeatureColour("red|green|novaluenone|10.0|20.0"); + assertEquals(Color.RED, fc.getMinColour()); + assertEquals(Color.GREEN, fc.getMaxColour()); + assertNull(fc.getNoColour()); + assertEquals(10f, fc.getMin()); + assertEquals(20f, fc.getMax()); + + /* + * the same, with invalid 'no value colour' + */ + try + { + fc = FeatureColour + .parseJalviewFeatureColour("red|green|blue|10.0|20.0"); + fail("expected exception"); + } catch (IllegalArgumentException e) + { + assertEquals( + "Couldn't parse the minimum value for graduated colour ('blue')", + e.getMessage()); + } + + /* * graduated colour (explicitly by 'score') (no threshold) */ fc = FeatureColour @@ -663,4 +712,101 @@ public class FeatureColourTest Color expected = new Color(70, 120, 170); assertEquals(expected, fc.getColor(sf)); } + + /** + * Test description of feature colour suitable for a tooltip + */ + @Test(groups = { "Functional" }) + public void testGetDescription() + { + /* + * plain colour + */ + FeatureColour fc = new FeatureColour(Color.RED); + assertEquals( + String.format("r=%d,g=%d,b=%d", Color.RED.getRed(), + Color.red.getGreen(), Color.red.getBlue()), + fc.getDescription()); + + /* + * colour by label (no threshold) + */ + fc = new FeatureColour(); + fc.setColourByLabel(true); + assertEquals("By Label", fc.getDescription()); + + /* + * colour by attribute text (no threshold) + */ + fc = new FeatureColour(); + fc.setColourByLabel(true); + fc.setAttributeName("CLIN_SIG"); + assertEquals("By CLIN_SIG", fc.getDescription()); + + /* + * colour by label (above score threshold) + */ + fc = new FeatureColour(); + fc.setColourByLabel(true); + fc.setAutoScaled(false); + fc.setThreshold(12.5f); + fc.setAboveThreshold(true); + assertEquals("By Label (Score > 12.5)", + fc.getDescription()); + + /* + * colour by label (below score threshold) + */ + fc.setBelowThreshold(true); + assertEquals("By Label (Score < 12.5)", + fc.getDescription()); + + /* + * colour by attributes text (below score threshold) + */ + fc.setBelowThreshold(true); + fc.setAttributeName("CSQ", "Consequence"); + assertEquals( + "By CSQ:Consequence (Score < 12.5)", + fc.getDescription()); + + /* + * graduated colour by score, no threshold + */ + fc = new FeatureColour(Color.GREEN, Color.RED, 12f, 25f); + assertEquals("By Score", fc.getDescription()); + + /* + * graduated colour by score, below threshold + */ + fc.setThreshold(12.5f); + fc.setBelowThreshold(true); + assertEquals("By Score (< 12.5)", + fc.getDescription()); + + /* + * graduated colour by score, above threshold + */ + fc.setThreshold(12.5f); + fc.setAboveThreshold(true); + fc.setAutoScaled(false); + assertEquals("By Score (> 12.5)", + fc.getDescription()); + + /* + * graduated colour by attribute, no threshold + */ + fc.setAttributeName("CSQ", "AF"); + fc.setAboveThreshold(false); + fc.setAutoScaled(false); + assertEquals("By CSQ:AF", fc.getDescription()); + + /* + * graduated colour by attribute, above threshold + */ + fc.setAboveThreshold(true); + fc.setAutoScaled(false); + assertEquals("By CSQ:AF (> 12.5)", + fc.getDescription()); + } }