public void ContainsItself_ReturnsTrue() { foreach (var DekRange in DekRanges) { Assert.That(DekRange.Contains(DekRange), Is.True); } }
public void ContainsInt_ReturnsTrue_IfInsideRange() { // Arrange var DekRange = new DekRange(5, 10); // Assert & Act // Values before range foreach (int i in new int[] { 0, 1, 2, 3, 4 }) { Assert.That(DekRange.Contains(i), Is.False); } // Inside range foreach (int i in new int[] { 5, 6, 7, 8, 9, 10 }) { Assert.That(DekRange.Contains(i), Is.True); } // After range foreach (int i in new int[] { 11, 12, 13, 100000 }) { Assert.That(DekRange.Contains(i), Is.False); } // Special case Assert.DoesNotThrow(() => DekRange.Contains(-1)); }
public void Range_14_DoesNotOverlap_59_vice_versa() { var testRange = new DekRange(1, 4); var otherRange = new DekRange(5, 9); // Assert Assert.That(testRange.Intersects(otherRange), Is.False); Assert.That(otherRange.Intersects(testRange), Is.False); }
public void Range_19_Overlaps_46_vice_versa() { var testRange = new DekRange(1, 9); var otherRange = new DekRange(4, 6); // Assert Assert.That(testRange.Intersects(otherRange), Is.True); Assert.That(otherRange.Intersects(testRange), Is.True); }
public void Range_14_DoesNotContians_01_nor_45() { var testRange = new DekRange(1, 4); var otherRange1 = new DekRange(0, 1); var otherRange2 = new DekRange(4, 5); // Assert Assert.That(testRange.Contains(otherRange1), Is.False); Assert.That(testRange.Contains(otherRange2), Is.False); }
public void Range_14_Contians_11_and_44() { var testRange = new DekRange(1, 4); var otherRange1 = new DekRange(1, 1); var otherRange2 = new DekRange(4, 4); // Assert Assert.That(testRange.Contains(otherRange1), Is.True); Assert.That(testRange.Contains(otherRange2), Is.True); }
public void AddAndMerge_New_Inside_Range_Does_Not_Alter_Ranges() { // Given var testRange = new DekRange(1, 4); // When List <DekRange> newRange = DisconnectedDekRanges1.AddAndMerge(testRange); // Then AssertRangesEqual(GenerateDisconnectedRange(), newRange); }
public void AddAndMerge_New_Inside_Range_Does_Not_Alter_Ranges() { // Given var testRange = new DekRange(1, 4); // When List <DekRange> newRange = DisconnectedDekRanges1.AddAndMerge(testRange); // Then DekRangeListTestHelper.AssertRangesEqual(DisconnectedDekRanges1, newRange); }
public static List <DekRange> SubtractRange(this List <DekRange> me, DekRange range) { List <DekRange> result = new List <DekRange>(); foreach (DekRange r in me) { result.AddRange(r.Subtract(range)); } return(result); }
public void Range_00_or_55_DoesNotIntersect_14_vice_versa() { var testRange = new DekRange(1, 4); var otherRange2 = new DekRange(0, 0); var otherRange1 = new DekRange(5, 5); // Assert Assert.That(testRange.Intersects(otherRange1), Is.False); Assert.That(otherRange1.Intersects(testRange), Is.False); Assert.That(testRange.Intersects(otherRange2), Is.False); Assert.That(otherRange2.Intersects(testRange), Is.False); }
public void Range_14_Intersect_01_and_45_and_vice_versa() { var testRange = new DekRange(1, 4); var otherRange1 = new DekRange(0, 1); var otherRange2 = new DekRange(4, 5); // Assert Assert.That(testRange.Intersects(otherRange1), Is.True); Assert.That(testRange.Intersects(otherRange2), Is.True); Assert.That(otherRange1.Intersects(testRange), Is.True); Assert.That(otherRange2.Intersects(testRange), Is.True); }
public void Subtract_15_from_14_Returns_EmptySet() { // Arrange var DekRange = new DekRange(1, 4); var subtractor = new DekRange(1, 5); // Act var result = DekRange.Subtract(subtractor); // Assert Assert.That(result.Count, Is.EqualTo(0)); }
/// <summary> /// Returns true if any range in list contains the provided range. /// </summary> public static bool ContainsRange(this List <DekRange> me, DekRange range) { foreach (DekRange r in me) { if (r.Contains(range)) { return(true); } } return(false); }
public void Subtract_24_from_14_Returns_11() { // Arrange var DekRange = new DekRange(1, 4); var subtractor = new DekRange(2, 4); var expected = new DekRange(1, 1); // Act var result = DekRange.Subtract(subtractor); // Assert Assert.That(result.Count, Is.EqualTo(1)); Assert.That(result[0], Is.EqualTo(expected)); }
public void BiggerContainsSmaller_And_NotTheOpposite() { foreach (var DekRange in DekRanges) { var biggerDekRange = new DekRange(DekRange.Start, DekRange.Stop + 1); Assert.That(biggerDekRange.Contains(DekRange), Is.True); Assert.That(DekRange.Contains(biggerDekRange), Is.False); // reverse var biggerReverseDekRange = new DekRange(DekRange.Stop + 1, DekRange.Start); Assert.That(biggerReverseDekRange.Contains(DekRange), Is.True); Assert.That(DekRange.Contains(biggerReverseDekRange), Is.False); } }
public void Subtract_All() { // Given var subtractor = new DekRange(0, 25); var expectedRange = new List <DekRange> { }; // When List <DekRange> newRange = DisconnectedDekRanges1.SubtractRange(subtractor); // Then DekRangeListTestHelper.AssertRangesEqual(expectedRange, newRange); }
public void Subtract_Touching_Ranges8() { // Given var testRange = new DekRange(1, 100); var expectedRange = new List <DekRange> { new DekRange(0, 0), }; // When List <DekRange> newRange = DekRangeListTestHelper.Touchingrange.SubtractRange(testRange); // Then DekRangeListTestHelper.AssertRangesEqual(expectedRange, newRange); }
public static void LoadFromText(this List <DekRange> me, string text) { if (string.IsNullOrWhiteSpace(text)) { return; } string[] asdjh = text.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); foreach (string s in asdjh) { string[] ns = s.Split(','); DekRange tr = new DekRange(int.Parse(ns[0]), int.Parse(ns[1])); me.Add(tr); } }
public void AddAndMerge_Overlapping_Ranges7() { // Given var testRange = new DekRange(1, 50); // Engulf all of testrange 2 var expectedRange = new List <DekRange> { new DekRange(1, 50), }; // When List <DekRange> newRange = DisconnectedDekRanges2.AddAndMerge(testRange); // Then AssertRangesEqual(expectedRange, newRange); }
public void AddAndMerge_Overlapping_Ranges4() { // Given var testRange = new DekRange(0, 25); var expectedRange = new List <DekRange> { new DekRange(0, 25), }; // When List <DekRange> newRange = DisconnectedDekRanges1.AddAndMerge(testRange); // Then AssertRangesEqual(expectedRange, newRange); }
public void Subtract_Last4() { // Given var subtractor = new DekRange(19, 26); var expectedRange = new List <DekRange> { new DekRange(0, 5), new DekRange(10, 15) }; // When List <DekRange> newRange = DisconnectedDekRanges1.SubtractRange(subtractor); // Then DekRangeListTestHelper.AssertRangesEqual(expectedRange, newRange); }
public void Subtract_12_from_03_Returns_00_and_33() { // Arrange var DekRange = new DekRange(0, 3); var subtractor = new DekRange(1, 2); var expected1 = new DekRange(0, 0); var expected2 = new DekRange(3, 3); // Act var result = DekRange.Subtract(subtractor); // Assert Assert.That(result.Count, Is.EqualTo(2)); Assert.That(result[0], Is.EqualTo(expected1)); Assert.That(result[1], Is.EqualTo(expected2)); }
public void Subtract_22_from_14_Returns_11_and_34() { // Arrange var DekRange = new DekRange(1, 4); var subtractor = new DekRange(2, 2); var expected1 = new DekRange(1, 1); var expected2 = new DekRange(3, 4); // Act var result = DekRange.Subtract(subtractor); // Assert Assert.That(result.Count, Is.EqualTo(2)); Assert.That(result[0], Is.EqualTo(expected1)); Assert.That(result[1], Is.EqualTo(expected2)); }
public void Subtract_SomeOfRangeAndAllOfNextAndMore() { // Given var subtractor = new DekRange(1, 16); var expectedRange = new List <DekRange> { new DekRange(0, 0), new DekRange(20, 25) }; // When List <DekRange> newRange = DisconnectedDekRanges1.SubtractRange(subtractor); // Then DekRangeListTestHelper.AssertRangesEqual(expectedRange, newRange); }
public void Subtract_EndOfRangePlusMore() { // Given var subtractor = new DekRange(1, 9); var expectedRange = new List <DekRange> { new DekRange(0, 0), new DekRange(10, 15), new DekRange(20, 25) }; // When List <DekRange> newRange = DisconnectedDekRanges1.SubtractRange(subtractor); // Then DekRangeListTestHelper.AssertRangesEqual(expectedRange, newRange); }
public void Subtract_Is_Pure() { // Given var subtractor = new DekRange(11, 12); var expectedRange = new List <DekRange> { new DekRange(0, 5), new DekRange(10, 15), new DekRange(20, 25), }; // When List <DekRange> newRange = DisconnectedDekRanges1.AddAndMerge(subtractor); // Then DekRangeListTestHelper.AssertRangesEqual(expectedRange, DisconnectedDekRanges1); }
public void AddAndMerge_Is_Pure() { // Given var testRange = new DekRange(40, 45); var expectedRange = new List <DekRange> { new DekRange(10, 15), new DekRange(20, 25), new DekRange(30, 35), }; // When List <DekRange> newRange = DisconnectedDekRanges2.AddAndMerge(testRange); // Then AssertRangesEqual(expectedRange, DisconnectedDekRanges2); }
public void AddAndMerge_Overlapping_Ranges2() { // Given var testRange = new DekRange(9, 11); var expectedRange = new List <DekRange> { new DekRange(0, 5), new DekRange(9, 15), new DekRange(20, 25) }; // When List <DekRange> newRange = DisconnectedDekRanges1.AddAndMerge(testRange); // Then DekRangeListTestHelper.AssertRangesEqual(expectedRange, newRange); }
public void AddAndMerge_Non_Overlapping_Ranges2() { // Given var testRange = new DekRange(40, 45); var expectedRange = new List <DekRange> { new DekRange(10, 15), new DekRange(20, 25), new DekRange(30, 35), new DekRange(40, 45), }; // When List <DekRange> newRange = DisconnectedDekRanges2.AddAndMerge(testRange); // Then DekRangeListTestHelper.AssertRangesEqual(expectedRange, newRange); }
public void AddAndMerge_Touching_Ranges3() { // Given var testRange = new DekRange(6, 9); var expectedRange = new List <DekRange> { new DekRange(0, 5), new DekRange(6, 9), new DekRange(10, 15), new DekRange(20, 25), }; // When List <DekRange> newRange = DisconnectedDekRanges1.AddAndMerge(testRange); // Then AssertRangesEqual(expectedRange, newRange); }