暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Vector4ComparerWithEqualsOperator.cs 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System.Collections.Generic;
  2. namespace UnityEngine.TestTools.Utils
  3. {
  4. /// <summary>
  5. /// 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.
  6. /// </summary>
  7. public class Vector4ComparerWithEqualsOperator : IEqualityComparer<Vector4>
  8. {
  9. private static readonly Vector4ComparerWithEqualsOperator m_Instance = new Vector4ComparerWithEqualsOperator();
  10. /// <summary>
  11. /// A singleton instance of the comparer with a predefined default error value.
  12. /// </summary>
  13. public static Vector4ComparerWithEqualsOperator Instance { get { return m_Instance; } }
  14. private Vector4ComparerWithEqualsOperator() {}
  15. /// <summary>
  16. /// Compares the actual and expected objects for equality using a custom comparison mechanism.
  17. /// </summary>
  18. /// <param name="expected">Expected Vector4 used to compare</param>
  19. /// <param name="actual">Actual Vector4 value to test.</param>
  20. /// <returns>Returns true if expected and actual objects are equal, otherwise it returns false.</returns>
  21. /// <example>
  22. /// <code>
  23. /// [TestFixture]
  24. /// public class Vector4Test
  25. /// {
  26. /// [Test]
  27. /// public void VerifyThat_TwoVector4ObjectsAreEqual()
  28. /// {
  29. /// var actual = new Vector4(10e-7f, 10e-7f, 10e-7f, 10e-7f);
  30. /// var expected = new Vector4(0f, 0f, 0f, 0f);
  31. ///
  32. /// Assert.That(actual, Is.EqualTo(expected).Using(Vector4ComparerWithEqualsOperator.Instance));
  33. /// }
  34. /// }
  35. /// </code>
  36. /// </example>
  37. public bool Equals(Vector4 expected, Vector4 actual)
  38. {
  39. return expected == actual;
  40. }
  41. /// <summary>
  42. /// Serves as the default hash function.
  43. /// </summary>
  44. /// <param name="vec4"> A not null Vector4 object</param>
  45. /// <returns>Returns 0</returns>
  46. public int GetHashCode(Vector4 vec4)
  47. {
  48. return 0;
  49. }
  50. }
  51. }