FloatEqualityComparer.cs 865 B

123456789101112131415161718192021222324252627282930
  1. using System.Collections.Generic;
  2. namespace UnityEngine.TestTools.Utils
  3. {
  4. public class FloatEqualityComparer : IEqualityComparer<float>
  5. {
  6. private const float k_DefaultError = 0.0001f;
  7. private readonly float AllowedError;
  8. private static readonly FloatEqualityComparer m_Instance = new FloatEqualityComparer();
  9. public static FloatEqualityComparer Instance { get { return m_Instance; } }
  10. private FloatEqualityComparer() : this(k_DefaultError) {}
  11. public FloatEqualityComparer(float allowedError)
  12. {
  13. this.AllowedError = allowedError;
  14. }
  15. public bool Equals(float expected, float actual)
  16. {
  17. return Utils.AreFloatsEqual(expected, actual, AllowedError);
  18. }
  19. public int GetHashCode(float value)
  20. {
  21. return 0;
  22. }
  23. }
  24. }