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

Vector2ComparerWithEqualsOperator.cs 2.2KB

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