Triangle2DTests GetHashCodeViaDictionary Method Delta Engine Documentation

Namespace: DeltaEngine.Rendering2D.Shapes.Tests
Assembly: DeltaEngine.Rendering2D.Shapes.Tests (in DeltaEngine.Rendering2D.Shapes.Tests.dll) Version: 1.1.1.0 (1.1.1)
Syntax

public void GetHashCodeViaDictionary()
Examples

[Test]
public void GetHashCodeViaDictionary()
{
    var triangle1 = new Triangle2D(new Vector2D(1, 2), new Vector2D(3, 4), new Vector2D(5, 6));
    var triangle1Similar = new Triangle2D(new Vector2D(1, 2), new Vector2D(3, 4),
        new Vector2D(15, 16));
    var triangle2 = new Triangle2D(new Vector2D(11, 12), new Vector2D(13, 14),
        new Vector2D(15, 16));
    var triangles = new Dictionary<Triangle2D, int> { { triangle1, 1 }, { triangle2, 2 } };
    Assert.IsTrue(triangles.ContainsKey(triangle1));
    Assert.IsTrue(triangles.ContainsKey(triangle2));
    Assert.IsFalse(
        triangles.ContainsKey(new Triangle2D(new Vector2D(1, 2), new Vector2D(3, 4),
            new Vector2D(5, 7))));
    Assert.AreNotEqual(triangle1.GetHashCode(), triangle1Similar.GetHashCode());
}
See Also