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