### Question:
OpenEndRangeMap { Collection<V> replaceFrom( K from, V value ) { Collection<V> removed = new ArrayList<>(); Iterator<V> itr = tree.tailMap( from ).values().iterator(); while ( itr.hasNext() ) { removed.add( itr.next() ); itr.remove(); } tree.put( from, value ); endKey = from; endValue = value; return removed; }  V last(); Set<Map.Entry<K,V>> entrySet(); Collection<V> remove( K lessThan );  }### Answer:
@Test public void shouldFindSingleRange() { ranges.replaceFrom( 0, "A" ); assertRange( -100, -1, new ValueRange<>( 0, null ) ); assertRange( 0, 100, new ValueRange<>( null, "A" ) ); }
@Test public void shouldHandleMultipleRanges() { ranges.replaceFrom( 0, "A" ); ranges.replaceFrom( 5, "B" ); ranges.replaceFrom( 10, "C" ); assertRange( -100, -1, new ValueRange<>( 0, null ) ); assertRange( 0, 4, new ValueRange<>( 5, "A" ) ); assertRange( 5, 9, new ValueRange<>( 10, "B" ) ); assertRange( 10, 100, new ValueRange<>( null, "C" ) ); }
@Test public void shouldTruncateAtPreviousEntry() { ranges.replaceFrom( 0, "A" ); ranges.replaceFrom( 10, "B" ); Collection<String> removed = ranges.replaceFrom( 10, "C" ); assertRange( -100, -1, new ValueRange<>( 0, null ) ); assertRange( 0, 9, new ValueRange<>( 10, "A" ) ); assertRange( 10, 100, new ValueRange<>( null, "C" ) ); assertThat( removed, hasItems( "B" ) ); }
@Test public void shouldTruncateBeforePreviousEntry() { ranges.replaceFrom( 0, "A" ); ranges.replaceFrom( 10, "B" ); Collection<String> removed = ranges.replaceFrom( 7, "C" ); assertRange( -100, -1, new ValueRange<>( 0, null ) ); assertRange( 0, 6, new ValueRange<>( 7, "A" ) ); assertRange( 7, 100, new ValueRange<>( null, "C" ) ); assertThat( removed, hasItems( "B" ) ); }
@Test public void shouldTruncateSeveralEntries() { ranges.replaceFrom( 0, "A" ); ranges.replaceFrom( 10, "B" ); ranges.replaceFrom( 20, "C" ); ranges.replaceFrom( 30, "D" ); Collection<String> removed = ranges.replaceFrom( 15, "E" ); assertRange( -100, -1, new ValueRange<>( 0, null ) ); assertRange( 0, 9, new ValueRange<>( 10, "A" ) ); assertRange( 10, 14, new ValueRange<>( 15, "B" ) ); assertRange( 15, 100, new ValueRange<>( null, "E" ) ); assertThat( removed, hasItems( "C", "D" ) ); }