public void SetsUnion() { var set1 = new IntervalSet.IntervalSet(new MyRange(1, 3)).Union( new IntervalSet.IntervalSet(new MyRange(4, 6))); Assert.AreEqual(set1.ToArray(), new int[] { 1, 2, 3, 4, 5, 6 }); var set2 = new IntervalSet.IntervalSet(new MyRange(1, 3)).Union( new IntervalSet.IntervalSet()); Assert.AreEqual(set2.ToArray(), new int[] { 1, 2, 3 }); var set3 = new IntervalSet.IntervalSet(new MyRange(4, 5)).Union( new IntervalSet.IntervalSet(new MyRange(1, 2))); Assert.AreEqual(set3.ToArray(), new int[] { 1, 2, 4, 5 }); var set4 = new IntervalSet.IntervalSet(new MyRange(1, 3)).Union( new IntervalSet.IntervalSet(new MyRange(2, 4))); Assert.AreEqual(set4.ToArray(), new int[] { 1, 2, 3, 4 }); var set5 = new IntervalSet.IntervalSet(new MyRange(1, 3)).Union( new IntervalSet.IntervalSet(new MyRange(2, 4), new MyRange(6, 7))); Assert.AreEqual(set5.ToArray(), new int[] { 1, 2, 3, 4, 6, 7 }); var set6 = new IntervalSet.IntervalSet(new MyRange(1, 1), new MyRange(3, 4), new MyRange(5, 6)).Union( new IntervalSet.IntervalSet(new MyRange(0, 7))); var test = set6.ToArray(); Assert.AreEqual(set6.ToArray(), new int[] { 0, 1, 2, 3, 4, 5, 6, 7 }); }
public void SetsIntersection() { var set1 = new IntervalSet.IntervalSet(new MyRange(1, 3)).Intersection( new IntervalSet.IntervalSet(new MyRange(4, 6))); Assert.AreEqual(set1.ToArray(), new int[] {}); var set2 = new IntervalSet.IntervalSet(new MyRange(1, 3)).Intersection( new IntervalSet.IntervalSet()); Assert.AreEqual(set2.ToArray(), new int[] {}); var set3 = new IntervalSet.IntervalSet(new MyRange(1, 5)).Intersection( new IntervalSet.IntervalSet(new MyRange(4, 6))); Assert.AreEqual(set3.ToArray(), new int[] { 4, 5 }); var set4 = new IntervalSet.IntervalSet(new MyRange(1, 3)).Intersection( new IntervalSet.IntervalSet(new MyRange(3, 7))); Assert.AreEqual(set4.ToArray(), new int[] { 3 }); var set5 = new IntervalSet.IntervalSet(new MyRange(1, 4), new MyRange(6, 9)).Intersection( new IntervalSet.IntervalSet(new MyRange(3, 7))); Assert.AreEqual(set5.ToArray(), new int[] { 3, 4, 6, 7 }); }
public void Contains() { var set1 = new IntervalSet.IntervalSet(new MyRange(1, 4)); Assert.True(set1.Contains(1)); Assert.True(set1.Contains(2)); Assert.True(set1.Contains(3)); Assert.True(set1.Contains(4)); Assert.False(set1.Contains(0)); Assert.False(set1.Contains(5)); Assert.False(set1.Contains(Int32.MinValue)); var set2 = new IntervalSet.IntervalSet(); Assert.False(set2.Contains(0)); Assert.False(set2.Contains(Int32.MinValue)); Assert.False(set2.Contains(Int32.MaxValue)); var set3 = new IntervalSet.IntervalSet(new MyRange(1, 3), new MyRange(2, 4), new MyRange(6, 6)); Assert.True(set3.Contains(1)); Assert.True(set3.Contains(2)); Assert.True(set3.Contains(3)); Assert.True(set3.Contains(4)); Assert.True(set3.Contains(6)); Assert.False(set3.Contains(0)); Assert.False(set3.Contains(5)); Assert.False(set3.Contains(Int32.MinValue)); }
public void BasicSets() { var set1 = new IntervalSet.IntervalSet(new MyRange(1, 5)); Assert.AreEqual(set1.ToArray(), new int[] { 1, 2, 3, 4, 5 }); var set2 = new IntervalSet.IntervalSet(); Assert.AreEqual(set2.ToArray(), new int[] {}); var set3 = new IntervalSet.IntervalSet(new MyRange(1, 3), new MyRange(5, 6)); Assert.AreEqual(set3.ToArray(), new int[] { 1, 2, 3, 5, 6 }); var set4 = new IntervalSet.IntervalSet(new MyRange(1, 1)); Assert.AreEqual(set4.ToArray(), new int[] { 1 }); }
public void IntersectingIntervals() { var set1 = new IntervalSet.IntervalSet(new MyRange(1, 4), new MyRange(3, 5)); Assert.AreEqual(set1.ToArray(), new int[] { 1, 2, 3, 4, 5 }); var set2 = new IntervalSet.IntervalSet(new MyRange(1, 4), new MyRange(1, 4)); Assert.AreEqual(set2.ToArray(), new int[] { 1, 2, 3, 4 }); var set3 = new IntervalSet.IntervalSet(new MyRange(3, 5), new MyRange(1, 4)); Assert.AreEqual(set3.ToArray(), new int[] { 1, 2, 3, 4, 5 }); var set4 = new IntervalSet.IntervalSet(new MyRange(1, 4), new MyRange(5, 6)); Assert.AreEqual(set4.ToArray(), new int[] { 1, 2, 3, 4, 5, 6 }); var set5 = new IntervalSet.IntervalSet(new MyRange(1, 3), new MyRange(2, 3)); Assert.AreEqual(set5.ToArray(), new int[] { 1, 2, 3 }); var set6 = new IntervalSet.IntervalSet(new MyRange(1, 3), new MyRange(2, 5), new MyRange(3, 6)); Assert.AreEqual(set6.ToArray(), new int[] { 1, 2, 3, 4, 5, 6 }); }
public void SetsDifference() { var set1 = new IntervalSet.IntervalSet(new MyRange(1, 3), new MyRange(5, 5)).Difference( new IntervalSet.IntervalSet()); Assert.AreEqual(set1.ToArray(), new int[] { 1, 2, 3, 5 }); var set2 = new IntervalSet.IntervalSet().Difference( new IntervalSet.IntervalSet(new MyRange(1, 3), new MyRange(5, 5))); Assert.AreEqual(set2.ToArray(), new int[] {}); var set3 = new IntervalSet.IntervalSet(new MyRange(1, 5)).Difference( new IntervalSet.IntervalSet(new MyRange(6, 8))); Assert.AreEqual(set3.ToArray(), new int[] { 1, 2, 3, 4, 5 }); var set4 = new IntervalSet.IntervalSet(new MyRange(5, 7)).Difference( new IntervalSet.IntervalSet(new MyRange(0, 3))); Assert.AreEqual(set4.ToArray(), new int[] { 5, 6, 7 }); var set5 = new IntervalSet.IntervalSet(new MyRange(1, 5)).Difference( new IntervalSet.IntervalSet(new MyRange(3, 7))); Assert.AreEqual(set5.ToArray(), new int[] { 1, 2 }); var set6 = new IntervalSet.IntervalSet(new MyRange(1, 4), new MyRange(6, 8)).Difference( new IntervalSet.IntervalSet(new MyRange(3, 7))); Assert.AreEqual(set6.ToArray(), new int[] { 1, 2, 8 }); var set7 = new IntervalSet.IntervalSet(new MyRange(1, 5)).Difference( new IntervalSet.IntervalSet(new MyRange(3, 3))); Assert.AreEqual(set7.ToArray(), new int[] { 1, 2, 4, 5 }); }
static void Main(string[] args) { var iSet1 = new IntervalSet.IntervalSet( new MyRange(3, 6), new MyRange(50, 53), new MyRange(-1, 2)); var iSet2 = new IntervalSet.IntervalSet( new MyRange(0, 0), new MyRange(1, 2), new MyRange(13, 16)); var iSet3 = new IntervalSet.IntervalSet( new MyRange(5, 10), new MyRange(0, 3)); var iSet = iSet1.Difference(iSet2).Union(iSet3); foreach (var x in iSet) { Console.Write($"{x} "); } /* * var set1 = new MySet(HelperMethods.MyRangesFromString("1..10,22,28,30..31,38..44")); * var set2 = new MySet(HelperMethods.MyRangesFromString("5..8,22,23,24,32..35,40..48")); * * var set3 = new MySet(HelperMethods.MyRangesFromString("5..10,15..25,26,27,28,30..33")); * var set4 = new MySet(HelperMethods.MyRangesFromString("1,2,6..7,9..13,15..17,26,28,31")); * * var set5 = new MySet(HelperMethods.MyRangesFromString("5..10,15..25,26,27,28,30..33")); * var set6 = new MySet(HelperMethods.MyRangesFromString("1,2,8..17,26,28,31")); * * foreach (var x in set1 + set2) * Console.Write($"{x} "); * Console.WriteLine(); * * foreach (var x in set3 - set4) * Console.Write($"{x} "); * Console.WriteLine(); * * foreach (var x in set5 * set6) * Console.Write($"{x} ");*/ }
public IntervalSet Intersection(IntervalSet other) { return(new IntervalSet(_tree.Intersection(other._tree))); }
public IntervalSet Difference(IntervalSet other) { return(new IntervalSet(_tree.Difference(other._tree))); }
public IntervalSet Union(IntervalSet other) { return(new IntervalSet(_tree.Union(other._tree))); }