### Question:
Interval { public boolean intersects(Interval other) { if (this.startIndex <= other.startIndex && other.startIndex <= this.endIndex) { return true; } if (this.startIndex <= other.endIndex && other.endIndex <= this.endIndex) { return true; } if (other.startIndex <= this.startIndex && this.startIndex <= other.endIndex) { return true; } if (other.startIndex <= this.endIndex && this.endIndex <= other.endIndex) { return true; } return false; } Interval(final int startIndex, final int endIndex); boolean intersects(Interval other); boolean intersects(Collection<Interval> col); static Interval[] createIntervals(Collection<Integer> indices); static Interval[] createIntervals(int[] indices); String toString(); final int startIndex; final int endIndex; }### Answer:
@Test public void intersects() { Interval a = new Interval(13, 14); Interval b = new Interval(9, 10); assertEquals("a.intersects(b)", false, a.intersects(b)); assertEquals("b.intersects(a)", false, b.intersects(a)); }
@Test public void intersects2() { Interval a = new Interval(13, 14); Interval b = new Interval(14, 15); assertEquals("a.intersects(b)", true, a.intersects(b)); assertEquals("b.intersects(a)", true, b.intersects(a)); }
@Test public void intersects3() { Interval a = new Interval(13, 14); Interval b = new Interval(12, 15); assertEquals("a.intersects(b)", true, a.intersects(b)); assertEquals("b.intersects(a)", true, b.intersects(a)); }
@Test public void intersects4() { Interval a = new Interval(9, 10); Interval b = new Interval(10, 12); assertEquals("a.intersects(b)", true, a.intersects(b)); assertEquals("b.intersects(a)", true, b.intersects(a)); }
@Test public void intersectsCollection() { List<Interval> list = new LinkedList<Interval>(); list.add(new Interval(1, 5)); list.add(new Interval(6, 9)); list.add(new Interval(10, 12)); Interval a = new Interval(13, 14); assertEquals("a.intersects(listCell)", false, a.intersects(list)); Interval b = new Interval(9, 10); assertEquals("a.intersects(listCell)", true, b.intersects(list)); }