Пример #1
0
        public void TestDelay()
        {
            FTimer t = new FTimer(3);
            t.Restart(4); // Restart and Start are exactly the same.
            float startTime = t.StartTime;

            t.Extend(2);
            Assert.That(t.Duration, Is.EqualTo(6));
            Assert.That(t.StartTime, Is.EqualTo(Time.time));

            t.Delay(1);
            Assert.That(t.Duration, Is.EqualTo(6));
            Assert.That(t.StartTime, Is.EqualTo(startTime+1));
            // Delay can cause Elapsed to go negative, but Normalized will always be clamped to [0,1].
            AssertState(t, -1, 0, true, false, false);

            #if FILUTIL_DEBUG
            t._SetNow(startTime + 3);
            AssertState(t, 2, 2f/6f, true, false, false);
            t.Delay(2);
            AssertState(t, 0, 0, true, false, false);

            // Extend and Delay should work while Paused.
            t._SetNow(startTime + 6);
            t.Pause();
            AssertState(t, 3, 0.5f, true, true, false);
            t.Delay(2);
            AssertState(t, 1, 1f/6f, true, true, false);
            t.Extend(2);
            AssertState(t, 1, 1f/8f, true, true, false);

            // We can force finish while paused.
            t.FinishImmediately();
            AssertState(t, 8, 1, true, true, true);
            #endif
        }
Пример #2
0
        public void TestPause()
        {
            FTimer t = new FTimer(3);
            t.Start(4); // override original duration
            float startTime = t.StartTime; // pausing fiddles with the timer's start time, so don't depend on it while faking time.
            Assert.That(t.Duration, Is.EqualTo(4f));
            Assert.That(t.StartTime, Is.EqualTo(Time.time));

            #if FILUTIL_DEBUG
            t._SetNow(startTime + 1);
            AssertState(t, 1, 0.25f, true, false, false);

            t.Pause();
            AssertState(t, 1, 0.25f, true, true, false);

            t._SetNow(startTime + 1);
            AssertState(t, 1, 0.25f, true, true, false);

            t._SetNow(startTime + 2);
            t.Unpause();
            AssertState(t, 1, 0.25f, true, false, false);

            t._SetNow(startTime + 3);
            AssertState(t, 2, 0.50f, true, false, false);

            t.Pause(true);
            t._SetNow(startTime + 7);
            AssertState(t, 2, 0.50f, true, true, false);

            t._SetNow(startTime + 9);
            AssertState(t, 2, 0.50f, true, true, false);

            t._SetNow(startTime + 10);
            t.Pause(false);
            AssertState(t, 2, 0.50f, true, false, false);

            t._SetNow(startTime + 12);
            AssertState(t, 4, 1, true, false, true);
            #endif
        }