docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Custom equality comparers

    To enable easier verification of custom Unity type values in your tests we provide you with some custom equality comparers:

    • ColorEqualityComparer
    • FloatEqualityComparer
    • QuaternionEqualityComparer
    • Vector2EqualityComparer
    • Vector3EqualityComparer
    • Vector4EqualityComparer

    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. To set a specific error value, instantiate a new comparer object using a one argument constructor ctor(float error).

    Static properties

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

    Constructors

    Syntax Description
    ctor(float error) Creates an instance of comparer with a custom error value.allowedError. The relative error to be considered while comparing two values.

    Public methods

    Syntax Description
    bool Equals(T expected, T actual); Compares the actual and expected objects for equality using a custom comparison mechanism. Returns true if expected and actual objects are equal, otherwise it returns false.
    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)