JAL-2597 Fix and unit test
[jalview.git] / test / jalview / datamodel / HiddenColumnsTest.java
index fbb354b..7c88d71 100644 (file)
@@ -689,4 +689,46 @@ public class HiddenColumnsTest
     assertNull(result);
   }
 
+  @Test(groups = "Functional")
+  public void testPropagateInsertions()
+  {
+    // create an alignment with no gaps - this will be the profile seq and other
+    // JPRED seqs
+    AlignmentGenerator gen = new AlignmentGenerator(false);
+    AlignmentI al = gen.generate(20, 10, 1234, 0, 0);
+
+    // get the profileseq
+    SequenceI profileseq = al.getSequenceAt(0);
+    SequenceI gappedseq = new Sequence(profileseq);
+    gappedseq.insertCharAt(5, al.getGapCharacter());
+    gappedseq.insertCharAt(6, al.getGapCharacter());
+    gappedseq.insertCharAt(7, al.getGapCharacter());
+    gappedseq.insertCharAt(8, al.getGapCharacter());
+    
+    // create an alignment view with the gapped sequence
+    SequenceI[] seqs = new SequenceI[1];
+    seqs[0] = gappedseq;
+    AlignmentI newal = new Alignment(seqs);
+    HiddenColumns hidden = new HiddenColumns();
+    hidden.hideColumns(15, 17);
+
+    AlignmentView view = new AlignmentView(newal, hidden, null, true, false,
+            false);
+
+    // confirm that original contigs are as expected
+    int[] oldcontigs = hidden.getVisibleContigs(0, 20);
+    int[] testcontigs = { 0, 14, 18, 19 };
+    assertTrue(Arrays.equals(oldcontigs, testcontigs));
+            
+    // propagate insertions
+    HiddenColumns result = HiddenColumns.propagateInsertions(profileseq, al,
+            view);
+
+    // confirm that the contigs have changed to account for the gaps
+    int[] newcontigs = result.getVisibleContigs(0, 20);
+    testcontigs[1] = 10;
+    testcontigs[2] = 14;
+    assertTrue(Arrays.equals(newcontigs, testcontigs));
+    
+  }
 }