package net.emaze.dysfunctional.ranges;

import org.junit.Assert;
import org.junit.Test;
import static net.emaze.dysfunctional.ranges.RangeMother.*;

/**
 *
 * @author rferranti
 */
public class RangeOpsTest {

    @Test
    public void canPerformDifferenceOnTwoDisjointRanges() {
        Range<Integer> lhs = r(0, 10);
        Range<Integer> rhs = r(11, 20);
        Assert.assertEquals(r(0, 10), RangeOps.difference(sequencer, comparator, lhs, rhs));
    }
    
    @Test
    public void canPerformDifferenceOnTwoOverlappingRanges() {
        Range<Integer> lhs = r(0, 10);
        Range<Integer> rhs = r(8, 20);
        Assert.assertEquals(r(0, 7), RangeOps.difference(sequencer, comparator, lhs, rhs));
    }
    
    @Test
    public void canPerformDifferenceOnTwoOverlappingRangesWithRhsLower() {
        Range<Integer> lhs = r(8, 20);
        Range<Integer> rhs = r(0, 10);
        Assert.assertEquals(r(11, 20), RangeOps.difference(sequencer, comparator, lhs, rhs));
    }
    
    @Test
    public void canPerformDifferenceOnTwoNestedRanges() {
        Range<Integer> lhs = r(0, 20);
        Range<Integer> rhs = r(4, 10);
        Assert.assertEquals(r(p(0, 3), p(11, 20)), RangeOps.difference(sequencer, comparator, lhs, rhs));
    }
    
    @Test
    public void canPerformIntersectOnTwoOverlappingRanges() {
        Range<Integer> lhs = r(0, 20);
        Range<Integer> rhs = r(4, 10);
        Assert.assertEquals(r(4, 10), RangeOps.intersect(sequencer, comparator, lhs, rhs));
    }
    
    @Test
    public void canPerformsymmetriDifferenceOnTwoRanges() {
        Range<Integer> lhs = r(0, 15);
        Range<Integer> rhs = r(10, 20);
        Assert.assertEquals(r(p(0, 9) , p(16, 20)), RangeOps.symmetricDifference(sequencer, comparator, lhs, rhs));
    }

}

@@ -34,16 +34,41 @@
 anges;%0A%0A
+import org.junit.Ignore;%0A
 import o
@@ -84,16 +84,16 @@
 Assert;%0A
-
 import o
@@ -469,37 +469,33 @@
 s, rhs));%0A    %7D%0A
-    
 %0A
+
     @Test%0A    pu
@@ -719,37 +719,33 @@
 s, rhs));%0A    %7D%0A
-    
 %0A
+
     @Test%0A    pu
@@ -983,37 +983,33 @@
 s, rhs));%0A    %7D%0A
-    
 %0A
+
     @Test%0A    pu
@@ -1242,36 +1242,582 @@
 s, rhs));%0A    %7D%0A
+%0A
     
+@Test%0A    @Ignore // TODO: needs support for empty range%0A    public void canPerformIntersectOnTwoNonOverlappingRanges() %7B%0A        Range%3CInteger%3E lhs = r(0, 1);%0A        Range%3CInteger%3E rhs = r(2, 3);%0A        RangeOps.intersect(sequencer, comparator, lhs, rhs);// == emptyRange%0A    %7D%0A%0A    @Test%0A    public void canPerformIntersectWithSparseRanges() %7B%0A        Range%3CInteger%3E lhs = r(p(0, 1), p(2, 4));%0A        Range%3CInteger%3E rhs = r(p(0, 1), p(5, 7));%0A        Assert.assertEquals(r(0, 1), RangeOps.intersect(sequencer, comparator, lhs, rhs));%0A    %7D%0A
 %0A    @Test%0A    p
@@ -2053,13 +2053,9 @@
   %7D%0A
-    
 %0A
+
     
@@ -2236,17 +2236,16 @@
 (p(0, 9)
- 
 , p(16, 
@@ -2320,11 +2320,10 @@
 ;%0A    %7D%0A
-%0A
 %7D%0A

range coverage