using System; using System.Collections.Generic; namespace UnityEngine.TestTools.Utils { /// /// 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. /// public class Vector3ComparerWithEqualsOperator : IEqualityComparer { private static readonly Vector3ComparerWithEqualsOperator m_Instance = new Vector3ComparerWithEqualsOperator(); /// /// A singleton instance of the comparer with a predefined default error value. /// public static Vector3ComparerWithEqualsOperator Instance { get { return m_Instance; } } private Vector3ComparerWithEqualsOperator() {} /// /// Compares the actual and expected objects for equality using a custom comparison mechanism. /// /// Expected Vector3 used to compare /// Actual Vector3 value to test. /// Returns true if expected and actual objects are equal, otherwise it returns false. /// /// /// [TestFixture] /// public class Vector3Test /// { /// [Test] /// public void VerifyThat_TwoVector3ObjectsAreEqual() /// { /// var actual = new Vector2(10e-7f, 10e-7f, 10e-7f); /// var expected = new Vector2(0f, 0f, 0f); /// /// Assert.That(actual, Is.EqualTo(expected).Using(Vector3ComparerWithEqualsOperator.Instance)); /// } /// } /// /// public bool Equals(Vector3 expected, Vector3 actual) { return expected == actual; } /// /// Serves as the default hash function. /// /// A not null Vector3 object /// Returns 0 public int GetHashCode(Vector3 vec3) { return 0; } } }