2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.commands;
23 import static org.testng.AssertJUnit.assertEquals;
25 import jalview.datamodel.Alignment;
26 import jalview.datamodel.AlignmentI;
27 import jalview.datamodel.Sequence;
28 import jalview.datamodel.SequenceI;
30 import org.testng.annotations.BeforeMethod;
31 import org.testng.annotations.Test;
34 * Unit tests for TrimRegionCommand
39 public class TrimRegionCommandTest
41 private AlignmentI al;
43 @BeforeMethod(alwaysRun = true)
46 SequenceI[] seqs = new SequenceI[2];
47 seqs[0] = new Sequence("seq0", "abcde-");
48 seqs[1] = new Sequence("seq1", "-ghjkl");
49 al = new Alignment(seqs);
54 * Test performing, undoing and redoing a 'trim left'
56 @Test(groups = { "Functional" })
57 public void testTrimLeft_withUndoAndRedo()
59 TrimRegionCommand cmd = new TrimRegionCommand("Remove Left", true,
60 al.getSequencesArray(), 2, al);
61 assertEquals(2, cmd.getSize());
62 assertEquals("cde-", al.getSequenceAt(0).getSequenceAsString());
63 assertEquals("hjkl", al.getSequenceAt(1).getSequenceAsString());
68 cmd.undoCommand(new AlignmentI[] { al });
69 assertEquals("abcde-", al.getSequenceAt(0).getSequenceAsString());
70 assertEquals("-ghjkl", al.getSequenceAt(1).getSequenceAsString());
75 cmd.doCommand(new AlignmentI[] { al });
76 assertEquals("cde-", al.getSequenceAt(0).getSequenceAsString());
77 assertEquals("hjkl", al.getSequenceAt(1).getSequenceAsString());
81 * Trim left of no columns - should do nothing. This is the case where the
82 * first column is selected and 'Remove Left' is selected.
84 @Test(groups = { "Functional" })
85 public void testTrimLeft_noColumns()
87 TrimRegionCommand cmd = new TrimRegionCommand("Remove Left", true,
88 al.getSequencesArray(), 0, al);
89 assertEquals(0, cmd.getSize());
90 assertEquals("abcde-", al.getSequenceAt(0).getSequenceAsString());
91 assertEquals("-ghjkl", al.getSequenceAt(1).getSequenceAsString());
95 * Trim left of a single column
97 @Test(groups = { "Functional" })
98 public void testTrimLeft_oneColumn()
100 TrimRegionCommand cmd = new TrimRegionCommand("Remove Left", true,
101 al.getSequencesArray(), 1, al);
102 assertEquals(1, cmd.getSize());
103 assertEquals("bcde-", al.getSequenceAt(0).getSequenceAsString());
104 assertEquals("ghjkl", al.getSequenceAt(1).getSequenceAsString());
108 * Trim right of no columns - should do nothing. This is the case where the
109 * last column is selected and 'Remove Right' is selected.
111 @Test(groups = { "Functional" })
112 public void testTrimRight_noColumns()
114 TrimRegionCommand cmd = new TrimRegionCommand("Remove Right", false,
115 al.getSequencesArray(), 5, al);
116 assertEquals(0, cmd.getSize());
117 assertEquals("abcde-", al.getSequenceAt(0).getSequenceAsString());
118 assertEquals("-ghjkl", al.getSequenceAt(1).getSequenceAsString());
122 * Trim right of a single column
124 @Test(groups = { "Functional" })
125 public void testTrimRight_oneColumn()
127 TrimRegionCommand cmd = new TrimRegionCommand("Remove Right", false,
128 al.getSequencesArray(), 4, al);
129 assertEquals(1, cmd.getSize());
130 assertEquals("abcde", al.getSequenceAt(0).getSequenceAsString());
131 assertEquals("-ghjk", al.getSequenceAt(1).getSequenceAsString());
135 * Test performing, undoing and redoing a 'trim right'
137 @Test(groups = { "Functional" })
138 public void testTrimRight_withUndoAndRedo()
140 TrimRegionCommand cmd = new TrimRegionCommand("Remove Right", false,
141 al.getSequencesArray(), 2, al);
142 assertEquals(3, cmd.getSize());
143 assertEquals("abc", al.getSequenceAt(0).getSequenceAsString());
144 assertEquals("-gh", al.getSequenceAt(1).getSequenceAsString());
149 cmd.undoCommand(new AlignmentI[] { al });
150 assertEquals("abcde-", al.getSequenceAt(0).getSequenceAsString());
151 assertEquals("-ghjkl", al.getSequenceAt(1).getSequenceAsString());
156 cmd.doCommand(new AlignmentI[] { al });
157 assertEquals("abc", al.getSequenceAt(0).getSequenceAsString());
158 assertEquals("-gh", al.getSequenceAt(1).getSequenceAsString());