SchedulerTest.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. using System.Collections;
  2. using NUnit.Framework;
  3. using UnityEngine;
  4. using UnityEngine.TestTools;
  5. namespace LitMotion.Tests.Runtime
  6. {
  7. public class SchedulerTest
  8. {
  9. const float Duration = 0.2f;
  10. [TearDown]
  11. public void TearDown()
  12. {
  13. Time.timeScale = 1;
  14. }
  15. [UnityTest]
  16. public IEnumerator Test_Scheduler_Initialization()
  17. {
  18. yield return LMotion.Create(0f, 10f, Duration)
  19. .WithScheduler(MotionScheduler.Initialization)
  20. .RunWithoutBinding()
  21. .ToYieldInteraction();
  22. }
  23. [UnityTest]
  24. public IEnumerator Test_Scheduler_Initialization_IgnoreTimeScale()
  25. {
  26. Time.timeScale = 0;
  27. yield return LMotion.Create(0f, 10f, Duration)
  28. .WithScheduler(MotionScheduler.InitializationIgnoreTimeScale)
  29. .RunWithoutBinding()
  30. .ToYieldInteraction();
  31. }
  32. [UnityTest]
  33. public IEnumerator Test_Scheduler_Initialization_Realtime()
  34. {
  35. Time.timeScale = 0;
  36. yield return LMotion.Create(0f, 10f, Duration)
  37. .WithScheduler(MotionScheduler.InitializationRealtime)
  38. .RunWithoutBinding()
  39. .ToYieldInteraction();
  40. }
  41. [UnityTest]
  42. public IEnumerator Test_Scheduler_EarlyUpdate()
  43. {
  44. yield return LMotion.Create(0f, 10f, Duration)
  45. .WithScheduler(MotionScheduler.EarlyUpdate)
  46. .RunWithoutBinding()
  47. .ToYieldInteraction();
  48. }
  49. [UnityTest]
  50. public IEnumerator Test_Scheduler_EarlyUpdate_IgnoreTimeScale()
  51. {
  52. Time.timeScale = 0;
  53. yield return LMotion.Create(0f, 10f, Duration)
  54. .WithScheduler(MotionScheduler.EarlyUpdateIgnoreTimeScale)
  55. .RunWithoutBinding()
  56. .ToYieldInteraction();
  57. }
  58. [UnityTest]
  59. public IEnumerator Test_Scheduler_EarlyUpdate_Realtime()
  60. {
  61. Time.timeScale = 0;
  62. yield return LMotion.Create(0f, 10f, Duration)
  63. .WithScheduler(MotionScheduler.EarlyUpdateRealtime)
  64. .RunWithoutBinding()
  65. .ToYieldInteraction();
  66. }
  67. [UnityTest]
  68. public IEnumerator Test_Scheduler_FixedUpdate()
  69. {
  70. yield return LMotion.Create(0f, 10f, Duration)
  71. .WithScheduler(MotionScheduler.FixedUpdate)
  72. .Bind(x =>
  73. {
  74. Assert.IsTrue(Time.inFixedTimeStep);
  75. })
  76. .ToYieldInteraction();
  77. }
  78. [UnityTest]
  79. public IEnumerator Test_Scheduler_Update()
  80. {
  81. yield return LMotion.Create(0f, 10f, Duration)
  82. .WithScheduler(MotionScheduler.Update)
  83. .RunWithoutBinding()
  84. .ToYieldInteraction();
  85. }
  86. [UnityTest]
  87. public IEnumerator Test_Scheduler_Update_WithHalfTimeScale()
  88. {
  89. Time.timeScale = 0.5f;
  90. var t = Time.unscaledTimeAsDouble;
  91. yield return LMotion.Create(0f, 10f, Duration)
  92. .WithScheduler(MotionScheduler.Update)
  93. .RunWithoutBinding()
  94. .ToYieldInteraction();
  95. Assert.That(Time.unscaledTimeAsDouble - t, Is.GreaterThan(Duration * 2f));
  96. }
  97. [UnityTest]
  98. public IEnumerator Test_Scheduler_Update_IgnoreTimeScale()
  99. {
  100. Time.timeScale = 0;
  101. yield return LMotion.Create(0f, 10f, Duration)
  102. .WithScheduler(MotionScheduler.UpdateIgnoreTimeScale)
  103. .RunWithoutBinding()
  104. .ToYieldInteraction();
  105. }
  106. [UnityTest]
  107. public IEnumerator Test_Scheduler_Update_Realtime()
  108. {
  109. Time.timeScale = 0;
  110. yield return LMotion.Create(0f, 10f, Duration)
  111. .WithScheduler(MotionScheduler.UpdateRealtime)
  112. .RunWithoutBinding()
  113. .ToYieldInteraction();
  114. }
  115. [UnityTest]
  116. public IEnumerator Test_Scheduler_PreLateUpdate()
  117. {
  118. yield return LMotion.Create(0f, 10f, Duration)
  119. .WithScheduler(MotionScheduler.PreLateUpdate)
  120. .RunWithoutBinding()
  121. .ToYieldInteraction();
  122. }
  123. [UnityTest]
  124. public IEnumerator Test_Scheduler_PreLateUpdate_IgnoreTimeScale()
  125. {
  126. Time.timeScale = 0;
  127. yield return LMotion.Create(0f, 10f, Duration)
  128. .WithScheduler(MotionScheduler.PreLateUpdateIgnoreTimeScale)
  129. .RunWithoutBinding()
  130. .ToYieldInteraction();
  131. }
  132. [UnityTest]
  133. public IEnumerator Test_Scheduler_PreLateUpdate_Realtime()
  134. {
  135. Time.timeScale = 0;
  136. yield return LMotion.Create(0f, 10f, Duration)
  137. .WithScheduler(MotionScheduler.PreLateUpdateRealtime)
  138. .RunWithoutBinding()
  139. .ToYieldInteraction();
  140. }
  141. [UnityTest]
  142. public IEnumerator Test_Scheduler_PostLateUpdate()
  143. {
  144. yield return LMotion.Create(0f, 10f, Duration)
  145. .WithScheduler(MotionScheduler.PostLateUpdate)
  146. .RunWithoutBinding()
  147. .ToYieldInteraction();
  148. }
  149. [UnityTest]
  150. public IEnumerator Test_Scheduler_PostLateUpdate_IgnoreTimeScale()
  151. {
  152. Time.timeScale = 0;
  153. yield return LMotion.Create(0f, 10f, Duration)
  154. .WithScheduler(MotionScheduler.PostLateUpdateIgnoreTimeScale)
  155. .RunWithoutBinding()
  156. .ToYieldInteraction();
  157. }
  158. [UnityTest]
  159. public IEnumerator Test_Scheduler_PostLateUpdate_Realtime()
  160. {
  161. Time.timeScale = 0;
  162. yield return LMotion.Create(0f, 10f, Duration)
  163. .WithScheduler(MotionScheduler.PostLateUpdateRealtime)
  164. .RunWithoutBinding()
  165. .ToYieldInteraction();
  166. }
  167. [UnityTest]
  168. public IEnumerator Test_Scheduler_TimeUpdate()
  169. {
  170. yield return LMotion.Create(0f, 10f, Duration)
  171. .WithScheduler(MotionScheduler.TimeUpdate)
  172. .RunWithoutBinding()
  173. .ToYieldInteraction();
  174. }
  175. [UnityTest]
  176. public IEnumerator Test_Scheduler_TimeUpdate_IgnoreTimeScale()
  177. {
  178. Time.timeScale = 0;
  179. yield return LMotion.Create(0f, 10f, Duration)
  180. .WithScheduler(MotionScheduler.TimeUpdateIgnoreTimeScale)
  181. .RunWithoutBinding()
  182. .ToYieldInteraction();
  183. }
  184. [UnityTest]
  185. public IEnumerator Test_Scheduler_TimeUpdate_Realtime()
  186. {
  187. Time.timeScale = 0;
  188. yield return LMotion.Create(0f, 10f, Duration)
  189. .WithScheduler(MotionScheduler.TimeUpdateRealtime)
  190. .RunWithoutBinding()
  191. .ToYieldInteraction();
  192. }
  193. }
  194. }