DelayTest.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using System.Collections;
  2. using NUnit.Framework;
  3. using UnityEngine;
  4. using UnityEngine.TestTools;
  5. namespace LitMotion.Tests.Runtime
  6. {
  7. public class DelayTest
  8. {
  9. [UnityTest]
  10. public IEnumerator Test_Delay()
  11. {
  12. var t = Time.timeAsDouble;
  13. yield return LMotion.Create(0f, 1f, 0.5f)
  14. .WithDelay(0.5f)
  15. .BindToUnityLogger()
  16. .ToYieldInteraction();
  17. Assert.That(Time.timeAsDouble - t, Is.GreaterThan(0.95).And.LessThan(1.1));
  18. }
  19. [UnityTest]
  20. public IEnumerator Test_Delay_WithZeroDuration()
  21. {
  22. var t = Time.timeAsDouble;
  23. yield return LMotion.Create(0f, 1f, 0f)
  24. .WithDelay(1f)
  25. .BindToUnityLogger()
  26. .ToYieldInteraction();
  27. Assert.That(Time.timeAsDouble - t, Is.GreaterThan(0.95).And.LessThan(1.1));
  28. }
  29. [UnityTest]
  30. public IEnumerator Test_Delay_EveryLoop()
  31. {
  32. var t = Time.timeAsDouble;
  33. yield return LMotion.Create(0f, 1f, 0.5f)
  34. .WithLoops(2)
  35. .WithDelay(0.5f, DelayType.EveryLoop)
  36. .BindToUnityLogger()
  37. .ToYieldInteraction();
  38. Assert.That(Time.timeAsDouble - t, Is.GreaterThan(1.95).And.LessThan(2.1));
  39. }
  40. [UnityTest]
  41. public IEnumerator Test_Delay_EveryLoop_WithZeroDuration()
  42. {
  43. var t = Time.timeAsDouble;
  44. yield return LMotion.Create(0f, 1f, 0f)
  45. .WithLoops(3)
  46. .WithDelay(0.5f, DelayType.EveryLoop)
  47. .BindToUnityLogger()
  48. .ToYieldInteraction();
  49. Assert.That(Time.timeAsDouble - t, Is.GreaterThan(1.45).And.LessThan(1.6));
  50. }
  51. [UnityTest]
  52. public IEnumerator Test_Delay_SkipValuesDuringDelay()
  53. {
  54. var value = 0f;
  55. var handle = LMotion.Create(1f, 2f, 0.5f)
  56. .WithDelay(0.5f, skipValuesDuringDelay: false)
  57. .Bind(x => value = x);
  58. yield return new WaitForSeconds(0.1f);
  59. Assert.That(value, Is.GreaterThan(0.9f));
  60. handle.Cancel();
  61. value = 0f;
  62. handle = LMotion.Create(1f, 2f, 0.5f)
  63. .WithDelay(0.5f, skipValuesDuringDelay: true)
  64. .Bind(x => value = x);
  65. yield return new WaitForSeconds(0.1f);
  66. Assert.That(value, Is.LessThan(0.9f));
  67. handle.Cancel();
  68. }
  69. }
  70. }