public void ICanCreateARangeCollectionOfIntegersAndAddToIt() { var rangeCollection = new RangeCollection <int> (); var random = new Random(); var randomRanges = Enumerable.Range(1, 100).Select(i => new Range <int>(random.Next(0, 100), random.Next(101, 200))); rangeCollection.AddRange(randomRanges); // Not a lot we can say about it, other than it should have some but less than 101 ranges in it rangeCollection.Ranges.Count().Should().BeGreaterOrEqualTo(1); rangeCollection.Ranges.Count().Should().BeLessOrEqualTo(100); }
public void TestRemovingRanges() { RangeCollection ranges = new RangeCollection(); ranges.AddRange(0, 4); ranges.RemoveRange(1, 2); Assert.AreEqual(2, ranges.Count); Assert.AreEqual(new Range(0, 0), ranges[0]); Assert.AreEqual(new Range(3, 4), ranges[1]); ranges.Clear(); ranges.AddRange(0, 4); ranges.RemoveRange(0, 1); Assert.AreEqual(1, ranges.Count); Assert.AreEqual(new Range(2, 4), ranges[0]); ranges.Clear(); ranges.AddRange(0, 4); ranges.RemoveRange(4, 4); Assert.AreEqual(1, ranges.Count); Assert.AreEqual(new Range(0, 3), ranges[0]); }
public void RangesCoallesceWithinARangeCollection() { Range <int> range1 = new Range <int> (1, 33); Range <int> range2 = new Range <int> (32, 67); Range <int> range3 = new Range <int> (66, 100); var rangeCollection = new RangeCollection <int> (); rangeCollection.AddRange(new [] { range1, range2, range3 }); rangeCollection.Ranges.Should().HaveCount(1, "all the ranges should collapse to one"); var first = rangeCollection.Ranges.First(); first.Start.Should().Be(1, "the collapsed range should start at 1"); first.End.Should().Be(100, "the collapsed range should end at 100"); }
public void RangesShouldBeReturnedInSortedOrder() { var range1 = new Range <int> (1, 33); var range2 = new Range <int> (34, 66); var range3 = new Range <int> (67, 100); var rangeCollection = new RangeCollection <int> (); rangeCollection.AddRange(new [] { range3, range2, range1 }); rangeCollection.Ranges.Should().HaveCount(3, "the ranges were distinct"); var result = rangeCollection.Ranges.ToArray(); result[0].Should().Be(range1); result[1].Should().Be(range2); result[2].Should().Be(range3); }
/// <summary> /// Returns a Collection of range that represents the current class /// </summary> /// <returns></returns> public virtual RangeCollection GetRanges() { RangeCollection ranges = new RangeCollection(); ranges.AddRange(m_RangeCollection); return ranges; }