JAL-3081 unit tests for 'custom' (no) sort, sort autocalc only
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 14 Nov 2019 16:13:31 +0000 (16:13 +0000)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 14 Nov 2019 16:13:31 +0000 (16:13 +0000)
test/jalview/analysis/AnnotationSorterTest.java

index 7153f67..3277a16 100644 (file)
@@ -410,4 +410,78 @@ public class AnnotationSorterTest
             + " sequences and " + numAnns + " annotations took " + elapsed
             + "ms");
   }
+
+  /**
+   * Test that sort does nothing if sort order is CUSTOM (manually ordered
+   * annotations)
+   */
+  @Test(groups = { "Functional" })
+  public void testSort_custom()
+  {
+    // @formatter:off
+    anns[0].sequenceRef = al.getSequenceAt(1); anns[0].label = "label0";
+    anns[1].sequenceRef = al.getSequenceAt(3); anns[1].label = "structure";
+    anns[2].sequenceRef = al.getSequenceAt(3); anns[2].label = "iron";
+    anns[3].autoCalculated = true;             anns[3].label = "Quality";
+    anns[4].autoCalculated = true;             anns[4].label = "Consensus";
+    anns[5].sequenceRef = al.getSequenceAt(0); anns[5].label = "label5";
+    anns[6].sequenceRef = al.getSequenceAt(3); anns[6].label = "IRP";
+    // @formatter:on
+
+    /*
+     * showAutocalcAbove=true ignored if CUSTOM ordering
+     */
+    AnnotationSorter testee = new AnnotationSorter(al, true, false);
+    testee.sort(anns, SequenceAnnotationOrder.CUSTOM);
+    assertEquals("label0", anns[0].label); // all unchanged
+    assertEquals("structure", anns[1].label);
+    assertEquals("iron", anns[2].label);
+    assertEquals("Quality", anns[3].label);
+    assertEquals("Consensus", anns[4].label);
+    assertEquals("label5", anns[5].label);
+    assertEquals("IRP", anns[6].label);
+  }
+
+  /**
+   * Test of sorting only autocalculated annotations
+   */
+  @Test(groups = { "Functional" })
+  public void testSort_autocalcOnly()
+  {
+    // @formatter:off
+    anns[0].sequenceRef = al.getSequenceAt(1); anns[0].label = "label0";
+    anns[1].sequenceRef = al.getSequenceAt(3); anns[1].label = "structure";
+    anns[2].sequenceRef = al.getSequenceAt(3); anns[2].label = "iron";
+    anns[3].autoCalculated = true;             anns[3].label = "Quality";
+    anns[4].autoCalculated = true;             anns[4].label = "Consensus";
+    anns[5].sequenceRef = al.getSequenceAt(0); anns[5].label = "label5";
+    anns[6].sequenceRef = al.getSequenceAt(3); anns[6].label = "IRP";
+    // @formatter:on
+
+    /*
+     * showAutocalcAbove=true, autocalcOnly=true
+     */
+    AnnotationSorter testee = new AnnotationSorter(al, true, true);
+    testee.sort(anns, SequenceAnnotationOrder.LABEL_AND_SEQUENCE);
+    assertEquals("Quality", anns[0].label); // moved to top
+    assertEquals("Consensus", anns[1].label); // moved to top
+    assertEquals("label0", anns[2].label); // the rest unchanged
+    assertEquals("structure", anns[3].label);
+    assertEquals("iron", anns[4].label);
+    assertEquals("label5", anns[5].label);
+    assertEquals("IRP", anns[6].label);
+
+    /*
+     * showAutocalcAbove=false, autocalcOnly=true
+     */
+    testee = new AnnotationSorter(al, false, true);
+    testee.sort(anns, SequenceAnnotationOrder.LABEL_AND_SEQUENCE);
+    assertEquals("label0", anns[0].label); // unchanged
+    assertEquals("structure", anns[1].label);
+    assertEquals("iron", anns[2].label);
+    assertEquals("label5", anns[3].label);
+    assertEquals("IRP", anns[4].label);
+    assertEquals("Quality", anns[5].label); // moved to bottom
+    assertEquals("Consensus", anns[6].label); // moved to bottom
+  }
 }