PlaybackSpeedTest.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System;
  2. using System.Collections;
  3. using NUnit.Framework;
  4. using UnityEngine;
  5. using UnityEngine.TestTools;
  6. using UnityEngine.TestTools.Utils;
  7. namespace LitMotion.Tests.Runtime
  8. {
  9. public class PlaybackSpeedTest
  10. {
  11. [UnityTest]
  12. public IEnumerator Test_PlaybackSpeed()
  13. {
  14. var endValue = 10f;
  15. var handle = LMotion.Create(0f, endValue, 1f)
  16. .BindToUnityLogger();
  17. handle.PlaybackSpeed = 0.5f;
  18. var time = Time.timeAsDouble;
  19. yield return handle.ToYieldInteraction();
  20. Assert.That(Time.timeAsDouble - time, Is.GreaterThan(2.0));
  21. }
  22. [UnityTest]
  23. public IEnumerator Test_PlaybackSpeed_Pause()
  24. {
  25. var endValue = 10f;
  26. var value = 0f;
  27. var handle = LMotion.Create(0f, endValue, 1f)
  28. .Bind(x => value = x);
  29. handle.PlaybackSpeed = 0f;
  30. yield return new WaitForSeconds(0.5f);
  31. Assert.That(value, Is.EqualTo(0f));
  32. handle.Cancel();
  33. }
  34. [UnityTest]
  35. public IEnumerator Test_PlaybackSpeed_2x_Speed()
  36. {
  37. var endValue = 10f;
  38. var value = 0f;
  39. var handle = LMotion.Create(0f, endValue, 1f)
  40. .Bind(x => value = x);
  41. handle.PlaybackSpeed = 2f;
  42. var time = Time.time;
  43. yield return handle.ToYieldInteraction();
  44. Assert.That(Time.time - time, Is.EqualTo(0.5f).Using(new FloatEqualityComparer(0.05f)));
  45. }
  46. [Test]
  47. public void Test_PlaybackSpeed_Minus()
  48. {
  49. var handle = LMotion.Create(0f, 10f, 1f).RunWithoutBinding();
  50. Assert.Throws<ArgumentOutOfRangeException>(() =>
  51. {
  52. handle.PlaybackSpeed = -1f;
  53. });
  54. }
  55. }
  56. }