public void TimerReset() { ManualClock clock = new ManualClock(); clock.Start(); VariableStepTimer timer = new VariableStepTimer(clock); timer.Idle += timer_Idle; timer.TimeChanged += timer_TimeChanged; timer.Reset(); timer.Start(); clock.Update(TimeSpan.FromMilliseconds(10)); CheckTimeChangedEvent(TimeSpan.FromMilliseconds(10), TimeSpan.FromMilliseconds(10)); timer.Reset(); Assert.IsFalse(timer.IsRunning); Assert.AreEqual(TimeSpan.Zero, timer.Time); Assert.AreEqual(TimeSpan.Zero, timer.DeltaTime); timer.Start(); clock.Update(TimeSpan.FromMilliseconds(10)); clock.Update(TimeSpan.FromMilliseconds(10)); CheckTimeChangedEvent(TimeSpan.FromMilliseconds(20), TimeSpan.FromMilliseconds(10)); timer.Stop(); Assert.AreEqual(TimeSpan.FromMilliseconds(20), timer.Time); Assert.AreEqual(TimeSpan.Zero, timer.DeltaTime); timer.Reset(); Assert.AreEqual(TimeSpan.Zero, timer.Time); Assert.AreEqual(TimeSpan.Zero, timer.DeltaTime); }
public void NormalRun() { ManualClock clock = new ManualClock(); clock.Start(); VariableStepTimer timer = new VariableStepTimer(clock); timer.Idle += timer_Idle; timer.TimeChanged += timer_TimeChanged; // Clock is not running clock.Update(TimeSpan.FromMilliseconds(10)); Assert.IsFalse(timer.IsRunning); CheckNoIdleEvent(); CheckNoTimeChangedEvent(); // Start/Stop ... not running timer.Start(); timer.Stop(); clock.Update(TimeSpan.FromMilliseconds(10)); Assert.IsFalse(timer.IsRunning); CheckNoIdleEvent(); CheckNoTimeChangedEvent(); // Start timer.Start(); clock.Update(TimeSpan.FromMilliseconds(10)); Assert.IsTrue(timer.IsRunning); CheckNoIdleEvent(); CheckTimeChangedEvent(TimeSpan.FromMilliseconds(10), TimeSpan.FromMilliseconds(10)); clock.Update(TimeSpan.FromMilliseconds(10)); CheckNoIdleEvent(); CheckTimeChangedEvent(TimeSpan.FromMilliseconds(20), TimeSpan.FromMilliseconds(10)); Assert.AreEqual(TimeSpan.FromMilliseconds(20), timer.Time); Assert.AreEqual(TimeSpan.FromMilliseconds(10), timer.DeltaTime); Assert.AreEqual(TimeSpan.Zero, timer.IdleTime); Assert.AreEqual(TimeSpan.Zero, timer.LostTime); // Pause timer.Stop(); clock.Update(TimeSpan.FromMilliseconds(10)); Assert.IsFalse(timer.IsRunning); CheckNoIdleEvent(); CheckNoTimeChangedEvent(); Assert.AreEqual(TimeSpan.FromMilliseconds(20), timer.Time); // Resume timer.Start(); clock.Update(TimeSpan.FromMilliseconds(10)); Assert.IsTrue(timer.IsRunning); CheckNoIdleEvent(); CheckTimeChangedEvent(TimeSpan.FromMilliseconds(30), TimeSpan.FromMilliseconds(10)); Assert.AreEqual(TimeSpan.FromMilliseconds(30), timer.Time); Assert.AreEqual(TimeSpan.FromMilliseconds(10), timer.DeltaTime); Assert.AreEqual(TimeSpan.Zero, timer.IdleTime); Assert.AreEqual(TimeSpan.Zero, timer.LostTime); // Stop timer.Stop(); clock.Update(TimeSpan.FromMilliseconds(10)); CheckNoIdleEvent(); CheckNoTimeChangedEvent(); }