1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
|
/*
* BioJava development code
*
* This code may be freely distributed and modified under the
* terms of the GNU Lesser General Public Licence. This should
* be distributed with the code. If you do not have a copy,
* see:
*
* http://www.gnu.org/copyleft/lesser.html
*
* Copyright for this code is held jointly by the individual
* authors. These should be listed in @author doc comments.
*
* For more information on the BioJava project and its aims,
* or to join the biojava-l mailing list, visit the home page
* at:
*
* http://www.biojava.org/
*/
package org.biojava.bio.symbol;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import junit.framework.TestCase;
/**
* <p>Title: MergeLocationTest</p>
* <p>Description: Tests the MergeLocation class</p>
* <p>Copyright: Copyright (c) 2002</p>
* <p>Company: AgResearch</p>
* @author Mark Schreiber
* @author Francois Pepin
* @version 1.0
*/
public class MergeLocationTest extends TestCase {
Location a;
Location b;
Location c;
Location d;
Location e;
Location f;
Location g;
MergeLocation ml;
List la;
List lb;
List nestl;
Location abc;
Location abcd;
MergeLocation fg;
Location nested;
public MergeLocationTest(String name){
super(name);
}
/**
* Runs the unit tests defined here.
*/
public static void main(String args[])
{
junit.textui.TestRunner.run(MergeLocationTest.class);
}
protected void setUp() throws java.lang.Exception {
super.setUp();
a = new RangeLocation(1, 10);
b = new RangeLocation(30,40);
c = new RangeLocation(35,65);
d = new RangeLocation(80,90);
e = new RangeLocation(60,70);
f = new RangeLocation(60,64);
g = new RangeLocation(65,70);
la = new ArrayList();
lb = new ArrayList();
nestl = new ArrayList();
la.add(a);
la.add(b);
la.add(c);
lb.add(a);
lb.add(b);
lb.add(c);
lb.add(d);
nestl.add(a);
nestl.add(d);
nestl.add(e);
ml = MergeLocation.mergeLocations(b,c);
nestl.add(ml);
abc = LocationTools.union(la);
abcd = LocationTools.union(lb);
fg = MergeLocation.mergeLocations(f,g);
nested = LocationTools.union(nestl);
}
protected void tearDown() throws java.lang.Exception {
super.tearDown();
}
public void testInstantiation()throws Exception{
assertNotNull(ml);
assertNotNull(abc);
assertNotNull(abcd);
assertNotNull(nested);
}
public void testBlocks(){
assertNotNull(ml.getComponentList(false));
assertTrue(fg.getComponentList(false).size() == 2);
assertTrue(ml.getComponentList(false).size() == 2);
assertTrue(ml.getComponentList(true).size() == 2);
}
public void testTouchingMerge(){
assertTrue(fg.getComponentList(true).size() == 2);
assertTrue(fg.isContiguous());
}
public void testCompoundABC(){
int blocks = 0;
MergeLocation loc = null;
for (Iterator i = abc.blockIterator(); i.hasNext(); ) {
Object item = i.next();
if(item instanceof MergeLocation){
loc = (MergeLocation)item;
}
blocks++;
}
assertTrue(blocks == 2);
assertNotNull(loc);
assertTrue(abc.getMax() == 65);
assertTrue(abc.getMin() == 1);
assertTrue(loc.getComponentList(false).size() == 2);
assertTrue(loc.getComponentList(true).size() == 2);
}
public void testCompoundABCD(){
int blocks = 0;
MergeLocation loc = null;
for (Iterator i = abcd.blockIterator(); i.hasNext(); ) {
Object item = i.next();
if(item instanceof MergeLocation){
loc = (MergeLocation)item;
}
blocks++;
}
assertTrue(blocks == 3);
assertTrue(abcd.getMin() == 1);
assertTrue(abcd.getMax() == 90);
assertTrue(loc.getComponentList(true).size() == 2);
assertTrue(loc.getComponentList(false).size() == 2);
}
public void testNested(){
int blocks = 0;
MergeLocation loc = null;
for (Iterator i = nested.blockIterator(); i.hasNext(); ) {
Object item = i.next();
if(item instanceof MergeLocation){
loc = (MergeLocation)item;
}
blocks++;
}
assertTrue(blocks == 3);
assertTrue(nested.getMax() == 90);
assertTrue(nested.getMin()==1);
assertTrue(loc.getComponentList(false).size()==2);
assertTrue(loc.getComponentList(true).size()==3);
}
}
|