Clover icon

Coverage Report

  1. Project Clover database Thu Nov 7 2024 17:01:39 GMT
  2. Package jalview.structure

File StructureMappingTest.java

 

Code metrics

0
60
2
1
143
96
2
0.03
30
2
1

Classes

Class Line # Actions
StructureMappingTest 37 60 2
0.00%
 

Contributing tests

No tests hitting this source file were found.

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.structure;
22   
23    import static org.testng.Assert.assertEquals;
24    import static org.testng.Assert.assertFalse;
25    import static org.testng.Assert.assertTrue;
26   
27    import jalview.datamodel.Mapping;
28    import jalview.datamodel.Sequence;
29    import jalview.datamodel.SequenceI;
30    import jalview.util.MapList;
31   
32    import java.util.HashMap;
33    import java.util.List;
34   
35    import org.testng.annotations.Test;
36   
 
37    public class StructureMappingTest
38    {
 
39  0 toggle @Test(groups = "Functional")
40    public void testGetPDBResNumRanges()
41    {
42  0 HashMap<Integer, int[]> map = new HashMap<>();
43   
44  0 StructureMapping mapping = new StructureMapping(null, null, null, null,
45    map, null);
46   
47  0 List<int[]> ranges = mapping.getPDBResNumRanges(1, 2);
48  0 assertTrue(ranges.isEmpty());
49   
50  0 map.put(1, new int[] { 12, 20 }); // 1 maps to 12
51  0 ranges = mapping.getPDBResNumRanges(2, 3);
52  0 assertTrue(ranges.isEmpty());
53  0 ranges = mapping.getPDBResNumRanges(1, 2);
54  0 assertEquals(ranges.size(), 1);
55  0 assertEquals(ranges.get(0)[0], 12);
56  0 assertEquals(ranges.get(0)[1], 12);
57   
58  0 map.put(2, new int[] { 13, 20 }); // 2 maps to 13
59  0 ranges = mapping.getPDBResNumRanges(1, 2);
60  0 assertEquals(ranges.size(), 1);
61  0 assertEquals(ranges.get(0)[0], 12);
62  0 assertEquals(ranges.get(0)[1], 13);
63   
64  0 map.put(3, new int[] { 15, 20 }); // 3 maps to 15 - break
65  0 ranges = mapping.getPDBResNumRanges(1, 5);
66  0 assertEquals(ranges.size(), 2);
67  0 assertEquals(ranges.get(0)[0], 12);
68  0 assertEquals(ranges.get(0)[1], 13);
69  0 assertEquals(ranges.get(1)[0], 15);
70  0 assertEquals(ranges.get(1)[1], 15);
71    }
72   
 
73  0 toggle @Test(groups = "Functional")
74    public void testEquals()
75    {
76  0 SequenceI seq1 = new Sequence("seq1", "ABCDE");
77  0 SequenceI seq2 = new Sequence("seq1", "ABCDE");
78  0 String pdbFile = "a/b/file1.pdb";
79  0 String pdbId = "1a70";
80  0 String chain = "A";
81  0 String mappingDetails = "these are the mapping details, honest";
82  0 HashMap<Integer, int[]> map = new HashMap<>();
83   
84  0 Mapping seqToPdbMapping = new Mapping(seq1,
85    new MapList(new int[]
86    { 1, 5 }, new int[] { 2, 6 }, 1, 1));
87  0 StructureMapping sm1 = new StructureMapping(seq1, pdbFile, pdbId, chain,
88    map, mappingDetails, seqToPdbMapping);
89  0 assertFalse(sm1.equals(null));
90  0 assertFalse(sm1.equals("x"));
91   
92  0 StructureMapping sm2 = new StructureMapping(seq1, pdbFile, pdbId, chain,
93    map, mappingDetails, seqToPdbMapping);
94  0 assertTrue(sm1.equals(sm2));
95  0 assertTrue(sm2.equals(sm1));
96  0 assertEquals(sm1.hashCode(), sm2.hashCode());
97   
98    // with different sequence
99  0 sm2 = new StructureMapping(seq2, pdbFile, pdbId, chain, map,
100    mappingDetails, seqToPdbMapping);
101  0 assertFalse(sm1.equals(sm2));
102  0 assertFalse(sm2.equals(sm1));
103   
104    // with different file
105  0 sm2 = new StructureMapping(seq1, "a/b/file2.pdb", pdbId, chain, map,
106    mappingDetails, seqToPdbMapping);
107  0 assertFalse(sm1.equals(sm2));
108  0 assertFalse(sm2.equals(sm1));
109   
110    // with different pdbid (case sensitive)
111  0 sm2 = new StructureMapping(seq1, pdbFile, "1A70", chain, map,
112    mappingDetails, seqToPdbMapping);
113  0 assertFalse(sm1.equals(sm2));
114  0 assertFalse(sm2.equals(sm1));
115   
116    // with different chain
117  0 sm2 = new StructureMapping(seq1, pdbFile, pdbId, "B", map,
118    mappingDetails, seqToPdbMapping);
119  0 assertFalse(sm1.equals(sm2));
120  0 assertFalse(sm2.equals(sm1));
121   
122    // map is ignore for this test
123  0 sm2 = new StructureMapping(seq1, pdbFile, pdbId, chain, null,
124    mappingDetails, seqToPdbMapping);
125  0 assertTrue(sm1.equals(sm2));
126  0 assertTrue(sm2.equals(sm1));
127   
128    // with different mapping details
129  0 sm2 = new StructureMapping(seq1, pdbFile, pdbId, chain, map,
130    "different details!", seqToPdbMapping);
131  0 assertFalse(sm1.equals(sm2));
132  0 assertFalse(sm2.equals(sm1));
133   
134    // with different seq to pdb mapping
135  0 Mapping map2 = new Mapping(seq1,
136    new MapList(new int[]
137    { 1, 5 }, new int[] { 3, 7 }, 1, 1));
138  0 sm2 = new StructureMapping(seq1, pdbFile, pdbId, chain, map,
139    mappingDetails, map2);
140  0 assertFalse(sm1.equals(sm2));
141  0 assertFalse(sm2.equals(sm1));
142    }
143    }