Clover icon

Coverage Report

  1. Project Clover database Thu Aug 13 2020 12:04:21 BST
  2. Package jalview.datamodel

File MappingTest.java

 

Code metrics

0
26
4
1
103
57
4
0.15
6.5
4
1

Classes

Class Line # Actions
MappingTest 37 26 4
1.0100%
 

Contributing tests

This file is covered by 3 tests. .

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.datamodel;
22   
23    import static org.testng.AssertJUnit.assertEquals;
24    import static org.testng.AssertJUnit.assertSame;
25   
26    import jalview.gui.JvOptionPane;
27    import jalview.util.MapList;
28   
29    import java.util.Arrays;
30   
31    import org.testng.annotations.BeforeClass;
32    import org.testng.annotations.Test;
33   
34    /**
35    * Test class refactored from main method
36    */
 
37    public class MappingTest
38    {
39   
 
40  1 toggle @BeforeClass(alwaysRun = true)
41    public void setUpJvOptionPane()
42    {
43  1 JvOptionPane.setInteractiveMode(false);
44  1 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
45    }
46   
47    /**
48    * trite test of the intersectVisContigs method for a simple DNA -> Protein
49    * exon map and a range of visContigs
50    */
 
51  1 toggle @Test(groups = { "Functional" })
52    public void testIntersectVisContigs()
53    {
54  1 MapList fk = new MapList(new int[] { 1, 6, 8, 13, 15, 23 }, new int[] {
55    1, 7 }, 3, 1);
56  1 Mapping m = new Mapping(fk);
57  1 Mapping m_1 = m.intersectVisContigs(new int[] { fk.getFromLowest(),
58    fk.getFromHighest() });
59  1 Mapping m_2 = m.intersectVisContigs(new int[] { 1, 7, 11, 20 });
60   
61    // assertions from output values 'as is', not checked for correctness
62  1 String result = Arrays.deepToString(m_1.map.getFromRanges().toArray());
63  1 System.out.println(result);
64  1 assertEquals("[[1, 6], [8, 13], [15, 23]]", result);
65   
66  1 result = Arrays.deepToString(m_2.map.getFromRanges().toArray());
67  1 System.out.println(result);
68  1 assertEquals("[[1, 6], [11, 13], [15, 20]]", result);
69    }
70   
 
71  1 toggle @Test(groups = { "Functional" })
72    public void testToString()
73    {
74    /*
75    * with no sequence
76    */
77  1 MapList fk = new MapList(new int[] { 1, 6, 8, 13 }, new int[] { 4, 7 },
78    3, 1);
79  1 Mapping m = new Mapping(fk);
80  1 assertEquals("[ [1, 6] [8, 13] ] 3:1 to [ [4, 7] ] ", m.toString());
81   
82    /*
83    * with a sequence
84    */
85  1 SequenceI seq = new Sequence("Seq1", "");
86  1 m = new Mapping(seq, fk);
87  1 assertEquals("[ [1, 6] [8, 13] ] 3:1 to [ [4, 7] ] Seq1", m.toString());
88    }
89   
 
90  1 toggle @Test(groups = { "Functional" })
91    public void testCopyConstructor()
92    {
93  1 MapList ml = new MapList(new int[] { 1, 6, 8, 13 }, new int[] { 4, 7 },
94    3, 1);
95  1 SequenceI seq = new Sequence("seq1", "agtacg");
96  1 Mapping m = new Mapping(seq, ml);
97  1 m.setMappedFromId("abc");
98  1 Mapping copy = new Mapping(m);
99  1 assertEquals("abc", copy.getMappedFromId());
100  1 assertEquals(ml, copy.getMap());
101  1 assertSame(seq, copy.getTo());
102    }
103    }