From 310fc4091cce0d48f80796fd0ce89dcf0e624ccd Mon Sep 17 00:00:00 2001 From: kiramt Date: Wed, 20 Sep 2017 16:14:15 +0100 Subject: [PATCH] JAL-2674 Transferred updated unit tests from first 2674 branch --- test/jalview/datamodel/HiddenColumnsTest.java | 727 +++++++++++++++++++++++-- 1 file changed, 675 insertions(+), 52 deletions(-) diff --git a/test/jalview/datamodel/HiddenColumnsTest.java b/test/jalview/datamodel/HiddenColumnsTest.java index 7c88d71..1aec1d3 100644 --- a/test/jalview/datamodel/HiddenColumnsTest.java +++ b/test/jalview/datamodel/HiddenColumnsTest.java @@ -27,7 +27,9 @@ import static org.testng.AssertJUnit.assertTrue; import jalview.analysis.AlignmentGenerator; import jalview.gui.JvOptionPane; +import jalview.util.Comparison; +import java.util.ArrayList; import java.util.Arrays; import java.util.BitSet; import java.util.List; @@ -132,7 +134,7 @@ public class HiddenColumnsTest // test that without hidden columns, findColumnNToLeft returns // position n to left of provided position - int pos = cs.subtractVisibleColumns(3, 10); + long pos = cs.subtractVisibleColumns(3, 10); assertEquals(7, pos); // 0 returns same position @@ -185,20 +187,33 @@ public class HiddenColumnsTest public void testGetVisibleContigs() { HiddenColumns cs = new HiddenColumns(); + + int[] visible = cs.getVisibleContigs(3, 10); + assertEquals("[]", Arrays.toString(visible)); + cs.hideColumns(3, 6); cs.hideColumns(8, 9); cs.hideColumns(12, 12); - // start position is inclusive, end position exclusive: - int[] visible = cs.getVisibleContigs(1, 13); + // Test both ends visible region + + // start position is inclusive, end position exclusive + visible = cs.getVisibleContigs(1, 13); assertEquals("[1, 2, 7, 7, 10, 11]", Arrays.toString(visible)); + // Test start hidden, end visible visible = cs.getVisibleContigs(4, 14); assertEquals("[7, 7, 10, 11, 13, 13]", Arrays.toString(visible)); + // Test start hidden, end hidden visible = cs.getVisibleContigs(3, 10); assertEquals("[7, 7]", Arrays.toString(visible)); + // Test start visible, end hidden + visible = cs.getVisibleContigs(0, 13); + assertEquals("[0, 2, 7, 7, 10, 11]", Arrays.toString(visible)); + + // Test empty result visible = cs.getVisibleContigs(4, 6); assertEquals("[]", Arrays.toString(visible)); } @@ -263,19 +278,17 @@ public class HiddenColumnsTest // no hidden columns assertEquals( - Arrays.toString(new int[] { seq.findIndex(seq.getStart()) - 1, - seq.findIndex(seq.getEnd()) - 1, seq.getStart(), - seq.getEnd(), seq.findIndex(seq.getStart()) - 1, - seq.findIndex(seq.getEnd()) - 1 }), + Arrays.toString(new int[] + { seq.findIndex(seq.getStart()) - 1, seq.findIndex(seq.getStart()) - 1, + seq.findIndex(seq.getEnd()) - 1 }), Arrays.toString(cs.locateVisibleBoundsOfSequence(seq))); // hidden column on gap after end of sequence - should not affect bounds colsel.hideSelectedColumns(13, al.getHiddenColumns()); assertEquals( - Arrays.toString(new int[] { seq.findIndex(seq.getStart()) - 1, - seq.findIndex(seq.getEnd()) - 1, seq.getStart(), - seq.getEnd(), seq.findIndex(seq.getStart()) - 1, - seq.findIndex(seq.getEnd()) - 1 }), + Arrays.toString(new int[] + { seq.findIndex(seq.getStart()) - 1, seq.findIndex(seq.getStart()) - 1, + seq.findIndex(seq.getEnd()) - 1 }), Arrays.toString(cs.locateVisibleBoundsOfSequence(seq))); cs.revealAllHiddenColumns(colsel); @@ -283,10 +296,9 @@ public class HiddenColumnsTest // one colsel.hideSelectedColumns(0, al.getHiddenColumns()); assertEquals( - Arrays.toString(new int[] { seq.findIndex(seq.getStart()) - 2, - seq.findIndex(seq.getEnd()) - 2, seq.getStart(), - seq.getEnd(), seq.findIndex(seq.getStart()) - 1, - seq.findIndex(seq.getEnd()) - 1 }), + Arrays.toString(new int[] + { seq.findIndex(seq.getStart()) - 2, seq.findIndex(seq.getStart()) - 1, + seq.findIndex(seq.getEnd()) - 1 }), Arrays.toString(cs.locateVisibleBoundsOfSequence(seq))); cs.revealAllHiddenColumns(colsel); @@ -294,11 +306,14 @@ public class HiddenColumnsTest cs.hideColumns(1, 3); cs.hideColumns(6, 11); assertEquals("-D", - cs.getVisibleSequenceStrings(0, 5, new SequenceI[] { seq })[0]); + cs.getVisibleSequenceStrings(0, 5, new SequenceI[] + { seq })[0]); + assertEquals( - Arrays.toString(new int[] { 1, 1, 3, 3, - seq.findIndex(seq.getStart()) - 1, - seq.findIndex(seq.getEnd()) - 1 }), + Arrays.toString( + new int[] + { 1, seq.findIndex(seq.getStart()) - 1, + seq.findIndex(seq.getEnd()) - 1 }), Arrays.toString(cs.locateVisibleBoundsOfSequence(seq))); cs.revealAllHiddenColumns(colsel); @@ -306,26 +321,193 @@ public class HiddenColumnsTest // containing sequence cs.hideColumns(1, 11); assertEquals( - Arrays.toString(new int[] { 0, 1, 0, 0, - seq.findIndex(seq.getStart()) - 1, - seq.findIndex(seq.getEnd()) - 1 }), + Arrays.toString( + new int[] + { 0, seq.findIndex(seq.getStart()) - 1, + seq.findIndex(seq.getEnd()) - 1 }), Arrays.toString(cs.locateVisibleBoundsOfSequence(seq))); + cs.revealAllHiddenColumns(colsel); + cs.hideColumns(0, 15); + assertEquals(Arrays + .toString(new int[] + { 0, seq.findIndex(seq.getStart()) - 1, + seq.findIndex(seq.getEnd()) - 1 }), + Arrays.toString(cs.locateVisibleBoundsOfSequence(seq))); + + SequenceI seq2 = new Sequence("RefSeq2", "-------A-SD-ASD--E---"); + + cs.revealAllHiddenColumns(colsel); + cs.hideColumns(7, 17); + assertEquals( + Arrays.toString( + new int[] + { 0, seq2.findIndex(seq2.getStart()) - 1, + seq2.findIndex(seq2.getEnd()) - 1 }), + Arrays.toString(cs.locateVisibleBoundsOfSequence(seq2))); + + cs.revealAllHiddenColumns(colsel); + cs.hideColumns(3, 17); + assertEquals( + Arrays.toString( + new int[] + { 0, seq2.findIndex(seq2.getStart()) - 1, + seq2.findIndex(seq2.getEnd()) - 1 }), + Arrays.toString(cs.locateVisibleBoundsOfSequence(seq2))); + + cs.revealAllHiddenColumns(colsel); + cs.hideColumns(3, 19); + assertEquals( + Arrays.toString( + new int[] + { 0, seq2.findIndex(seq2.getStart()) - 1, + seq2.findIndex(seq2.getEnd()) - 1 }), + Arrays.toString(cs.locateVisibleBoundsOfSequence(seq2))); + + cs.revealAllHiddenColumns(colsel); + cs.hideColumns(0, 0); + int[] test = cs.locateVisibleBoundsOfSequence(seq); + assertEquals(Arrays.toString(new int[] { 0, 1, 11 }), + Arrays.toString(test)); + + cs.revealAllHiddenColumns(colsel); + cs.hideColumns(0, 1); + test = cs.locateVisibleBoundsOfSequence(seq); + assertEquals(Arrays.toString(new int[] { 1, 1, 11 }), + Arrays.toString(test)); + + cs.revealAllHiddenColumns(colsel); + cs.hideColumns(0, 2); + test = cs.locateVisibleBoundsOfSequence(seq); + assertEquals(Arrays.toString(new int[] { 0, 1, 11 }), + Arrays.toString(test)); + + cs.revealAllHiddenColumns(colsel); + cs.hideColumns(1, 1); + test = cs.locateVisibleBoundsOfSequence(seq); + assertEquals(Arrays.toString(new int[] { 2, 1, 11 }), + Arrays.toString(test)); + + cs.revealAllHiddenColumns(colsel); + cs.hideColumns(1, 2); + test = cs.locateVisibleBoundsOfSequence(seq); + assertEquals(Arrays.toString(new int[] { 1, 1, 11 }), + Arrays.toString(test)); + + cs.revealAllHiddenColumns(colsel); + cs.hideColumns(1, 3); + test = cs.locateVisibleBoundsOfSequence(seq); + assertEquals(Arrays.toString(new int[] { 1, 1, 11 }), + Arrays.toString(test)); + + cs.revealAllHiddenColumns(colsel); + cs.hideColumns(0, 2); + cs.hideColumns(5, 6); + test = cs.locateVisibleBoundsOfSequence(seq); + assertEquals(Arrays.toString(new int[] { 0, 1, 11 }), + Arrays.toString(test)); + + cs.revealAllHiddenColumns(colsel); + cs.hideColumns(0, 2); + cs.hideColumns(5, 6); + cs.hideColumns(9, 10); + test = cs.locateVisibleBoundsOfSequence(seq); + assertEquals(Arrays.toString(new int[] { 0, 1, 11 }), + Arrays.toString(test)); + + cs.revealAllHiddenColumns(colsel); + cs.hideColumns(0, 2); + cs.hideColumns(7, 11); + test = cs.locateVisibleBoundsOfSequence(seq); + assertEquals(Arrays.toString(new int[] { 0, 1, 11 }), + Arrays.toString(test)); + + cs.revealAllHiddenColumns(colsel); + cs.hideColumns(2, 4); + cs.hideColumns(7, 11); + test = cs.locateVisibleBoundsOfSequence(seq); + assertEquals(Arrays.toString(new int[] { 1, 1, 11 }), + Arrays.toString(test)); + + cs.revealAllHiddenColumns(colsel); + cs.hideColumns(2, 4); + cs.hideColumns(7, 12); + test = cs.locateVisibleBoundsOfSequence(seq); + assertEquals(Arrays.toString(new int[] { 1, 1, 11 }), + Arrays.toString(test)); + + cs.revealAllHiddenColumns(colsel); + cs.hideColumns(1, 11); + test = cs.locateVisibleBoundsOfSequence(seq); + assertEquals(Arrays.toString(new int[] { 0, 1, 11 }), + Arrays.toString(test)); + + cs.revealAllHiddenColumns(colsel); + cs.hideColumns(0, 12); + test = cs.locateVisibleBoundsOfSequence(seq); + assertEquals(Arrays.toString(new int[] { 0, 1, 11 }), + Arrays.toString(test)); + + cs.revealAllHiddenColumns(colsel); + cs.hideColumns(0, 4); + cs.hideColumns(6, 12); + test = cs.locateVisibleBoundsOfSequence(seq); + assertEquals(Arrays.toString(new int[] { 0, 1, 11 }), + Arrays.toString(test)); + + cs.revealAllHiddenColumns(colsel); + cs.hideColumns(0, 1); + cs.hideColumns(3, 12); + test = cs.locateVisibleBoundsOfSequence(seq); + assertEquals(Arrays.toString(new int[] { 0, 1, 11 }), + Arrays.toString(test)); + + // These tests cover different behaviour to original + // locateVisibleBoundsOfSequence + // Previously first values of each were 3,9 and 6 respectively. + cs.revealAllHiddenColumns(colsel); + cs.hideColumns(3, 14); + cs.hideColumns(17, 19); + assertEquals( + Arrays.toString( + new int[] + { 3, seq2.findIndex(seq2.getStart()) - 1, + seq2.findIndex(seq2.getEnd()) - 1 }), + Arrays.toString(cs.locateVisibleBoundsOfSequence(seq2))); + + cs.revealAllHiddenColumns(colsel); + cs.hideColumns(3, 7); + cs.hideColumns(9, 14); + cs.hideColumns(17, 19); + assertEquals( + Arrays.toString( + new int[] + { 9, seq2.findIndex(seq2.getStart()) - 1, + seq2.findIndex(seq2.getEnd()) - 1 }), + Arrays.toString(cs.locateVisibleBoundsOfSequence(seq2))); + + cs.revealAllHiddenColumns(colsel); + cs.hideColumns(0, 1); + cs.hideColumns(3, 4); + cs.hideColumns(6, 8); + cs.hideColumns(10, 12); + test = cs.locateVisibleBoundsOfSequence(seq); + assertEquals(Arrays.toString(new int[] { 6, 1, 11 }), + Arrays.toString(test)); + } @Test(groups = { "Functional" }) public void testLocateVisibleBoundsPathologicals() { // test some pathological cases we missed - AlignmentI al = new Alignment(new SequenceI[] { new Sequence( - "refseqGaptest", "KTDVTI----------NFI-----G----L") }); + AlignmentI al = new Alignment( + new SequenceI[] + { new Sequence("refseqGaptest", "KTDVTI----------NFI-----G----L") }); HiddenColumns cs = new HiddenColumns(); cs.hideInsertionsFor(al.getSequenceAt(0)); - assertEquals( - "G", - "" - + al.getSequenceAt(0).getCharAt( - cs.adjustForHiddenColumns(9))); + assertEquals("G", "" + + al.getSequenceAt(0).getCharAt(cs.adjustForHiddenColumns(9))); } @@ -427,8 +609,10 @@ public class HiddenColumnsTest cs.hideColumns(5, 8); colsel.addElement(10); cs.revealHiddenColumns(5, colsel); - // hidden columns list now null but getter returns empty list: - assertTrue(cs.getHiddenColumnsCopy().isEmpty()); + + // hiddenColumns now empty + assertEquals(0, cs.getSize()); + // revealed columns are marked as selected (added to selection): assertEquals("[10, 5, 6, 7, 8]", colsel.getSelected().toString()); @@ -436,30 +620,34 @@ public class HiddenColumnsTest colsel = new ColumnSelection(); cs = new HiddenColumns(); cs.hideColumns(5, 8); - List hidden = cs.getHiddenColumnsCopy(); + + int prevSize = cs.getSize(); cs.revealHiddenColumns(6, colsel); - assertEquals(hidden.size(), cs.getHiddenColumnsCopy().size()); + assertEquals(prevSize, cs.getSize()); assertTrue(colsel.getSelected().isEmpty()); } @Test(groups = { "Functional" }) public void testRevealAllHiddenColumns() { - HiddenColumns cs = new HiddenColumns(); + HiddenColumns hidden = new HiddenColumns(); ColumnSelection colsel = new ColumnSelection(); - cs.hideColumns(5, 8); - cs.hideColumns(2, 3); + hidden.hideColumns(5, 8); + hidden.hideColumns(2, 3); colsel.addElement(11); colsel.addElement(1); - cs.revealAllHiddenColumns(colsel); + hidden.revealAllHiddenColumns(colsel); /* * revealing hidden columns adds them (in order) to the (unordered) * selection list */ - assertTrue(cs.getHiddenColumnsCopy().isEmpty()); - assertEquals("[11, 1, 2, 3, 5, 6, 7, 8]", colsel.getSelected() - .toString()); + + // hiddenColumns now empty + assertEquals(0, hidden.getSize()); + + assertEquals("[11, 1, 2, 3, 5, 6, 7, 8]", + colsel.getSelected().toString()); } @Test(groups = { "Functional" }) @@ -581,7 +769,7 @@ public class HiddenColumnsTest } @Test(groups = { "Functional" }) - public void testGetBitset() + public void testMarkHiddenRegions() { BitSet toMark, fromMark; long seed = -3241532; @@ -589,8 +777,9 @@ public class HiddenColumnsTest for (int n = 0; n < 1000; n++) { // create a random bitfield - toMark = BitSet.valueOf(new long[] { number.nextLong(), - number.nextLong(), number.nextLong() }); + toMark = BitSet + .valueOf(new long[] + { number.nextLong(), number.nextLong(), number.nextLong() }); toMark.set(n * number.nextInt(10), n * (25 + number.nextInt(25))); HiddenColumns hc = new HiddenColumns(); hc.hideMarkedBits(toMark); @@ -637,7 +826,7 @@ public class HiddenColumnsTest } @Test(groups = "Functional") - public void getVisibleStartAndEndIndexTest() + public void testGetVisibleStartAndEndIndexTest() { Sequence seq = new Sequence("testSeq", "ABCDEFGHIJKLMNOPQRSTUVWXYZ"); AlignmentI align = new Alignment(new SequenceI[] { seq }); @@ -677,7 +866,7 @@ public class HiddenColumnsTest hc.hideColumns(10, 10); hc.hideColumns(14, 15); - result = hc.getRegionWithEdgeAtRes(3); + result = hc.getRegionWithEdgeAtRes(2); assertEquals(3, result[0]); assertEquals(7, result[1]); @@ -687,6 +876,17 @@ public class HiddenColumnsTest result = hc.getRegionWithEdgeAtRes(6); assertNull(result); + + result = hc.getRegionWithEdgeAtRes(0); + assertNull(result); + + result = hc.getRegionWithEdgeAtRes(7); + assertEquals(14, result[0]); + assertEquals(15, result[1]); + + result = hc.getRegionWithEdgeAtRes(8); + assertEquals(14, result[0]); + assertEquals(15, result[1]); } @Test(groups = "Functional") @@ -695,7 +895,7 @@ public class HiddenColumnsTest // 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); + AlignmentI al = gen.generate(25, 10, 1234, 0, 0); // get the profileseq SequenceI profileseq = al.getSequenceAt(0); @@ -704,7 +904,7 @@ public class HiddenColumnsTest 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; @@ -716,19 +916,442 @@ public class HiddenColumnsTest false); // confirm that original contigs are as expected - int[] oldcontigs = hidden.getVisibleContigs(0, 20); - int[] testcontigs = { 0, 14, 18, 19 }; + int[] oldcontigs = hidden.getVisibleContigs(0, 25); + int[] testcontigs = { 0, 14, 18, 24 }; 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); + int[] newcontigs = result.getVisibleContigs(0, 25); testcontigs[1] = 10; testcontigs[2] = 14; assertTrue(Arrays.equals(newcontigs, testcontigs)); - + + // confirm the alignment has been changed so that the other sequences have + // gaps inserted where the columns are hidden + assertFalse(Comparison.isGap(al.getSequenceAt(1).getSequence()[10])); + assertTrue(Comparison.isGap(al.getSequenceAt(1).getSequence()[11])); + assertTrue(Comparison.isGap(al.getSequenceAt(1).getSequence()[12])); + assertTrue(Comparison.isGap(al.getSequenceAt(1).getSequence()[13])); + assertFalse(Comparison.isGap(al.getSequenceAt(1).getSequence()[14])); + + } + + @Test(groups = "Functional") + public void testPropagateInsertionsOverlap() + { + // test propagateInsertions where gaps and hiddenColumns overlap + + // 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); + + // hide columns so that some overlap with the gaps + HiddenColumns hidden = new HiddenColumns(); + hidden.hideColumns(7, 10); + + 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, 6, 11, 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] = 4; + testcontigs[2] = 7; + assertTrue(Arrays.equals(newcontigs, testcontigs)); + + // confirm the alignment has been changed so that the other sequences have + // gaps inserted where the columns are hidden + assertFalse(Comparison.isGap(al.getSequenceAt(1).getSequence()[4])); + assertTrue(Comparison.isGap(al.getSequenceAt(1).getSequence()[5])); + assertTrue(Comparison.isGap(al.getSequenceAt(1).getSequence()[6])); + assertFalse(Comparison.isGap(al.getSequenceAt(1).getSequence()[7])); } + + @Test(groups = "Functional") + public void testHasHiddenColumns() + { + HiddenColumns h = new HiddenColumns(); + + // new HiddenColumns2 has no hidden cols + assertFalse(h.hasHiddenColumns()); + + // some columns hidden, returns true + h.hideColumns(5, 10); + assertTrue(h.hasHiddenColumns()); + + // reveal columns, no hidden cols again + ColumnSelection sel = new ColumnSelection(); + h.revealAllHiddenColumns(sel); + assertFalse(h.hasHiddenColumns()); + } + + @Test(groups = "Functional") + public void testHasManyHiddenColumns() + { + HiddenColumns h = new HiddenColumns(); + + // new HiddenColumns2 has no hidden cols + assertFalse(h.hasManyHiddenColumns()); + + // one set of columns hidden, returns false + h.hideColumns(5, 10); + assertFalse(h.hasManyHiddenColumns()); + + // two sets hidden, returns true + h.hideColumns(15, 17); + assertTrue(h.hasManyHiddenColumns()); + + // back to one block, asserts false + h.hideColumns(11, 14); + assertFalse(h.hasManyHiddenColumns()); + } + + @Test(groups = "Functional") + public void testAdjustForHiddenColumns() + { + HiddenColumns h = new HiddenColumns(); + // returns input value when there are no hidden columns + assertEquals(10, h.adjustForHiddenColumns(10)); + + h.hideColumns(20, 30); + assertEquals(10, h.adjustForHiddenColumns(10)); + assertEquals(20 + 11, h.adjustForHiddenColumns(20)); + assertEquals(35 + 11, h.adjustForHiddenColumns(35)); + + h.hideColumns(5, 7); + assertEquals(10 + 3, h.adjustForHiddenColumns(10)); + assertEquals(20 + 14, h.adjustForHiddenColumns(20)); + assertEquals(35 + 14, h.adjustForHiddenColumns(35)); + + ColumnSelection sel = new ColumnSelection(); + h.revealAllHiddenColumns(sel); + h.hideColumns(0, 1); + assertEquals(4, h.adjustForHiddenColumns(2)); + } + + /*@Test(groups = "Functional") + public void testCompensateForEdit() + { + HiddenColumns2 h = new HiddenColumns2(); + + ColumnSelection sel = new ColumnSelection(); + assertNull(h.compensateForEdit(10, 3, sel)); + + h.hideColumns(3, 4); + List result = h.compensateForEdit(10, 3, sel); + assertEquals(0, result.size()); + + // edit partially overlapping hidden + + h = new HiddenColumns2(); + h.hideColumns(15, 17); + result = h.compensateForEdit(10, 6, sel); + assertEquals(0, result.size()); + + HiddenColumns2 h2 = new HiddenColumns2(); + h2.hideColumns(9, 11); + assertTrue(h.equals(h2)); + + // edit fully overlapping hidden + + h = new HiddenColumns2(); + h.hideColumns(15, 17); + result = h.compensateForEdit(10, 8, sel); + assertEquals(result.get(0)[0], 15); + assertEquals(result.get(0)[1], 17); + assertFalse(h.hasHiddenColumns()); + + // edit at start + + h = new HiddenColumns2(); + h.hideColumns(0, 3); + result = h.compensateForEdit(0, 4, sel); + assertEquals(0, result.size()); + assertEquals(sel.getSelected().size(), 4); + assertFalse(h.hasHiddenColumns()); + }*/ + + /*@Test(groups = "Functional") + public void testCompensateForDelEdits() + { + HiddenColumns2 h = new HiddenColumns2(); + HiddenColumns2 h2 = new HiddenColumns2(); + + h.compensateForDelEdits(10, 3); + assertFalse(h.hasHiddenColumns()); + + h = new HiddenColumns2(); + h.hideColumns(3, 4); + h.compensateForDelEdits(10, 3); + h2.hideColumns(3, 4); + assertTrue(h.equals(h2)); + + h = new HiddenColumns2(); + h.hideColumns(15, 17); + h.compensateForDelEdits(10, 6); + h2 = new HiddenColumns2(); + h2.hideColumns(9, 11); + assertTrue(h.equals(h2)); + + h = new HiddenColumns2(); + h.hideColumns(15, 17); + h.compensateForDelEdits(10, 8); + h2 = new HiddenColumns2(); + h2.hideColumns(7, 9); + assertTrue(h.equals(h2)); + + h = new HiddenColumns2(); + h.hideColumns(0, 3); + h.compensateForDelEdits(0, 4); + h2 = new HiddenColumns2(); + h2.hideColumns(0, 0); + assertTrue(h.equals(h2)); + }*/ + + @Test(groups = "Functional") + public void testGetHiddenBoundaryLeft() + { + HiddenColumns h = new HiddenColumns(); + + // returns same value if no hidden cols + assertEquals(3, h.getHiddenBoundaryLeft(3)); + + h.hideColumns(5, 10); + assertEquals(10, h.getHiddenBoundaryLeft(15)); + assertEquals(3, h.getHiddenBoundaryLeft(3)); + assertEquals(7, h.getHiddenBoundaryLeft(7)); + + h.hideColumns(15, 20); + assertEquals(10, h.getHiddenBoundaryLeft(15)); + assertEquals(20, h.getHiddenBoundaryLeft(21)); + } + + @Test(groups = "Functional") + public void testGetHiddenBoundaryRight() + { + HiddenColumns h = new HiddenColumns(); + + // returns same value if no hidden cols + assertEquals(3, h.getHiddenBoundaryRight(3)); + + h.hideColumns(5, 10); + assertEquals(5, h.getHiddenBoundaryRight(3)); + assertEquals(15, h.getHiddenBoundaryRight(15)); + assertEquals(7, h.getHiddenBoundaryRight(7)); + + h.hideColumns(15, 20); + assertEquals(15, h.getHiddenBoundaryRight(7)); + assertEquals(15, h.getHiddenBoundaryRight(14)); + } + + @Test(groups = "Functional") + public void testGetHiddenColumnsCopy() + { + HiddenColumns h = new HiddenColumns(); + ArrayList result = h.getHiddenColumnsCopy(); + assertTrue(result.isEmpty()); + + h.hideColumns(5, 10); + result = h.getHiddenColumnsCopy(); + assertEquals(1, result.size()); + assertEquals(5, result.get(0)[0]); + assertEquals(10, result.get(0)[1]); + + h.hideColumns(22, 23); + result = h.getHiddenColumnsCopy(); + assertEquals(2, result.size()); + assertEquals(5, result.get(0)[0]); + assertEquals(10, result.get(0)[1]); + assertEquals(22, result.get(1)[0]); + assertEquals(23, result.get(1)[1]); + + // test for only one hidden region at start of alignment + ColumnSelection sel = new ColumnSelection(); + h.revealAllHiddenColumns(sel); + h.hideColumns(0, 1); + result = h.getHiddenColumnsCopy(); + assertEquals(1, result.size()); + assertEquals(0, result.get(0)[0]); + assertEquals(1, result.get(0)[1]); + } + + @Test(groups = "Functional") + public void testGetVisibleSequenceStrings() + { + HiddenColumns h = new HiddenColumns(); + SequenceI seq1 = new Sequence("TEST1", "GALMFWKQESPVICYHRNDT"); + SequenceI seq2 = new Sequence("TEST2", "VICYHRNDTGA"); + SequenceI[] seqs = new SequenceI[2]; + seqs[0] = seq1; + seqs[1] = seq2; + String[] result = h.getVisibleSequenceStrings(5, 10, seqs); + assertEquals(2, result.length); + assertEquals("WKQES", result[0]); + assertEquals("RNDTG", result[1]); + + h.hideColumns(6, 8); + result = h.getVisibleSequenceStrings(5, 10, seqs); + assertEquals(2, result.length); + assertEquals("WS", result[0]); + assertEquals("RG", result[1]); + + SequenceI seq = new Sequence("RefSeq", "-A-SD-ASD--E---"); + ColumnSelection sel = new ColumnSelection(); + h.revealAllHiddenColumns(sel); + h.hideColumns(1, 3); + h.hideColumns(6, 11); + assertEquals("-D", + h.getVisibleSequenceStrings(0, 5, new SequenceI[] + { seq })[0]); + } + + @Test(groups = "Functional") + public void testHideInsertionsFor() + { + HiddenColumns h = new HiddenColumns(); + HiddenColumns h2 = new HiddenColumns(); + SequenceI seq1 = new Sequence("TEST1", "GAL---MFW-KQESPVICY--HRNDT"); + SequenceI seq2 = new Sequence("TEST1", "GALMFWKQESPVICYHRNDT"); + + h.hideInsertionsFor(seq2); + assertTrue(h.equals(h2)); + + h.hideInsertionsFor(seq1); + h2.hideColumns(3, 5); + h2.hideColumns(9, 9); + h2.hideColumns(19, 20); + assertTrue(h.equals(h2)); + } + + @Test(groups = "Functional") + public void testHideMarkedBits() + { + HiddenColumns h = new HiddenColumns(); + HiddenColumns h2 = new HiddenColumns(); + + BitSet tohide = new BitSet(21); + h.hideMarkedBits(tohide); + assertTrue(h.equals(h2)); + + // NB in hideMarkedBits, the last bit is not set to hidden + tohide.set(3, 6); + tohide.set(9); + tohide.set(19, 21); + h.hideMarkedBits(tohide); + + h2.hideColumns(3, 5); + h2.hideColumns(9, 9); + h2.hideColumns(19, 20); + assertTrue(h.equals(h2)); + } + + @Test(groups = "Functional") + public void testMakeVisibleAnnotation() + { + HiddenColumns h = new HiddenColumns(); + Annotation[] anns = new Annotation[] { null, null, new Annotation(1), + new Annotation(2), new Annotation(3), null, null, new Annotation(4), + new Annotation(5), new Annotation(6), new Annotation(7), + new Annotation(8) }; + AlignmentAnnotation ann = new AlignmentAnnotation("an", "some an", + anns); + + // without hidden cols, just truncates + h.makeVisibleAnnotation(3, 5, ann); + assertEquals(3, ann.annotations.length); + assertEquals(2.0f, ann.annotations[0].value); + assertEquals(3.0f, ann.annotations[1].value); + assertNull(ann.annotations[2]); + + anns = new Annotation[] { null, null, new Annotation(1), + new Annotation(2), new Annotation(3), null, null, new Annotation(4), + new Annotation(5), new Annotation(6), new Annotation(7), + new Annotation(8) }; + ann = new AlignmentAnnotation("an", "some an", anns); + h.hideColumns(4, 7); + h.makeVisibleAnnotation(1, 9, ann); + assertEquals(5, ann.annotations.length); + assertNull(ann.annotations[0]); + assertEquals(1.0f, ann.annotations[1].value); + assertEquals(2.0f, ann.annotations[2].value); + assertEquals(5.0f, ann.annotations[3].value); + assertEquals(6.0f, ann.annotations[4].value); + + anns = new Annotation[] { null, null, new Annotation(1), + new Annotation(2), new Annotation(3), null, null, new Annotation(4), + new Annotation(5), new Annotation(6), new Annotation(7), + new Annotation(8) }; + ann = new AlignmentAnnotation("an", "some an", anns); + h.hideColumns(1, 2); + h.makeVisibleAnnotation(1, 9, ann); + assertEquals(3, ann.annotations.length); + assertEquals(2.0f, ann.annotations[0].value); + assertEquals(5.0f, ann.annotations[1].value); + assertEquals(6.0f, ann.annotations[2].value); + } + + @Test(groups = "Functional") + public void testSubtractVisibleColumns() + { + HiddenColumns h = new HiddenColumns(); + int result = h.subtractVisibleColumns(1, 10); + assertEquals(9, result); + + h.hideColumns(7, 9); + result = h.subtractVisibleColumns(4, 10); + assertEquals(3, result); + + h.hideColumns(14, 15); + result = h.subtractVisibleColumns(4, 10); + assertEquals(3, result); + + result = h.subtractVisibleColumns(10, 17); + assertEquals(2, result); + + result = h.subtractVisibleColumns(1, 7); + assertEquals(5, result); + + result = h.subtractVisibleColumns(1, 8); + assertEquals(5, result); + + result = h.subtractVisibleColumns(3, 15); + assertEquals(10, result); + + ColumnSelection sel = new ColumnSelection(); + h.revealAllHiddenColumns(sel); + h.hideColumns(0, 30); + result = h.subtractVisibleColumns(31, 13); + assertEquals(-18, result); + + result = h.subtractVisibleColumns(31, 0); + assertEquals(-31, result); + + } + } -- 1.7.10.2