Section implements Mergeable<Section> { public static boolean isBetween(final int min, final int max, final int index, final boolean includeMin, final boolean includeMax) { if (includeMin && includeMax) { if (index >= min && index <= max) { return true; } else { return false; } } if (includeMin && !includeMax) { if (index >= min && index < max) { return true; } else { return false; } } if (!includeMin && includeMax) { if (index > min && index <= max) { return true; } else { return false; } } if (min < index && index < max) { return true; } else { return false; } }  static boolean isBetween(final int min, final int max, final int index,
		final boolean includeMin, final boolean includeMax); boolean isBetween(final Section other); boolean isToLeft(final Section other); boolean isToRight(final Section other); @Override Section merge(final Section other); boolean overlapsWith(final Section other);  }
@Test public void testIsBetween() { boolean expected; boolean actual; Section section; Section other; section = Section.builder().start(23).end(45).build(); other = Section.builder().start(22).end(44).build(); actual = section.isBetween(other); expected = false; assertEquals(expected, actual); section = Section.builder().start(23).end(45).build(); other = Section.builder().start(23).end(45).build(); actual = section.isBetween(other); expected = true; assertEquals(expected, actual); section = Section.builder().start(23).end(45).build(); other = Section.builder().start(24).end(44).build(); actual = section.isBetween(other); expected = true; assertEquals(expected, actual); section = Section.builder().start(23).end(45).build(); other = Section.builder().start(23).end(46).build(); actual = section.isBetween(other); expected = false; assertEquals(expected, actual); section = Section.builder().start(23).end(45).build(); other = Section.builder().start(24).end(46).build(); actual = section.isBetween(other); expected = false; assertEquals(expected, actual); }
@Test public void testIsBetweenIntIntIntBooleanBoolean() { boolean expected; boolean actual; int min; int max; int index; final int primitiveOne = 1; boolean includeMin; boolean includeMax; min = 0; max = 10; index = min; includeMin = false; includeMax = false; actual = Section.isBetween(min, max, index, includeMin, includeMax); expected = false; assertEquals(actual, expected); for (index = min + primitiveOne; index < max; index++) { actual = Section.isBetween(min, max, index, includeMin, includeMax); expected = true; assertEquals(actual, expected); } index = max; actual = Section.isBetween(min, max, index, includeMin, includeMax); expected = false; assertEquals(actual, expected); index = min - primitiveOne; actual = Section.isBetween(min, max, index, includeMin, includeMax); expected = false; assertEquals(actual, expected); index = max + primitiveOne; actual = Section.isBetween(min, max, index, includeMin, includeMax); expected = false; assertEquals(actual, expected); index = min; includeMin = true; includeMax = true; actual = Section.isBetween(min, max, index, includeMin, includeMax); expected = true; assertEquals(actual, expected); for (index = min + primitiveOne; index < max; index++) { actual = Section.isBetween(min, max, index, includeMin, includeMax); expected = true; assertEquals(actual, expected); } index = max; actual = Section.isBetween(min, max, index, includeMin, includeMax); expected = true; assertEquals(actual, expected); index = min - primitiveOne; actual = Section.isBetween(min, max, index, includeMin, includeMax); expected = false; assertEquals(actual, expected); index = max + primitiveOne; actual = Section.isBetween(min, max, index, includeMin, includeMax); expected = false; assertEquals(actual, expected); index = min; includeMin = false; includeMax = true; actual = Section.isBetween(min, max, index, includeMin, includeMax); expected = false; assertEquals(actual, expected); for (index = min + primitiveOne; index < max; index++) { actual = Section.isBetween(min, max, index, includeMin, includeMax); expected = true; assertEquals(actual, expected); } index = max; actual = Section.isBetween(min, max, index, includeMin, includeMax); expected = true; assertEquals(actual, expected); index = min - primitiveOne; actual = Section.isBetween(min, max, index, includeMin, includeMax); expected = false; assertEquals(actual, expected); index = max + primitiveOne; actual = Section.isBetween(min, max, index, includeMin, includeMax); expected = false; assertEquals(actual, expected); index = min; includeMin = true; includeMax = false; actual = Section.isBetween(min, max, index, includeMin, includeMax); expected = true; assertEquals(actual, expected); for (index = min + primitiveOne; index < max; index++) { actual = Section.isBetween(min, max, index, includeMin, includeMax); expected = true; assertEquals(actual, expected); } index = max; actual = Section.isBetween(min, max, index, includeMin, includeMax); expected = false; assertEquals(actual, expected); index = min - primitiveOne; actual = Section.isBetween(min, max, index, includeMin, includeMax); expected = false; assertEquals(actual, expected); index = max + primitiveOne; actual = Section.isBetween(min, max, index, includeMin, includeMax); expected = false; assertEquals(actual, expected); }