ContinuousSpaceSegment implements Comparable<ContinuousSpaceSegment<C, V>> { IntersectionType intersects(C from, C to) { return intersects(new RangeBoundary<C>(from), new RangeBoundary<C>(to)); } ContinuousSpaceSegment(C from, C to, V value);  ContinuousSpaceSegment(RangeBoundary<C> from, RangeBoundary<C> to, V value);  ContinuousSpaceSegment(ContinuousSpaceSegment<C, V> other, V value); boolean contains(RangeBoundary<C> point); boolean contains(C point); RangeBoundary<C> segmentStart(); RangeBoundary<C> segmentEnd(); V value(); @Override int compareTo(ContinuousSpaceSegment<C, V> other); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString();  }
@Test public void shouldReturnNONEIntersectionTypeWhenNoIntersectionPresent() { ContinuousSpaceSegment<Integer, String> segment = new ContinuousSpaceSegment<Integer, String>(1, 10, "A"); ContinuousSpaceSegment.IntersectionType intersection = segment.intersects(20, 30); assertThat(intersection).isSameAs(ContinuousSpaceSegment.IntersectionType.NONE); }
@Test public void shouldReturnIDENTICALIntersectionTypeWhenSegmentsHaveSameStartAndEndPoints() { ContinuousSpaceSegment<Integer, String> segment = new ContinuousSpaceSegment<Integer, String>(1, 10, "A"); ContinuousSpaceSegment.IntersectionType intersection = segment.intersects(1, 10); assertThat(intersection).isSameAs(ContinuousSpaceSegment.IntersectionType.IDENTICAL); }
@Test public void shouldReturnBEFOREIntersectionTypeWhenSegmentsIntersectAndOtherSegmentStartsBeforeSegment() { ContinuousSpaceSegment<Integer, String> segment = new ContinuousSpaceSegment<Integer, String>(10, 20, "A"); ContinuousSpaceSegment.IntersectionType intersection = segment.intersects(5, 15); assertThat(intersection).isSameAs(ContinuousSpaceSegment.IntersectionType.BEFORE); }
@Test public void shouldReturnAFTERIntersectionTypeWhenSegmentsIntersectAndOtherSegmentStartsAfterSegment() { ContinuousSpaceSegment<Integer, String> segment = new ContinuousSpaceSegment<Integer, String>(10, 20, "A"); ContinuousSpaceSegment.IntersectionType intersection = segment.intersects(15, 25); assertThat(intersection).isSameAs(ContinuousSpaceSegment.IntersectionType.AFTER); }
@Test public void shouldReturnCONTAINSIntersectionTypeWhenOtherSegmentIsContainedWithingSegment() { ContinuousSpaceSegment<Integer, String> segment = new ContinuousSpaceSegment<Integer, String>(10, 20, "A"); ContinuousSpaceSegment.IntersectionType intersection = segment.intersects(15, 18); assertThat(intersection).isSameAs(ContinuousSpaceSegment.IntersectionType.CONTAINS); }
@Test public void shouldReturnCONTAINEDIntersectionTypeWhenSegmentIsContainedWithingOtherSegment() { ContinuousSpaceSegment<Integer, String> segment = new ContinuousSpaceSegment<Integer, String>(10, 20, "A"); ContinuousSpaceSegment.IntersectionType intersection = segment.intersects(0, 100); assertThat(intersection).isSameAs(ContinuousSpaceSegment.IntersectionType.CONTAINED); }