AssertFloat.cs 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using System.Diagnostics;
  2. using UnityEngine.Assertions.Comparers;
  3. namespace XGame.Framework
  4. {
  5. public partial class Assert
  6. {
  7. [Conditional(MacroDefine.XGAME_ASSERT), Conditional(MacroDefine.UNITY_EDITOR)]
  8. public static void AreApproximatelyEqual(float expected, float actual)
  9. {
  10. AreEqual(expected, actual, FloatComparer.s_ComparerWithDefaultTolerance, null);
  11. }
  12. [Conditional(MacroDefine.XGAME_ASSERT), Conditional(MacroDefine.UNITY_EDITOR)]
  13. public static void AreApproximatelyEqual(float expected, float actual, string format, params object[] args)
  14. {
  15. AreEqual(expected, actual, FloatComparer.s_ComparerWithDefaultTolerance, format, args);
  16. }
  17. [Conditional(MacroDefine.XGAME_ASSERT), Conditional(MacroDefine.UNITY_EDITOR)]
  18. public static void AreApproximatelyEqual<T>(float expected, float actual, T e) where T : System.Exception
  19. {
  20. AreEqual(expected, actual, FloatComparer.s_ComparerWithDefaultTolerance, e);
  21. }
  22. [Conditional(MacroDefine.XGAME_ASSERT), Conditional(MacroDefine.UNITY_EDITOR)]
  23. public static void AreApproximatelyEqual(float expected, float actual, float tolerance)
  24. {
  25. AreApproximatelyEqual(expected, actual, tolerance, null);
  26. }
  27. [Conditional(MacroDefine.XGAME_ASSERT), Conditional(MacroDefine.UNITY_EDITOR)]
  28. public static void AreApproximatelyEqual(float expected, float actual, float tolerance, string format, params object[] args)
  29. {
  30. AreEqual(expected, actual, new FloatComparer(tolerance), format, args);
  31. }
  32. [Conditional(MacroDefine.XGAME_ASSERT), Conditional(MacroDefine.UNITY_EDITOR)]
  33. public static void AreApproximatelyEqual<T>(float expected, float actual, float tolerance, T e) where T : System.Exception
  34. {
  35. AreEqual(expected, actual, new FloatComparer(tolerance), e);
  36. }
  37. [Conditional(MacroDefine.XGAME_ASSERT), Conditional(MacroDefine.UNITY_EDITOR)]
  38. public static void AreNotApproximatelyEqual(float expected, float actual)
  39. {
  40. AreNotEqual(expected, actual, null, FloatComparer.s_ComparerWithDefaultTolerance);
  41. }
  42. [Conditional(MacroDefine.XGAME_ASSERT), Conditional(MacroDefine.UNITY_EDITOR)]
  43. public static void AreNotApproximatelyEqual(float expected, float actual, string format, params object[] args)
  44. {
  45. AreNotEqual(expected, actual, FloatComparer.s_ComparerWithDefaultTolerance, format, args);
  46. }
  47. [Conditional(MacroDefine.XGAME_ASSERT), Conditional(MacroDefine.UNITY_EDITOR)]
  48. public static void AreNotApproximatelyEqual<T>(float expected, float actual, T e) where T : System.Exception
  49. {
  50. AreNotEqual(expected, actual, FloatComparer.s_ComparerWithDefaultTolerance, e);
  51. }
  52. [Conditional(MacroDefine.XGAME_ASSERT), Conditional(MacroDefine.UNITY_EDITOR)]
  53. public static void AreNotApproximatelyEqual(float expected, float actual, float tolerance)
  54. {
  55. AreNotApproximatelyEqual(expected, actual, tolerance, null);
  56. }
  57. [Conditional(MacroDefine.XGAME_ASSERT), Conditional(MacroDefine.UNITY_EDITOR)]
  58. public static void AreNotApproximatelyEqual(float expected, float actual, float tolerance, string format, params object[] args)
  59. {
  60. AreNotEqual(expected, actual, new FloatComparer(tolerance), format, args);
  61. }
  62. [Conditional(MacroDefine.XGAME_ASSERT), Conditional(MacroDefine.UNITY_EDITOR)]
  63. public static void AreNotApproximatelyEqual<T>(float expected, float actual, float tolerance, T e) where T : System.Exception
  64. {
  65. AreNotEqual(expected, actual, new FloatComparer(tolerance), e);
  66. }
  67. }
  68. }