123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- using System.Collections;
- using UnityEngine;
- using UnityEngine.Assertions;
- using UnityEngine.TestTools;
- namespace LitMotion.Tests.Runtime
- {
- public class MotionHandleTest
- {
- [UnityTest]
- public IEnumerator Test_Cancel()
- {
- var value = 0f;
- var endValue = 10f;
- var handle = LMotion.Create(0f, endValue, 2f)
- .Bind(x =>
- {
- value = x;
- Debug.Log(x);
- });
- yield return new WaitForSeconds(1f);
- handle.Cancel();
- yield return new WaitForSeconds(1f);
- Assert.IsTrue(value < endValue);
- Assert.IsTrue(!handle.IsActive());
- }
- [UnityTest]
- public IEnumerator Test_Complete()
- {
- var value = 0f;
- var endValue = 10f;
- var handle = LMotion.Create(0f, endValue, 2f)
- .Bind(x =>
- {
- value = x;
- Debug.Log(x);
- });
- yield return new WaitForSeconds(1f);
- handle.Complete();
- Assert.AreApproximatelyEqual(value, endValue);
- Assert.IsTrue(!handle.IsActive());
- }
- [UnityTest]
- public IEnumerator Test_Complete_WithYoyoLoop()
- {
- var value = 0f;
- var startValue = 0f;
- var handle = LMotion.Create(startValue, 10f, 2f)
- .WithLoops(2, LoopType.Yoyo)
- .Bind(x =>
- {
- value = x;
- Debug.Log(x);
- });
- yield return new WaitForSeconds(1f);
- handle.Complete();
- Assert.AreApproximatelyEqual(value, startValue);
- Assert.IsTrue(!handle.IsActive());
- }
- [UnityTest]
- public IEnumerator Test_CompleteAndCancel_WithInfiniteLoop()
- {
- var value = 0f;
- var startValue = 0f;
- var handle = LMotion.Create(startValue, 10f, 2f)
- .WithLoops(-1)
- .Bind(x =>
- {
- value = x;
- Debug.Log(x);
- });
- yield return new WaitForSeconds(1f);
- handle.Complete();
- Assert.IsTrue(handle.IsActive());
- handle.Cancel();
- Assert.IsTrue(!handle.IsActive());
- }
- [UnityTest]
- public IEnumerator Test_ToDisposable()
- {
- var value = 0f;
- var endValue = 10f;
- var disposable = LMotion.Create(0f, endValue, 2f)
- .Bind(x =>
- {
- value = x;
- Debug.Log(x);
- })
- .ToDisposable();
- yield return new WaitForSeconds(1f);
- disposable.Dispose();
- yield return new WaitForSeconds(1f);
- Assert.IsTrue(value < endValue);
- }
- [UnityTest]
- public IEnumerator Test_IsActive()
- {
- MotionHandle handle = LMotion.Create(0f, 10f, 2f).RunWithoutBinding();
- Assert.IsTrue(handle.IsActive());
- yield return new WaitForSeconds(2.5f);
- Assert.IsFalse(handle.IsActive());
- }
- }
- }
|