From eb2c919a6ad59d6447fcba2597d044ac7ca749b8 Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Wed, 3 May 2017 17:35:47 +0100 Subject: [PATCH] JAL-2503 AlignmentAnnotation.isQuantitative() test --- src/jalview/datamodel/AlignmentAnnotation.java | 9 +++++ .../datamodel/AlignmentAnnotationTests.java | 42 ++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/src/jalview/datamodel/AlignmentAnnotation.java b/src/jalview/datamodel/AlignmentAnnotation.java index 6117baf..543958e 100755 --- a/src/jalview/datamodel/AlignmentAnnotation.java +++ b/src/jalview/datamodel/AlignmentAnnotation.java @@ -1494,4 +1494,13 @@ public class AlignmentAnnotation { return counter++; } + + /** + * + * @return true for rows that have a range of values in their annotation set + */ + public boolean isQuantitative() + { + return graphMin < graphMax; + } } diff --git a/test/jalview/datamodel/AlignmentAnnotationTests.java b/test/jalview/datamodel/AlignmentAnnotationTests.java index a2c6256..e47e9d6 100644 --- a/test/jalview/datamodel/AlignmentAnnotationTests.java +++ b/test/jalview/datamodel/AlignmentAnnotationTests.java @@ -28,6 +28,7 @@ import jalview.gui.JvOptionPane; import jalview.io.AppletFormatAdapter; import jalview.io.FileFormat; +import org.testng.Assert; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -293,4 +294,45 @@ public class AlignmentAnnotationTests ann.getDefaultRnaHelixSymbol(i)); } } + + public static Annotation newAnnotation(String ann) + { + float val = 0f; + try + { + val = Float.parseFloat(ann); + } catch (NumberFormatException q) + { + } + ; + return new Annotation(ann, ann, '\0', val); + } + + @Test(groups = { "Functional" }) + public void testIsQuantitative() + { + AlignmentAnnotation ann = null; + + ann = new AlignmentAnnotation("an", "some an", null); + Assert.assertFalse(ann.isQuantitative(), + "Empty annotation set should not be quantitative."); + + ann = new AlignmentAnnotation("an", "some an", new Annotation[] { + newAnnotation("4"), newAnnotation("1"), newAnnotation("1"), + newAnnotation("0.1"), newAnnotation("0.3") }); + Assert.assertTrue(ann.isQuantitative(), + "All numbers annotation set should be quantitative."); + + ann = new AlignmentAnnotation("an", "some an", new Annotation[] { + newAnnotation("E"), newAnnotation("E"), newAnnotation("E"), + newAnnotation("E"), newAnnotation("E") }); + Assert.assertFalse(ann.isQuantitative(), + "All 'E' annotation set should not be quantitative."); + + ann = new AlignmentAnnotation("an", "some an", new Annotation[] { + newAnnotation("E"), newAnnotation("1"), newAnnotation("2"), + newAnnotation("3"), newAnnotation("E") }); + Assert.assertTrue(ann.isQuantitative(), + "Mixed 'E' annotation set should be quantitative."); + } } -- 1.7.10.2