public void RemoveElementInMiddleOfRange() { // Arrange var sut = new OrderedRangedSet<int>(); int v1 = 123; int v2 = v1 + 1; int v3 = v2 + 1; sut.Add(v1); sut.Add(v2); sut.Add(v3); // Act sut.Remove(v2); // Assert Assert.That(sut.IsEmpty, Is.False); Assert.That(sut.Count, Is.EqualTo(2)); Assert.That(sut, Is.EquivalentTo(new [] { v1, v3 })); Assert.That(sut.Contains(v1), Is.True); Assert.That(sut.Contains(v2), Is.False); Assert.That(sut.Contains(v3), Is.True); Assert.That(sut.GetRanges(), Is.EquivalentTo(new []{ new Interval<int>(v1, v1 + 1), new Interval<int>(v3, v3 + 1) })); }
public void RemoveStandAloneElement() { // Arrange var sut = new OrderedRangedSet<int>(); int[] arr = new [] { 1234, 123, 456, 5678, 789 }; foreach(int v in arr) sut.Add(v); // Act sut.Remove(arr[2]); // Assert Assert.That(sut.IsEmpty, Is.False); Assert.That(sut.Count, Is.EqualTo(arr.Length - 1)); Assert.That(sut, Is.EquivalentTo(arr.Where(i => i != arr[2]).OrderBy(i => i))); foreach(int v in arr.Where(i => i != arr[2])) Assert.That(sut.Contains(v), Is.True); Assert.That(sut.GetRanges(), Is.EquivalentTo(arr.Where(i => i != arr[2]).Select(i => new Interval<int>(i, i + 1)))); }