Clover icon

jalviewX

  1. Project Clover database Wed Oct 31 2018 15:13:58 GMT
  2. Package jalview.analysis

File GroupingTest.java

 

Code metrics

4
20
2
1
113
73
4
0.2
10
2
2

Classes

Class Line # Actions
GroupingTest 37 20 4 0
1.0100%
 

Contributing tests

This file is covered by 1 test. .

Source view

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.analysis;
22   
23    import jalview.datamodel.Alignment;
24    import jalview.datamodel.AlignmentI;
25    import jalview.datamodel.ColumnSelection;
26    import jalview.datamodel.Sequence;
27    import jalview.datamodel.SequenceGroup;
28    import jalview.datamodel.SequenceI;
29    import jalview.gui.JvOptionPane;
30   
31    import java.util.Arrays;
32   
33    import org.testng.AssertJUnit;
34    import org.testng.annotations.BeforeClass;
35    import org.testng.annotations.Test;
36   
 
37    public class GroupingTest
38    {
 
39  1 toggle @BeforeClass(alwaysRun = true)
40    public void setUpJvOptionPane()
41    {
42  1 JvOptionPane.setInteractiveMode(false);
43  1 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
44    }
45   
46    Sequence s1 = new Sequence("s1", "AAAADDDDEEEE");
47   
48    Sequence s2 = new Sequence("s2", "AAAADDDDEEEE");
49   
50    Sequence s3 = new Sequence("s3", "ACAADDEDEEEE");
51   
52    Sequence s4 = new Sequence("s4", "AAAADDEDEEEE");
53   
54    Sequence s5 = new Sequence("s5", "AAAADDEDTTEE");
55   
56    SequenceGroup sg_12 = new SequenceGroup(Arrays.asList(new SequenceI[] {
57    s1, s2 }), "Group1", null, false, false, false, 0, 5);
58   
59    SequenceGroup sg_345 = new SequenceGroup(Arrays.asList(new SequenceI[] {
60    s3, s4, s5 }), "Group2", null, false, false, false, 0, 5);
61   
62    AlignmentI alignment = new Alignment(
63    new SequenceI[] { s1, s2, s3, s4, s5 });
64   
65    /*
66    * test for the case where column selections are not added in
67    * left to right order
68    */
69    int[] positions = new int[] { 7, 9, 1 };
70   
 
71  1 toggle @Test(groups = { "Functional" })
72    public void testMakeGroupsWithBoth()
73    {
74  1 String[] str = new String[alignment.getHeight()];
75  1 int seq = 0;
76  1 for (SequenceI s : alignment.getSequences())
77    {
78  5 StringBuilder sb = new StringBuilder();
79  5 for (int p : positions)
80    {
81  15 sb.append(s.getCharAt(p));
82    }
83  5 str[seq++] = sb.toString();
84    }
85  1 SequenceGroup[] seqgroupsString = Grouping.makeGroupsFrom(
86    alignment.getSequencesArray(), str,
87    Arrays.asList(new SequenceGroup[] { sg_12, sg_345 }));
88   
89  1 ColumnSelection cs = new ColumnSelection();
90  1 for (int p : positions)
91    {
92  3 cs.addElement(p);
93    }
94  1 SequenceGroup[] seqgroupsColSel = Grouping.makeGroupsFromCols(
95    alignment.getSequencesArray(), cs,
96    Arrays.asList(new SequenceGroup[] { sg_12, sg_345 }));
97  1 AssertJUnit
98    .assertEquals(seqgroupsString.length, seqgroupsColSel.length);
99  5 for (int p = 0; p < seqgroupsString.length; p++)
100    {
101  4 AssertJUnit.assertEquals(seqgroupsString[p].getName(),
102    seqgroupsColSel[p].getName());
103  4 AssertJUnit.assertArrayEquals(
104    seqgroupsString[p].getSequencesInOrder(alignment),
105    seqgroupsColSel[p].getSequencesInOrder(alignment));
106  4 if (seqgroupsString[p].getSequences().contains(s2))
107    {
108  1 AssertJUnit.assertTrue(seqgroupsString[p].getSize() == 2);
109    }
110    }
111    }
112   
113    }