Geen omschrijving
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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