Clover icon

Coverage Report

  1. Project Clover database Mon Nov 11 2024 16:01:40 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
1.0100%
 

Contributing tests

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