X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fschemes%2FFeatureColourTest.java;h=42b898db0fd8bd8a57138cde4b519a6a63b616bf;hb=43d97319aebb52a38c58fe201198f593d312b940;hp=99542ae3532df95a7427f0bf0dff0e6726a9c01f;hpb=dcfba29a940c44003581f28e6da481450aa86575;p=jalview.git diff --git a/test/jalview/schemes/FeatureColourTest.java b/test/jalview/schemes/FeatureColourTest.java index 99542ae..42b898d 100644 --- a/test/jalview/schemes/FeatureColourTest.java +++ b/test/jalview/schemes/FeatureColourTest.java @@ -38,8 +38,6 @@ import java.awt.Color; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import junit.extensions.PA; - public class FeatureColourTest { @@ -51,6 +49,30 @@ public class FeatureColourTest } @Test(groups = { "Functional" }) + public void testConstructors() + { + FeatureColourI fc = new FeatureColour(); + assertNull(fc.getColour()); + assertTrue(fc.isSimpleColour()); + assertFalse(fc.isColourByLabel()); + assertFalse(fc.isGraduatedColour()); + assertFalse(fc.isColourByAttribute()); + assertEquals(Color.white, fc.getMinColour()); + assertEquals(Color.black, fc.getMaxColour()); + + fc = new FeatureColour(Color.RED); + assertEquals(Color.red, fc.getColour()); + assertTrue(fc.isSimpleColour()); + assertFalse(fc.isColourByLabel()); + assertFalse(fc.isGraduatedColour()); + assertFalse(fc.isColourByAttribute()); + assertEquals(ColorUtils.bleachColour(Color.RED, 0.9f), + fc.getMinColour()); + assertEquals(Color.RED, fc.getMaxColour()); + + } + + @Test(groups = { "Functional" }) public void testCopyConstructor() { /* @@ -67,7 +89,8 @@ public class FeatureColourTest /* * min-max colour */ - fc = new FeatureColour(Color.gray, Color.black, 10f, 20f); + fc = new FeatureColour(null, Color.gray, Color.black, Color.gray, 10f, + 20f); fc.setAboveThreshold(true); fc.setThreshold(12f); fc1 = new FeatureColour(fc); @@ -86,12 +109,14 @@ public class FeatureColourTest /* * min-max-noValue colour */ - fc = new FeatureColour(Color.gray, Color.black, Color.green, 10f, 20f); + fc = new FeatureColour(Color.red, Color.gray, Color.black, Color.green, + 10f, 20f); fc.setAboveThreshold(true); fc.setThreshold(12f); fc1 = new FeatureColour(fc); assertTrue(fc1.isGraduatedColour()); assertFalse(fc1.isColourByLabel()); + assertFalse(fc1.isSimpleColour()); assertFalse(fc1.isColourByAttribute()); assertNull(fc1.getAttributeName()); assertTrue(fc1.isAboveThreshold()); @@ -99,6 +124,7 @@ public class FeatureColourTest assertEquals(Color.gray, fc1.getMinColour()); assertEquals(Color.black, fc1.getMaxColour()); assertEquals(Color.green, fc1.getNoColour()); + assertEquals(Color.red, fc1.getColour()); assertEquals(10f, fc1.getMin()); assertEquals(20f, fc1.getMax()); @@ -128,7 +154,8 @@ public class FeatureColourTest /* * colour by attribute (value) */ - fc = new FeatureColour(Color.gray, Color.black, Color.green, 10f, 20f); + fc = new FeatureColour(Color.yellow, Color.gray, Color.black, + Color.green, 10f, 20f); fc.setAboveThreshold(true); fc.setThreshold(12f); fc.setAttributeName("AF"); @@ -136,101 +163,23 @@ public class FeatureColourTest assertTrue(fc1.isGraduatedColour()); assertFalse(fc1.isColourByLabel()); assertTrue(fc1.isColourByAttribute()); + assertFalse(fc1.isSimpleColour()); assertArrayEquals(new String[] { "AF" }, fc1.getAttributeName()); assertTrue(fc1.isAboveThreshold()); assertEquals(12f, fc1.getThreshold()); assertEquals(Color.gray, fc1.getMinColour()); assertEquals(Color.black, fc1.getMaxColour()); assertEquals(Color.green, fc1.getNoColour()); + assertEquals(Color.yellow, fc1.getColour()); assertEquals(10f, fc1.getMin()); assertEquals(20f, fc1.getMax()); - } - - @Test(groups = { "Functional" }) - public void testCopyConstructor_minMax() - { - /* - * graduated colour - */ - FeatureColour fc = new FeatureColour(Color.BLUE, Color.RED, 1f, 5f); - assertTrue(fc.isGraduatedColour()); - assertFalse(fc.isColourByLabel()); - assertFalse(fc.isColourByAttribute()); - assertNull(fc.getAttributeName()); - assertEquals(1f, fc.getMin()); - assertEquals(5f, fc.getMax()); - - /* - * update min-max bounds - */ - FeatureColour fc1 = new FeatureColour(fc, 2f, 6f); - assertTrue(fc1.isGraduatedColour()); - assertFalse(fc1.isColourByLabel()); - assertFalse(fc1.isColourByAttribute()); - assertNull(fc1.getAttributeName()); - assertEquals(2f, fc1.getMin()); - assertEquals(6f, fc1.getMax()); - assertFalse((boolean) PA.getValue(fc1, "isHighToLow")); - - /* - * update min-max bounds - high to low - */ - fc1 = new FeatureColour(fc, 23f, 16f); - assertTrue(fc1.isGraduatedColour()); - assertFalse(fc1.isColourByLabel()); - assertFalse(fc1.isColourByAttribute()); - assertNull(fc1.getAttributeName()); - assertEquals(23f, fc1.getMin()); - assertEquals(16f, fc1.getMax()); - assertTrue((boolean) PA.getValue(fc1, "isHighToLow")); /* - * graduated colour by attribute + * modify original attribute label and check that copy doesn't change */ - fc1.setAttributeName("AF"); - fc1 = new FeatureColour(fc1, 13f, 36f); - assertTrue(fc1.isGraduatedColour()); - assertFalse(fc1.isColourByLabel()); - assertTrue(fc1.isColourByAttribute()); + fc.setAttributeName("MAF", "AF"); assertArrayEquals(new String[] { "AF" }, fc1.getAttributeName()); - assertEquals(13f, fc1.getMin()); - assertEquals(36f, fc1.getMax()); - assertFalse((boolean) PA.getValue(fc1, "isHighToLow")); - - /* - * colour by label - */ - fc = new FeatureColour(Color.BLUE, Color.RED, 1f, 5f); - fc.setColourByLabel(true); - assertFalse(fc.isGraduatedColour()); - assertTrue(fc.isColourByLabel()); - assertFalse(fc.isColourByAttribute()); - assertNull(fc.getAttributeName()); - assertEquals(1f, fc.getMin()); - assertEquals(5f, fc.getMax()); - - /* - * update min-max bounds - */ - fc1 = new FeatureColour(fc, 2f, 6f); - assertFalse(fc1.isGraduatedColour()); - assertTrue(fc1.isColourByLabel()); - assertFalse(fc1.isColourByAttribute()); - assertNull(fc1.getAttributeName()); - assertEquals(2f, fc1.getMin()); - assertEquals(6f, fc1.getMax()); - /* - * colour by attribute text - */ - fc1.setAttributeName("AC"); - fc1 = new FeatureColour(fc1, 13f, 36f); - assertFalse(fc1.isGraduatedColour()); - assertTrue(fc1.isColourByLabel()); - assertTrue(fc1.isColourByAttribute()); - assertArrayEquals(new String[] { "AC" }, fc1.getAttributeName()); - assertEquals(13f, fc1.getMin()); - assertEquals(36f, fc1.getMax()); } @Test(groups = { "Functional" }) @@ -260,7 +209,8 @@ public class FeatureColourTest * score 0 to 100 * gray(128, 128, 128) to red(255, 0, 0) */ - FeatureColour fc = new FeatureColour(Color.GRAY, Color.RED, 0f, 100f); + FeatureColour fc = new FeatureColour(null, Color.GRAY, Color.RED, null, + 0f, 100f); // feature score is 75 which is 3/4 of the way from GRAY to RED SequenceFeature sf = new SequenceFeature("type", "desc", 0, 20, 75f, null); @@ -276,8 +226,8 @@ public class FeatureColourTest public void testGetColor_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); + FeatureColour fc = new FeatureColour(null, Color.WHITE, Color.BLACK, + Color.white, 50f, 150f); SequenceFeature sf = new SequenceFeature("type", "desc", 0, 20, 70f, null); @@ -331,8 +281,9 @@ public class FeatureColourTest fc = new FeatureColour(); fc.setColourByLabel(true); fc.setAttributeName("CLIN_SIG"); - assertEquals("domain\tattribute|CLIN_SIG", fc.toJalviewFormat("domain")); - + assertEquals("domain\tattribute|CLIN_SIG", + fc.toJalviewFormat("domain")); + /* * colour by label (autoscaled) (an odd state you can reach by selecting * 'above threshold', then deselecting 'threshold is min/max' then 'colour @@ -371,7 +322,8 @@ public class FeatureColourTest * graduated colour by score, no threshold * - default constructor sets noValueColor = minColor */ - fc = new FeatureColour(Color.GREEN, Color.RED, 12f, 25f); + fc = new FeatureColour(null, Color.GREEN, Color.RED, Color.GREEN, 12f, + 25f); String greenHex = Format.getHexString(Color.GREEN); String expected = String.format( "domain\tscore|%s|%s|noValueMin|abso|12.0|25.0|none", greenHex, @@ -381,7 +333,8 @@ public class FeatureColourTest /* * graduated colour by score, no threshold, no value gets min colour */ - fc = new FeatureColour(Color.GREEN, Color.RED, Color.GREEN, 12f, 25f); + fc = new FeatureColour(Color.RED, Color.GREEN, Color.RED, Color.GREEN, + 12f, 25f); expected = String.format( "domain\tscore|%s|%s|noValueMin|abso|12.0|25.0|none", greenHex, redHex); @@ -390,12 +343,13 @@ public class FeatureColourTest /* * graduated colour by score, no threshold, no value gets max colour */ - fc = new FeatureColour(Color.GREEN, Color.RED, Color.RED, 12f, 25f); + fc = new FeatureColour(Color.RED, Color.GREEN, Color.RED, Color.RED, + 12f, 25f); expected = String.format( "domain\tscore|%s|%s|noValueMax|abso|12.0|25.0|none", greenHex, redHex); assertEquals(expected, fc.toJalviewFormat("domain")); - + /* * colour ranges over the actual score ranges (not min/max) */ @@ -411,8 +365,8 @@ public class FeatureColourTest fc.setThreshold(12.5f); fc.setBelowThreshold(true); expected = String.format( - "domain\tscore|%s|%s|noValueMax|12.0|25.0|below|12.5", - greenHex, redHex); + "domain\tscore|%s|%s|noValueMax|12.0|25.0|below|12.5", greenHex, + redHex); assertEquals(expected, fc.toJalviewFormat("domain")); /* @@ -454,8 +408,8 @@ public class FeatureColourTest /* * simple colour by hex code */ - fc = FeatureColour.parseJalviewFeatureColour(Format - .getHexString(Color.RED)); + fc = FeatureColour + .parseJalviewFeatureColour(Format.getHexString(Color.RED)); assertTrue(fc.isSimpleColour()); assertEquals(Color.RED, fc.getColour()); @@ -687,8 +641,9 @@ public class FeatureColourTest * graduated colour based on attribute value for AF * given a min-max range of 0-100 */ - FeatureColour fc = new FeatureColour(new Color(50, 100, 150), - new Color(150, 200, 250), Color.yellow, 0f, 100f); + FeatureColour fc = new FeatureColour(Color.white, + new Color(50, 100, 150), new Color(150, 200, 250), Color.yellow, + 0f, 100f); String attName = "AF"; fc.setAttributeName(attName); @@ -713,6 +668,48 @@ public class FeatureColourTest 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 + } + /** * Test description of feature colour suitable for a tooltip */ @@ -727,14 +724,14 @@ public class FeatureColourTest 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) */ @@ -742,7 +739,7 @@ public class FeatureColourTest fc.setColourByLabel(true); fc.setAttributeName("CLIN_SIG"); assertEquals("By CLIN_SIG", fc.getDescription()); - + /* * colour by label (above score threshold) */ @@ -751,47 +748,41 @@ public class FeatureColourTest fc.setAutoScaled(false); fc.setThreshold(12.5f); fc.setAboveThreshold(true); - assertEquals("By Label (Score > 12.5)", - fc.getDescription()); - + 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()); - + 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()); - + assertEquals("By CSQ:Consequence (Score < 12.5)", fc.getDescription()); + /* * graduated colour by score, no threshold */ - fc = new FeatureColour(Color.GREEN, Color.RED, 12f, 25f); + fc = new FeatureColour(null, Color.GREEN, Color.RED, null, 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()); - + 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()); + assertEquals("By Score (> 12.5)", fc.getDescription()); /* * graduated colour by attribute, no threshold @@ -800,13 +791,12 @@ public class FeatureColourTest 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()); + assertEquals("By CSQ:AF (> 12.5)", fc.getDescription()); } }