+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
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()
{
}
@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()
{
FeatureColour fc = new FeatureColour(Color.RED);
- assertEquals(Color.RED, fc.getColor(new SequenceFeature()));
+ assertEquals(Color.RED,
+ fc.getColor(new SequenceFeature("Cath", "", 1, 2, 0f, null)));
}
@Test(groups = { "Functional" })
fc.setColourByLabel(true);
SequenceFeature sf = new SequenceFeature("type", "desc", 0, 20, 1f,
null);
- Color expected = UserColourScheme.createColourFromName("desc");
+ Color expected = ColorUtils.createColourFromName("desc");
assertEquals(expected, fc.getColor(sf));
}
@Test(groups = { "Functional" })
public void testGetColor_Graduated()
{
- // graduated colour from score 0 to 100, gray(128, 128, 128) to red(255, 0, 0)
+ // graduated colour from score 0 to 100, gray(128, 128, 128) to red(255, 0,
+ // 0)
FeatureColour fc = new FeatureColour(Color.GRAY, Color.RED, 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,
}
@Test(groups = { "Functional" })
- public void testGetColor_belowThreshold()
+ 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);
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(Color.white, fc.getColor(sf2));
fc.setAboveThreshold(true); // feature lies below threshold
- assertFalse(fc.isColored(sf));
- assertEquals(new Color(204, 204, 204), fc.getColor(sf));
+ assertNull(fc.getColor(sf));
+ assertEquals(Color.white, fc.getColor(sf2));
+
+ fc.setBelowThreshold(true);
+ fc.setThreshold(70f);
+ assertNull(fc.getColor(sf)); // feature score == threshold - hidden
+ assertEquals(Color.white, fc.getColor(sf2));
+ fc.setThreshold(69f);
+ assertNull(fc.getColor(sf)); // feature score > threshold - hidden
+ assertEquals(Color.white, fc.getColor(sf2));
}
/**
String redHex = Format.getHexString(Color.RED);
String hexColour = redHex;
assertEquals("domain\t" + hexColour, fc.toJalviewFormat("domain"));
-
+
/*
* colour by label (no threshold)
*/