Tanoda
TweenTests.cs
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) Ultraleap, Inc. 2011-2020. *
3 * *
4 * Use subject to the terms of the Apache License 2.0 available at *
5 * http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
6 * between Ultraleap and you, your company or other organization. *
7 ******************************************************************************/
8
9#if UNITY_5_6 && UNITY_EDITOR
10using UnityEngine;
11using UnityEngine.TestTools;
12using NUnit.Framework;
13using System;
14using System.Collections;
15using Leap.Unity.Animation;
16
17public class TweenCoreTests {
18
19 [UnityTest]
20 public IEnumerator BasicSingleTweenLifecycle() {
21 bool didHitEnd = false;
22
23 var tween = Tween.Single().
24 Value(0, 1, p => {
25 if (p == 1) {
26 didHitEnd = true;
27 }
28 }).
29 OverTime(1.0f).
30 Play();
31
32 Assert.IsTrue(tween.isRunning);
33 Assert.IsTrue(tween.isValid);
34
35 yield return tween.Yield();
36
37 Assert.IsFalse(tween.isValid);
38 Assert.IsTrue(didHitEnd);
39 }
40
41 [UnityTest]
42 public IEnumerator BasicPersistentTweenLifecycle() {
43 bool didHitEnd = false;
44
45 var tween = Tween.Persistent().
46 Value(0, 1, p => {
47 if (p == 1) {
48 didHitEnd = true;
49 }
50 }).
51 Play();
52
53 Assert.IsTrue(tween.isRunning);
54 Assert.IsTrue(tween.isValid);
55
56 yield return tween.Yield();
57
58 Assert.IsTrue(tween.isValid);
59 Assert.IsFalse(tween.isRunning);
60 Assert.IsTrue(didHitEnd);
61 }
62
63 [UnityTest]
64 public IEnumerator OverTimeTest([Values]TweenType type,
65 [Values(0.0f, 0.1f, 1.0f, 2.0f)] float time) {
66 var tween = Create(type).OverTime(time).Play();
67
68 float startTime = Time.time;
69 yield return tween.Yield();
70 float endTime = Time.time;
71
72 float delta = endTime - startTime;
73 Assert.That(delta, Is.EqualTo(time).Within(0.1f));
74 }
75
76 public Tween Create(TweenType type) {
77 switch (type) {
78 case TweenType.Single:
79 return Tween.Single();
80 case TweenType.Persistent:
81 return Tween.Persistent();
82 default:
83 throw new Exception();
84 }
85 }
86
87 public enum TweenType {
88 Single,
89 Persistent
90 }
91}
92#endif