JAL-3746 apply copyright to tests
[jalview.git] / test / jalview / gui / PairwiseAlignmentPanelTest.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
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.
11  *  
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.
16  * 
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.
20  */
21 package jalview.gui;
22
23 import static org.testng.Assert.assertEquals;
24
25 import jalview.datamodel.AlignmentI;
26 import jalview.datamodel.SequenceGroup;
27 import jalview.io.DataSourceType;
28 import jalview.io.FileLoader;
29
30 import javax.swing.JTextArea;
31
32 import junit.extensions.PA;
33
34 import org.testng.annotations.Test;
35
36 public class PairwiseAlignmentPanelTest
37 {
38   @Test(groups = "Functional")
39   public void testConstructor_withSelectionGroup()
40   {
41     AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
42             "examples/uniref50.fa", DataSourceType.FILE);
43     AlignViewport viewport = af.getViewport();
44     AlignmentI al = viewport.getAlignment();
45
46     /*
47      * select columns 29-36 of sequences 4 and 5 for alignment
48      * Q93XJ9_SOLTU/23-29 L-KAISNV
49      * FER1_PEA/26-32     V-TTTKAF
50      */
51     SequenceGroup sg = new SequenceGroup();
52     sg.addSequence(al.getSequenceAt(3), false);
53     sg.addSequence(al.getSequenceAt(4), false);
54     sg.setStartRes(28);
55     sg.setEndRes(35);
56     viewport.setSelectionGroup(sg);
57
58     PairwiseAlignPanel testee = new PairwiseAlignPanel(viewport);
59
60     String text = ((JTextArea) PA.getValue(testee, "textarea")).getText();
61     String expected = "Score = 80.0\n" + "Length of alignment = 4\n"
62             + "Sequence     FER1_PEA/29-32 (Sequence length = 7)\n"
63             + "Sequence Q93XJ9_SOLTU/23-26 (Sequence length = 7)\n\n"
64             + "    FER1_PEA/29-32 TKAF\n" + "                    ||.\n"
65             + "Q93XJ9_SOLTU/23-26 LKAI\n\n" + "Percentage ID = 50.00\n\n";
66     assertEquals(text, expected);
67   }
68
69   /**
70    * This test aligns the same sequences as testConstructor_withSelectionGroup
71    * but as a complete alignment (no selection). Note that in fact the user is
72    * currently required to make a selection in order to calculate pairwise
73    * alignments, so this case does not arise.
74    */
75   @Test(groups = "Functional")
76   public void testConstructor_noSelectionGroup()
77   {
78     String seqs = ">Q93XJ9_SOLTU/23-29\nL-KAISNV\n>FER1_PEA/26-32\nV-TTTKAF\n";
79     AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(seqs,
80             DataSourceType.PASTE);
81     AlignViewport viewport = af.getViewport();
82
83     PairwiseAlignPanel testee = new PairwiseAlignPanel(viewport);
84
85     String text = ((JTextArea) PA.getValue(testee, "textarea")).getText();
86     String expected = "Score = 80.0\n" + "Length of alignment = 4\n"
87             + "Sequence     FER1_PEA/29-32 (Sequence length = 7)\n"
88             + "Sequence Q93XJ9_SOLTU/23-26 (Sequence length = 7)\n\n"
89             + "    FER1_PEA/29-32 TKAF\n" + "                    ||.\n"
90             + "Q93XJ9_SOLTU/23-26 LKAI\n\n" + "Percentage ID = 50.00\n\n";
91     assertEquals(text, expected);
92   }
93 }