X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=test%2Fjalview%2Fschemes%2FFeatureColourTest.java;fp=test%2Fjalview%2Fschemes%2FFeatureColourTest.java;h=8f7ac7cd5804819636e0eada5527ffb3c08eb100;hb=3c8a25936a2d805e7e3d7ab82f83b13135406d18;hp=1a6a5f342e8ec9bb8b1fda575657e243ccd12f33;hpb=e42eed3a0089a8a064560df4cf17a5021fd1e16a;p=jalview.git diff --git a/test/jalview/schemes/FeatureColourTest.java b/test/jalview/schemes/FeatureColourTest.java index 1a6a5f3..8f7ac7c 100644 --- a/test/jalview/schemes/FeatureColourTest.java +++ b/test/jalview/schemes/FeatureColourTest.java @@ -469,11 +469,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 @@ -610,4 +659,45 @@ public class FeatureColourTest Color expected = new Color(70, 120, 170); assertEquals(expected, fc.getColor(sf)); } + + @Test(groups = { "Functional" }) + public void testIsOutwithThreshold() + { + FeatureColourI fc = new FeatureColour(Color.red); + SequenceFeature sf = new SequenceFeature("METAL", "desc", 10, 12, 1.2f, "grp"); + assertFalse(fc.isOutwithThreshold(null)); + assertFalse(fc.isOutwithThreshold(sf)); + + fc = new FeatureColour(null, Color.white, Color.black, Color.green, 0f, + 10f); + assertFalse(fc.isOutwithThreshold(sf)); // no threshold + + fc.setAboveThreshold(true); + fc.setThreshold(1f); + assertFalse(fc.isOutwithThreshold(sf)); // feature score 1.2 is above 1 + + fc.setThreshold(2f); + assertTrue(fc.isOutwithThreshold(sf)); // feature score 1.2 is not above 2 + + fc.setBelowThreshold(true); + assertFalse(fc.isOutwithThreshold(sf)); // feature score 1.2 is below 2 + + fc.setThreshold(1f); + assertTrue(fc.isOutwithThreshold(sf)); // feature score 1.2 is not below 1 + + /* + * with attribute value threshold + */ + fc.setAttributeName("AC"); + assertFalse(fc.isOutwithThreshold(sf)); // missing attribute AC is ignored + + sf.setValue("AC", "-1"); + assertFalse(fc.isOutwithThreshold(sf)); // value -1 is below 1 + + sf.setValue("AC", "1"); + assertTrue(fc.isOutwithThreshold(sf)); // value 1 is not below 1 + + sf.setValue("AC", "junk"); + assertFalse(fc.isOutwithThreshold(sf)); // bad value is ignored + } }