BindTest.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using System;
  2. using System.Collections;
  3. using UnityEngine;
  4. using UnityEngine.Assertions;
  5. using UnityEngine.TestTools;
  6. namespace LitMotion.Tests.Runtime
  7. {
  8. public class BindTest
  9. {
  10. [UnityTest]
  11. public IEnumerator Test_Bind_LocalVariable()
  12. {
  13. var value = 0f;
  14. var endValue = 10f;
  15. LMotion.Create(0f, endValue, 1f).Bind(x => value = x);
  16. yield return new WaitForSeconds(1.1f);
  17. Assert.AreApproximatelyEqual(value, endValue);
  18. }
  19. [UnityTest]
  20. public IEnumerator Test_BindWithState()
  21. {
  22. var target = new TestClass();
  23. var endValue = 10f;
  24. LMotion.Create(0f, endValue, 0.5f).BindWithState(target, (x, target) =>
  25. {
  26. target.Value = x;
  27. });
  28. yield return new WaitForSeconds(0.6f);
  29. Assert.AreApproximatelyEqual(target.Value, endValue);
  30. }
  31. [UnityTest]
  32. public IEnumerator Test_BindWithState_2()
  33. {
  34. var target1 = new TestClass();
  35. var target2 = new TestClass();
  36. var endValue = 10f;
  37. LMotion.Create(0f, endValue, 0.5f).BindWithState(target1, target2, (x, target1, target2) =>
  38. {
  39. target1.Value = x;
  40. target2.Value = x;
  41. });
  42. yield return new WaitForSeconds(0.6f);
  43. Assert.AreApproximatelyEqual(target1.Value, endValue);
  44. Assert.AreApproximatelyEqual(target2.Value, endValue);
  45. }
  46. [UnityTest]
  47. public IEnumerator Test_BindWithState_3()
  48. {
  49. var target1 = new TestClass();
  50. var target2 = new TestClass();
  51. var target3 = new TestClass();
  52. var endValue = 10f;
  53. LMotion.Create(0f, endValue, 0.5f).BindWithState(target1, target2, target3, (x, target1, target2, target3) =>
  54. {
  55. target1.Value = x;
  56. target2.Value = x;
  57. target3.Value = x;
  58. });
  59. yield return new WaitForSeconds(0.6f);
  60. Assert.AreApproximatelyEqual(target1.Value, endValue);
  61. Assert.AreApproximatelyEqual(target2.Value, endValue);
  62. Assert.AreApproximatelyEqual(target3.Value, endValue);
  63. }
  64. [UnityTest]
  65. public IEnumerator Test_BindToProgress()
  66. {
  67. var value = 0f;
  68. var progress = new Progress<float>(x => value = x);
  69. var endValue = 10f;
  70. LMotion.Create(0f, endValue, 1f).BindToProgress(progress);
  71. yield return new WaitForSeconds(1.1f);
  72. Assert.AreApproximatelyEqual(value, endValue);
  73. }
  74. class TestClass
  75. {
  76. public float Value { get; set; }
  77. }
  78. }
  79. }