Skip to content

Commit b3142b9

Browse files
committed
More tests for issue #355
1 parent df1f905 commit b3142b9

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

biojava-genome/src/main/java/org/biojava/nbio/genome/parsers/gff/Location.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,10 +311,10 @@ private Location intersect(int a1, int a2, int b1, int b2) {
311311
if (b1 >= a2) {
312312
// b starts after a ends
313313
return null;
314-
} else if (b1 < a2 && b2 < a2) {
315-
// b starts after a and ends before a ends
314+
} else if (b1 < a2 && b2 <= a2) {
315+
// b starts after a starts and ends before or at where a ends
316316
return new Location(b1, b2);
317-
} else if (a2 < b2) {
317+
} else if (b1 >= a1 && a2 <= b2) {
318318
// b starts after a but extends after the end of a
319319
return new Location(b1, a2);
320320
}

biojava-genome/src/test/java/org/biojava/nbio/genome/TestLocation.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,29 @@ public void testLocation() {
9191
assertEquals(L(12,20), L(2,20).suffix( L(10,12)));
9292

9393
}
94+
95+
@Test
96+
public void testLocationIntersections() {
97+
// One inside another
98+
Location r21_25 = new Location( 21, 25 );
99+
Location r1_100 = new Location(1, 100 );
100+
101+
assertEquals(r21_25, r21_25.intersection( r1_100));
102+
assertEquals(r21_25, r1_100.intersection( r21_25));
103+
104+
// Non overlapping
105+
Location r10_100 = new Location(10, 100 );
106+
Location r1_9 = new Location( 1, 9 );
107+
108+
assertNull(r10_100.intersection( r1_9));
109+
assertNull(r1_9.intersection( new Location( 9, 10 )));
110+
111+
// Partially overlappping
112+
Location r1_25 = new Location( 1, 25 );
113+
Location r21_100 = new Location(21, 100 );
114+
assertEquals(r21_25, r1_25.intersection( r21_100));
115+
assertEquals(r21_25, r21_100.intersection( r1_25));
116+
}
94117

95118
//shorthand for testing
96119
private static Location L( int s, int e ) {

0 commit comments

Comments
 (0)