1 package jalview.datamodel.features;
3 import static org.testng.Assert.assertEquals;
5 import jalview.datamodel.ContiguousI;
6 import jalview.datamodel.Range;
8 import java.util.Comparator;
10 import org.testng.annotations.Test;
12 public class RangeComparatorTest
15 @Test(groups = "Functional")
16 public void testCompare()
18 RangeComparator comp = new RangeComparator(true);
20 // same position, same length
21 assertEquals(comp.compare(10, 10, 20, 20), 0);
22 // same position, len1 > len2
23 assertEquals(comp.compare(10, 10, 20, 19), -1);
24 // same position, len1 < len2
25 assertEquals(comp.compare(10, 10, 20, 21), 1);
27 assertEquals(comp.compare(11, 10, 20, 20), 1);
29 assertEquals(comp.compare(10, 11, 20, 10), -1);
32 @Test(groups = "Functional")
33 public void testCompare_byStart()
35 Comparator<ContiguousI> comp = RangeComparator.BY_START_POSITION;
37 // same start position, same length
38 assertEquals(comp.compare(new Range(10, 20), new Range(10, 20)), 0);
39 // same start position, len1 > len2
40 assertEquals(comp.compare(new Range(10, 20), new Range(10, 19)), -1);
41 // same start position, len1 < len2
42 assertEquals(comp.compare(new Range(10, 18), new Range(10, 20)), 1);
44 assertEquals(comp.compare(new Range(11, 20), new Range(10, 20)), 1);
46 assertEquals(comp.compare(new Range(10, 20), new Range(11, 20)), -1);
49 @Test(groups = "Functional")
50 public void testCompare_byEnd()
52 Comparator<ContiguousI> comp = RangeComparator.BY_END_POSITION;
54 // same end position, same length
55 assertEquals(comp.compare(new Range(10, 20), new Range(10, 20)), 0);
56 // same end position, len1 > len2
57 assertEquals(comp.compare(new Range(10, 20), new Range(11, 20)), -1);
58 // same end position, len1 < len2
59 assertEquals(comp.compare(new Range(11, 20), new Range(10, 20)), 1);
61 assertEquals(comp.compare(new Range(10, 21), new Range(10, 20)), 1);
63 assertEquals(comp.compare(new Range(10, 20), new Range(10, 21)), -1);