NativeAnimationCurveTest.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using System;
  2. using LitMotion.Collections;
  3. using NUnit.Framework;
  4. using Unity.Collections;
  5. using UnityEngine;
  6. using UnityEngine.TestTools.Utils;
  7. namespace LitMotion.Tests.Runtime
  8. {
  9. public class NativeAnimationCurveTest
  10. {
  11. [Test]
  12. public void Test_NativeAnimationCurve_Evaluate()
  13. {
  14. var curve = AnimationCurve.EaseInOut(0f, 0f, 1f, 1f);
  15. using var native = new NativeAnimationCurve(curve, Allocator.Temp);
  16. for (int i = 0; i < 100; i++)
  17. {
  18. var t = Mathf.InverseLerp(0, 99, i);
  19. Assert.That(curve.Evaluate(t), Is.EqualTo(native.Evaluate(t)).Using(FloatEqualityComparer.Instance));
  20. }
  21. }
  22. [Test]
  23. public void Test_UnsafeAnimationCurve_Evaluate()
  24. {
  25. var curve = AnimationCurve.EaseInOut(0f, 0f, 1f, 1f);
  26. using var native = new UnsafeAnimationCurve(curve, Allocator.Temp);
  27. for (int i = 0; i < 100; i++)
  28. {
  29. var t = Mathf.InverseLerp(0, 99, i);
  30. Assert.That(curve.Evaluate(t), Is.EqualTo(native.Evaluate(t)).Using(FloatEqualityComparer.Instance));
  31. }
  32. }
  33. #if ENABLE_UNITY_COLLECTIONS_CHECKS
  34. [Test]
  35. public void Test_NativeAnimationCurve_Dispose()
  36. {
  37. var curve = AnimationCurve.EaseInOut(0f, 0f, 1f, 1f);
  38. var native = new NativeAnimationCurve(curve, Allocator.Temp);
  39. native.Dispose();
  40. try
  41. {
  42. native.Evaluate(0f);
  43. }
  44. catch (ObjectDisposedException)
  45. {
  46. return;
  47. }
  48. Assert.Fail();
  49. }
  50. [Test]
  51. public void Test_NativeAnimationCurve_Dispose_RewindableAllocator()
  52. {
  53. var curve = AnimationCurve.EaseInOut(0f, 0f, 1f, 1f);
  54. var allocator = RewindableAllocatorFactory.CreateAllocator();
  55. var native = new NativeAnimationCurve(curve, allocator.Allocator.Handle);
  56. allocator.Allocator.Rewind();
  57. try
  58. {
  59. native.Evaluate(0f);
  60. }
  61. catch (ObjectDisposedException)
  62. {
  63. return;
  64. }
  65. Assert.Fail();
  66. }
  67. #endif
  68. }
  69. }