RuntimeExampleTest.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using UnityEngine;
  2. using UnityEngine.TestTools;
  3. using NUnit.Framework;
  4. using System.Collections;
  5. public class RuntimeDampingTest
  6. {
  7. [Test]
  8. public void DampFloat()
  9. {
  10. const float dampTime = 10f;
  11. const float initial = 100f;
  12. float[] fixedFactor = new float[3] { 0.79f, 0f, 1.07f };
  13. for (int f = 0; f < fixedFactor.Length; ++f)
  14. {
  15. float t = 0;
  16. float r = Cinemachine.Utility.Damper.Damp(initial, dampTime, t);
  17. Assert.AreEqual(0, r);
  18. Assert.Less(r, initial);
  19. const int iterations = 10;
  20. for (int i = 0; i < iterations; ++i)
  21. {
  22. t += dampTime / iterations;
  23. float fdt = fixedFactor[f] * t;
  24. string msg = "i = " + i + ", t = " + t + ", fdt = " + fdt;
  25. if (i != iterations-1)
  26. Assert.Less(t, dampTime, msg);
  27. else
  28. t = dampTime;
  29. float r2 = Cinemachine.Utility.Damper.Damp(initial, dampTime, t);
  30. Assert.Less(r, r2, msg);
  31. r = r2;
  32. }
  33. //Assert.AreEqual(initial * (1 - MathHelpers.kNegligibleResidual), r, "f = " + f);
  34. }
  35. }
  36. /*
  37. // A UnityTest behaves like a coroutine in PlayMode
  38. // and allows you to yield null to skip a frame in EditMode
  39. [UnityTest]
  40. public IEnumerator PlayModeSampleTestWithEnumeratorPasses() {
  41. // Use the Assert class to test conditions.
  42. // yield to skip a frame
  43. yield return null;
  44. }
  45. */
  46. }