public void Equals_GetHashCode_Contract() { var rnd = new System.Random(); var offset = rnd.NextDouble() * 60; if (rnd.NextDouble() < 0.5) { offset *= -1; } var leftLine = new List <LineString> { GetLineString(offset + 1), GetLineString(offset + 2) }; var left = new MultiLineString(leftLine); var rightLine = new List <LineString> { GetLineString(offset + 1), GetLineString(offset + 2) }; var right = new MultiLineString(rightLine); Assert.AreEqual(left, right); Assert.AreEqual(right, left); Assert.IsTrue(left.Equals(right)); Assert.IsTrue(left.Equals(left)); Assert.IsTrue(right.Equals(left)); Assert.IsTrue(right.Equals(right)); Assert.IsTrue(left == right); Assert.IsTrue(right == left); Assert.AreEqual(left.GetHashCode(), right.GetHashCode()); }
public void TestMultiLineStringEqualsHashCode() { var multiLineString1 = new MultiLineString( new[] { new LineStringCoordinates(new[] { new Position(20, 30), new Position(30, 40) }), new LineStringCoordinates(new[] { new Position(40, 50), new Position(60, 60) }) }, new GeometryParams { AdditionalProperties = new Dictionary <string, object> { { "a", "b" } }, BoundingBox = new BoundingBox(new Position(0, 0), new Position(40, 40)), Crs = Crs.Named("SomeCrs") }); var multiLineString2 = new MultiLineString( new[] { new LineStringCoordinates(new[] { new Position(20, 30), new Position(30, 40) }), new LineStringCoordinates(new[] { new Position(40, 50), new Position(60, 60) }) }, new GeometryParams { AdditionalProperties = new Dictionary <string, object> { { "a", "b" } }, BoundingBox = new BoundingBox(new Position(0, 0), new Position(40, 40)), Crs = Crs.Named("SomeCrs") }); var multiLineString3 = new MultiLineString( new[] { new LineStringCoordinates(new[] { new Position(20, 30), new Position(30, 41) }), new LineStringCoordinates(new[] { new Position(40, 50), new Position(60, 60) }) }, new GeometryParams { AdditionalProperties = new Dictionary <string, object> { { "a", "b" } }, BoundingBox = new BoundingBox(new Position(0, 0), new Position(40, 40)), Crs = Crs.Named("SomeCrs") }); var multiLineString4 = new MultiLineString( new[] { new LineStringCoordinates(new[] { new Position(20, 30), new Position(30, 40) }), new LineStringCoordinates(new[] { new Position(40, 50), new Position(60, 60) }) }, new GeometryParams { AdditionalProperties = new Dictionary <string, object> { { "b", "c" } }, BoundingBox = new BoundingBox(new Position(0, 0), new Position(40, 40)), Crs = Crs.Named("SomeCrs") }); var multiLineString5 = new MultiLineString( new[] { new LineStringCoordinates(new[] { new Position(20, 30), new Position(30, 40) }), new LineStringCoordinates(new[] { new Position(40, 50), new Position(60, 60) }) }, new GeometryParams { AdditionalProperties = new Dictionary <string, object> { { "a", "b" } }, BoundingBox = new BoundingBox(new Position(0, 0), new Position(40, 41)), Crs = Crs.Named("SomeCrs") }); var multiLineString6 = new MultiLineString( new[] { new LineStringCoordinates(new[] { new Position(20, 30), new Position(30, 40) }), new LineStringCoordinates(new[] { new Position(40, 50), new Position(60, 60) }) }, new GeometryParams { AdditionalProperties = new Dictionary <string, object> { { "a", "b" } }, BoundingBox = new BoundingBox(new Position(0, 0), new Position(40, 40)), Crs = Crs.Named("SomeCrs1") }); Assert.AreEqual(multiLineString1, multiLineString2); Assert.AreEqual(multiLineString1.GetHashCode(), multiLineString2.GetHashCode()); Assert.AreNotEqual(multiLineString1, multiLineString3); Assert.AreNotEqual(multiLineString1.GetHashCode(), multiLineString3.GetHashCode()); Assert.AreNotEqual(multiLineString1, multiLineString4); Assert.AreNotEqual(multiLineString1.GetHashCode(), multiLineString4.GetHashCode()); Assert.AreNotEqual(multiLineString1, multiLineString5); Assert.AreNotEqual(multiLineString1.GetHashCode(), multiLineString5.GetHashCode()); Assert.AreNotEqual(multiLineString1, multiLineString6); Assert.AreNotEqual(multiLineString1.GetHashCode(), multiLineString6.GetHashCode()); }