docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class Vector2ComparerWithEqualsOperator

    Use these classes to compare two objects of the same type for equality within the range of a given tolerance using NUnit or custom constraints . Call Instance to apply the default calculation error value to the comparison.

    Inheritance
    object
    Vector2ComparerWithEqualsOperator
    Implements
    IEqualityComparer<Vector2>
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: UnityEngine.TestTools.Utils
    Assembly: UnityEngine.TestRunner.dll
    Syntax
    public class Vector2ComparerWithEqualsOperator : IEqualityComparer<Vector2>

    Properties

    Instance

    A singleton instance of the comparer with a predefined default error value.

    Declaration
    public static Vector2ComparerWithEqualsOperator Instance { get; }
    Property Value
    Type Description
    Vector2ComparerWithEqualsOperator

    Methods

    Equals(Vector2, Vector2)

    Compares the actual and expected objects for equality using a custom comparison mechanism.

    Declaration
    public bool Equals(Vector2 expected, Vector2 actual)
    Parameters
    Type Name Description
    Vector2 expected

    Expected Vector2 used to compare

    Vector2 actual

    Actual Vector2 value to test.

    Returns
    Type Description
    bool

    Returns true if expected and actual objects are equal, otherwise it returns false.

    Examples
    [TestFixture]
    public class Vector2Test
    {
        [Test]
        public void VerifyThat_TwoVector2ObjectsAreEqual()
        {
            var actual = new Vector2(10e-7f, 10e-7f);
            var expected = new Vector2(0f, 0f);
    
            Assert.That(actual, Is.EqualTo(expected).Using(Vector2ComparerWithEqualsOperator.Instance));
        }
    }

    GetHashCode(Vector2)

    Serves as the default hash function.

    Declaration
    public int GetHashCode(Vector2 vec2)
    Parameters
    Type Name Description
    Vector2 vec2

    A not null Vector2 object

    Returns
    Type Description
    int

    Returns 0

    Implements

    IEqualityComparer<T>
    In This Article
    Back to top
    Copyright © 2024 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)