public static void Contains_Returns_True_or_False_Indicating_Presence_of_Segment() { List <CartesianCoordinate> coordinates = new List <CartesianCoordinate>() { new CartesianCoordinate(1, 1), new CartesianCoordinate(1, 2), new CartesianCoordinate(3, 4), new CartesianCoordinate(5, 6) }; List <LineSegment> segments = new List <LineSegment>() { new LineSegment(coordinates[0], coordinates[1]), new LineSegment(coordinates[1], coordinates[2]), new LineSegment(coordinates[2], coordinates[3]) }; SegmentsBoundary boundary = new SegmentsBoundary(segments); Assert.IsTrue(boundary.Contains(new LineSegment(coordinates[1], coordinates[2]))); Assert.IsFalse(boundary.Contains( new LineSegment( new CartesianCoordinate(5, 6), new CartesianCoordinate(7, 8)))); }
public static void Replace_Replaces_Segment_if_Present() { List <CartesianCoordinate> coordinates = new List <CartesianCoordinate>() { new CartesianCoordinate(0, 0), new CartesianCoordinate(1, 2), new CartesianCoordinate(3, 4), new CartesianCoordinate(5, 6) }; List <LineSegment> segments = new List <LineSegment>() { new LineSegment(coordinates[0], coordinates[1]), new LineSegment(coordinates[1], coordinates[2]), new LineSegment(coordinates[2], coordinates[3]) }; SegmentsBoundary boundary = new SegmentsBoundary(segments); Assert.AreEqual(3, boundary.Count); Assert.AreEqual(1, boundary[1].I.X); Assert.AreEqual(2, boundary[1].I.Y); // Replaces existing segment IPathSegment newSegment = new LineSegment(coordinates[2], coordinates[3]); Assert.IsTrue(boundary.Replace(segments[2], newSegment)); Assert.AreEqual(3, boundary.Count); Assert.AreEqual(1, boundary[1].I.X); Assert.AreEqual(2, boundary[1].I.Y); // Does not replace non-existing segment IPathSegment newInvalidSegment = new LineSegment( new CartesianCoordinate(5, 6), new CartesianCoordinate(7, 8)); Assert.IsFalse(boundary.Replace(segments[2], newInvalidSegment)); Assert.IsFalse(boundary.Replace(newInvalidSegment, segments[2])); Assert.AreEqual(3, boundary.Count); Assert.IsFalse(boundary.Contains(newInvalidSegment)); }