+/*
+ * 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.datamodel;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.internal.junit.ArrayAsserts.assertArrayEquals;
import jalview.gui.AlignViewport;
+import jalview.gui.JvOptionPane;
import java.util.List;
+import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
@Test(singleThreaded = true)
public class HiddenSequencesTest
{
- static int SEQ_COUNT = 10;
+
+ @BeforeClass(alwaysRun = true)
+ public void setUpJvOptionPane()
+ {
+ JvOptionPane.setInteractiveMode(false);
+ JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
+ }
+
+ static int SEQ_COUNT = 25;
SequenceI[] seqs;
seqs = new SequenceI[SEQ_COUNT];
for (int i = 0; i < SEQ_COUNT; i++)
{
- // sequence lengths are 1, 2, ... 10
- seqs[i] = new Sequence("Seq" + i, "abcdefghijk".substring(0, i + 1));
+ // sequence lengths are 1, 2, ... 25
+ seqs[i] = new Sequence("Seq" + i,
+ "abcdefghijklmnopqrstuvwxy".substring(0, i + 1));
}
}
/*
* alignment is now seq0/2/3/4/7/8/9
*/
- assertEquals(7, al.getHeight());
+ assertEquals(SEQ_COUNT - 3, al.getHeight());
assertEquals(0, hs.adjustForHiddenSeqs(0));
assertEquals(2, hs.adjustForHiddenSeqs(1));
assertEquals(3, hs.adjustForHiddenSeqs(2));
{
AlignmentI al = new Alignment(seqs);
HiddenSequences hs = al.getHiddenSequences();
- for (int i = 0; i < SEQ_COUNT; i++)
+ int height = al.getHeight();
+ for (int i = 0; i < height; i++)
{
assertEquals(i, hs.findIndexWithoutHiddenSeqs(i));
}
/*
* alignment is now seq0/2/3/4/7/8/9
*/
- assertEquals(7, al.getHeight());
+ assertEquals(height - 3, al.getHeight());
assertEquals(0, hs.findIndexWithoutHiddenSeqs(0));
assertEquals(0, hs.findIndexWithoutHiddenSeqs(1));
assertEquals(1, hs.findIndexWithoutHiddenSeqs(2));
assertEquals(4, hs.findIndexWithoutHiddenSeqs(7));
assertEquals(5, hs.findIndexWithoutHiddenSeqs(8));
assertEquals(6, hs.findIndexWithoutHiddenSeqs(9));
+
+ /*
+ * hide first two sequences
+ */
+ hs.showAll(null);
+ hs.hideSequence(seqs[0]);
+ hs.hideSequence(seqs[1]);
+ assertEquals(-1, hs.findIndexWithoutHiddenSeqs(0));
+ assertEquals(-1, hs.findIndexWithoutHiddenSeqs(1));
+ for (int i = 2; i < height; i++)
+ {
+ assertEquals(i - 2, hs.findIndexWithoutHiddenSeqs(i));
+ }
+ }
+
+ /**
+ * Test the method that finds the visible row position a given distance before
+ * another row
+ */
+ @Test(groups = { "Functional" })
+ public void testFindIndexNFromRow()
+ {
+ AlignmentI al = new Alignment(seqs);
+ HiddenSequences hs = new HiddenSequences(al);
+
+ // test that without hidden rows, findIndexNFromRow returns
+ // position n above provided position
+ int pos = hs.subtractVisibleRows(3, 10);
+ assertEquals(7, pos);
+
+ // 0 returns same position
+ pos = hs.subtractVisibleRows(0, 10);
+ assertEquals(10, pos);
+
+ // overflow to top returns negative number
+ pos = hs.subtractVisibleRows(3, 0);
+ assertEquals(-3, pos);
+
+ // test that with hidden rows above result row
+ // behaviour is the same as above
+ hs.hideSequence(seqs[1]);
+ hs.hideSequence(seqs[2]);
+ hs.hideSequence(seqs[3]);
+
+ // position n above provided position
+ pos = hs.subtractVisibleRows(3, 10);
+ assertEquals(7, pos);
+
+ // 0 returns same position
+ pos = hs.subtractVisibleRows(0, 10);
+ assertEquals(10, pos);
+
+ // test with one set of hidden rows between start and required position
+ hs.hideSequence(seqs[12]);
+ hs.hideSequence(seqs[13]);
+ hs.hideSequence(seqs[14]);
+ hs.hideSequence(seqs[15]);
+ pos = hs.subtractVisibleRows(8, 17);
+ assertEquals(5, pos);
+
+ // test with two sets of hidden rows between start and required position
+ hs.hideSequence(seqs[20]);
+ hs.hideSequence(seqs[21]);
+ pos = hs.subtractVisibleRows(8, 23);
+ assertEquals(9, pos);
+
+ // repeat last 2 tests with no hidden columns to left of required position
+ hs.showAll(null);
+
+ // test with one set of hidden rows between start and required position
+ hs.hideSequence(seqs[12]);
+ hs.hideSequence(seqs[13]);
+ hs.hideSequence(seqs[14]);
+ hs.hideSequence(seqs[15]);
+ pos = hs.subtractVisibleRows(8, 17);
+ assertEquals(5, pos);
+
+ // test with two sets of hidden rows between start and required position
+ hs.hideSequence(seqs[20]);
+ hs.hideSequence(seqs[21]);
+ pos = hs.subtractVisibleRows(8, 23);
+ assertEquals(9, pos);
+
}
/**
assertTrue(al.getSequences().contains(seqs[1]));
HiddenSequences hs = al.getHiddenSequences();
assertEquals(0, hs.getSize());
- assertEquals(10, al.getHeight());
+ assertEquals(SEQ_COUNT, al.getHeight());
/*
* hide the second sequence in the alignment
assertTrue(hs.isHidden(seqs[1]));
assertFalse(al.getSequences().contains(seqs[1]));
assertEquals(1, hs.getSize());
- assertEquals(9, al.getHeight());
+ assertEquals(SEQ_COUNT - 1, al.getHeight());
assertSame(seqs[2], al.getSequenceAt(1));
/*
assertFalse(al.getSequences().contains(seqs[1]));
assertFalse(al.getSequences().contains(seqs[2]));
assertEquals(2, hs.getSize());
- assertEquals(8, al.getHeight());
+ assertEquals(SEQ_COUNT - 2, al.getHeight());
/*
* perform 'reveal' on what is now the second sequence in the alignment
assertTrue(revealed.contains(seqs[1]));
assertTrue(revealed.contains(seqs[2]));
assertEquals(0, hs.getSize());
- assertEquals(10, al.getHeight());
+ assertEquals(SEQ_COUNT, al.getHeight());
+ }
+
+ /**
+ * Test the method that adds a sequence to the hidden sequences and deletes it
+ * from the alignment, and its converse, where the first hidden sequences are
+ * at the bottom of the alignment (JAL-2437)
+ */
+ @Test(groups = "Functional")
+ public void testHideShowLastSequences()
+ {
+ AlignmentI al = new Alignment(seqs);
+ assertTrue(al.getSequences().contains(seqs[1]));
+ HiddenSequences hs = al.getHiddenSequences();
+ assertEquals(0, hs.getSize());
+ assertEquals(SEQ_COUNT, al.getHeight());
+
+ /*
+ * hide the last sequence in the alignment
+ */
+ hs.hideSequence(seqs[SEQ_COUNT - 1]);
+ assertFalse(hs.isHidden(seqs[SEQ_COUNT - 2]));
+ assertTrue(hs.isHidden(seqs[SEQ_COUNT - 1]));
+ assertFalse(al.getSequences().contains(seqs[SEQ_COUNT - 1]));
+ assertEquals(1, hs.getSize());
+ assertEquals(SEQ_COUNT - 1, al.getHeight());
+
+ /*
+ * hide the third last sequence in the alignment
+ */
+ hs.hideSequence(seqs[SEQ_COUNT - 3]);
+ assertFalse(hs.isHidden(seqs[SEQ_COUNT - 2]));
+ assertTrue(hs.isHidden(seqs[SEQ_COUNT - 3]));
+ assertFalse(al.getSequences().contains(seqs[SEQ_COUNT - 3]));
+ assertEquals(2, hs.getSize());
+ assertEquals(SEQ_COUNT - 2, al.getHeight());
+
+ /*
+ * reveal all the sequences, which should be reinstated in the same order as they started in
+ */
+ hs.showAll(null);
+ assertFalse(hs.isHidden(seqs[SEQ_COUNT - 3]));
+ assertFalse(hs.isHidden(seqs[SEQ_COUNT - 1]));
+ assertEquals(seqs[SEQ_COUNT - 3], al.getSequences().get(SEQ_COUNT - 3));
+ assertEquals(seqs[SEQ_COUNT - 2], al.getSequences().get(SEQ_COUNT - 2));
+ assertEquals(seqs[SEQ_COUNT - 1], al.getSequences().get(SEQ_COUNT - 1));
+ assertEquals(0, hs.getSize());
+ assertEquals(SEQ_COUNT, al.getHeight());
}
@Test(groups = "Functional")