public class RangesTest {
@Test
public void test() {
Ranges ranges = new Ranges();
// Example of a simple range merges..
ranges.add(0, 5);
ranges.add(15, 5);
ranges.add(5,10);
assertEquals(ranges(range(0,20)), ranges.toArrayList());
// Remove which splits an existing range into 2.
ranges.remove(5,10);
assertEquals(ranges(range(0,5),range(15,20)), ranges.toArrayList());
// overlapping add...
ranges.add(4,12);
assertEquals(ranges(range(0,20)), ranges.toArrayList());
// Removes are idempotent
ranges.remove(5,10);
assertEquals(ranges(range(0,5),range(15,20)), ranges.toArrayList());
ranges.remove(5,10);
assertEquals(ranges(range(0,5),range(15,20)), ranges.toArrayList());
// Adds are idempotent
ranges.add(5,10);
assertEquals(ranges(range(0,20)), ranges.toArrayList());
ranges.add(5,10);
assertEquals(ranges(range(0,20)), ranges.toArrayList());
}