RangeHelper { public boolean isSatisfiable(final Iterable<Range> ranges, final long streamLength) { for (Range range : ranges) { if (range.getTo() >= streamLength || !isRangeValid(range)) { return false; } } return true; }  long getRangeLength(final Range range); boolean isRangeValid(final Range range); long getTotalLength(final List<Range> ranges); boolean isSatisfiable(final Iterable<Range> ranges, final long streamLength);  }
@Test public void shouldBeSatisfiable() { assertThat(rangeHelper.isSatisfiable(Collections.singletonList(new Range(0, 0)), 1), is(true)); assertThat(rangeHelper.isSatisfiable(Collections.singletonList(new Range(0, 1)), 2), is(true)); assertThat(rangeHelper.isSatisfiable(Collections.singletonList(new Range(0, 2)), 3), is(true)); }
@Test public void shouldNotBeSatisfiable() { assertThat(rangeHelper.isSatisfiable(Collections.singletonList(new Range(0, 0)), 0), is(false)); assertThat(rangeHelper.isSatisfiable(Collections.singletonList(new Range(0, 1)), 1), is(false)); assertThat(rangeHelper.isSatisfiable(Collections.singletonList(new Range(0, 2)), 1), is(false)); assertThat(rangeHelper.isSatisfiable(Collections.singletonList(new Range(-1, 0)), 0), is(false)); assertThat(rangeHelper.isSatisfiable(Collections.singletonList(new Range(-1, 0)), 55), is(false)); assertThat(rangeHelper.isSatisfiable(Collections.singletonList(new Range(50, 49)), 0), is(false)); }
@Test public void shouldNotBeSatisfiableWhenFirstElementIsFine() { assertThat(rangeHelper.isSatisfiable(Arrays.asList(new Range(0, 0), new Range(-1, 0)), 5), is(false)); }