MotionHandleTest.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. using System.Collections;
  2. using UnityEngine;
  3. using UnityEngine.Assertions;
  4. using UnityEngine.TestTools;
  5. namespace LitMotion.Tests.Runtime
  6. {
  7. public class MotionHandleTest
  8. {
  9. [UnityTest]
  10. public IEnumerator Test_Cancel()
  11. {
  12. var value = 0f;
  13. var endValue = 10f;
  14. var handle = LMotion.Create(0f, endValue, 2f)
  15. .Bind(x =>
  16. {
  17. value = x;
  18. Debug.Log(x);
  19. });
  20. yield return new WaitForSeconds(1f);
  21. handle.Cancel();
  22. yield return new WaitForSeconds(1f);
  23. Assert.IsTrue(value < endValue);
  24. Assert.IsTrue(!handle.IsActive());
  25. }
  26. [UnityTest]
  27. public IEnumerator Test_Complete()
  28. {
  29. var value = 0f;
  30. var endValue = 10f;
  31. var handle = LMotion.Create(0f, endValue, 2f)
  32. .Bind(x =>
  33. {
  34. value = x;
  35. Debug.Log(x);
  36. });
  37. yield return new WaitForSeconds(1f);
  38. handle.Complete();
  39. Assert.AreApproximatelyEqual(value, endValue);
  40. Assert.IsTrue(!handle.IsActive());
  41. }
  42. [UnityTest]
  43. public IEnumerator Test_Complete_WithYoyoLoop()
  44. {
  45. var value = 0f;
  46. var startValue = 0f;
  47. var handle = LMotion.Create(startValue, 10f, 2f)
  48. .WithLoops(2, LoopType.Yoyo)
  49. .Bind(x =>
  50. {
  51. value = x;
  52. Debug.Log(x);
  53. });
  54. yield return new WaitForSeconds(1f);
  55. handle.Complete();
  56. Assert.AreApproximatelyEqual(value, startValue);
  57. Assert.IsTrue(!handle.IsActive());
  58. }
  59. [UnityTest]
  60. public IEnumerator Test_CompleteAndCancel_WithInfiniteLoop()
  61. {
  62. var value = 0f;
  63. var startValue = 0f;
  64. var handle = LMotion.Create(startValue, 10f, 2f)
  65. .WithLoops(-1)
  66. .Bind(x =>
  67. {
  68. value = x;
  69. Debug.Log(x);
  70. });
  71. yield return new WaitForSeconds(1f);
  72. handle.Complete();
  73. Assert.IsTrue(handle.IsActive());
  74. handle.Cancel();
  75. Assert.IsTrue(!handle.IsActive());
  76. }
  77. [UnityTest]
  78. public IEnumerator Test_ToDisposable()
  79. {
  80. var value = 0f;
  81. var endValue = 10f;
  82. var disposable = LMotion.Create(0f, endValue, 2f)
  83. .Bind(x =>
  84. {
  85. value = x;
  86. Debug.Log(x);
  87. })
  88. .ToDisposable();
  89. yield return new WaitForSeconds(1f);
  90. disposable.Dispose();
  91. yield return new WaitForSeconds(1f);
  92. Assert.IsTrue(value < endValue);
  93. }
  94. [UnityTest]
  95. public IEnumerator Test_IsActive()
  96. {
  97. MotionHandle handle = LMotion.Create(0f, 10f, 2f).RunWithoutBinding();
  98. Assert.IsTrue(handle.IsActive());
  99. yield return new WaitForSeconds(2.5f);
  100. Assert.IsFalse(handle.IsActive());
  101. }
  102. }
  103. }