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