public void TestBasicState() { FTimer t = new FTimer(3f); Assert.That(t.Duration, Is.EqualTo(3f)); // StartTime, Elapsed, and Normalized are garbage values on a non-Running timer. //Assert.That(t.StartTime, Is.EqualTo(0)); //Assert.That(t.Elapsed, Is.EqualTo(0)); //Assert.That(t.Normalized, Is.EqualTo(0)); Assert.That(t.Running, Is.False); Assert.That(t.Paused, Is.False); Assert.That(t.Done, Is.False); t.Start(); Assert.That(t.StartTime, Is.EqualTo(Time.time)); AssertState(t, 0, 0, true, false, false); #if FILUTIL_DEBUG // _SetNow is a debug hook used to test timer advancement. t._SetNow(t.StartTime + 1); AssertState(t, 1, 1f/3f, true, false, false); t._SetNow(t.StartTime + 3); AssertState(t, 3, 1, true, false, true); t._SetNow(t.StartTime + 4); // overtime AssertState(t, 4, 1, true, false, true); #endif t.Stop(); // StartTime, Elapsed, and Normalized go back to junk values after Stop. //Assert.That(t.StartTime, Is.EqualTo(0)); //Assert.That(t.Elapsed, Is.EqualTo(0)); //Assert.That(t.Normalized, Is.EqualTo(0)); Assert.That(t.Running, Is.False); Assert.That(t.Paused, Is.False); Assert.That(t.Done, Is.False); }
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 }