public void StopEventRunTest() { ScheduledEvent evt = new ScheduledEvent( "test", callback, 3.0f, true, 1); // doesn't run until the cooldown is reached Reset(); evt.Update(5.0f); Assert.That(evt.LastShot, Is.False); Assert.That(evt.Finished, Is.False); Assert.That(didRun, Is.True); evt.Stop(); // and now it should not run Assert.That(evt.LastShot, Is.False); Assert.That(evt.Finished, Is.True); Reset(); evt.Update(5.0f); Assert.That(didRun, Is.False); }
public void CooldownEventRunTest() { ScheduledEvent evt = new ScheduledEvent( "test", callback, 3.0f, true, 1); // doesn't run until the cooldown is reached Reset(); evt.Update(2.0f); Assert.That(evt.LastShot, Is.False); Assert.That(evt.Finished, Is.False); Assert.That(evt.TimeToWait, Is.EqualTo(1.0f)); Assert.That(didRun, Is.False); Reset(); evt.Update(1.0f); Assert.That(evt.LastShot, Is.False); Assert.That(evt.Finished, Is.False); Assert.That(didRun, Is.True); // timer should be reset after firing Assert.That(evt.TimeToWait, Is.EqualTo(evt.Cooldown)); // so it should work again as above Reset(); evt.Update(2.0f); Assert.That(evt.LastShot, Is.False); Assert.That(evt.Finished, Is.False); Assert.That(didRun, Is.False); Reset(); evt.Update(1.0f); Assert.That(evt.LastShot, Is.False); Assert.That(evt.Finished, Is.False); Assert.That(didRun, Is.True); // and it should also work if we overshoot the cooldown Reset(); evt.Update(5.0f); Assert.That(evt.LastShot, Is.False); Assert.That(evt.Finished, Is.False); Assert.That(didRun, Is.True); }
public void SetCooldownTest() { ScheduledEvent evt = new ScheduledEvent( "test", callback, 3.0f, true, 1); Reset(); evt.Update(2f); evt.SetCooldown(2.5f); Assert.That(evt.TimeToWait, Is.EqualTo(.5f)); Assert.That(didRun, Is.False); evt.SetCooldown(1f); Assert.That(evt.TimeToWait, Is.EqualTo(0f)); evt.Update(.1f); Assert.That(didRun, Is.True); Assert.That(runCount, Is.EqualTo(1)); }
public void LargeDeltaTimeEventRunTest() { int tally = 0; ScheduledEvent evt = new ScheduledEvent( "test", (ev) => { tally++; Debug.ULogChannel("ScheduledEventTest", "Event {0} fired", ev.Name); }, 3.0f, true, 0); // event should fire three times in 10 seconds evt.Update(10f); Assert.That(tally, Is.EqualTo(3)); // timer should be 4 * 3 - 10 = 2 seconds Assert.That(evt.TimeToWait, Is.EqualTo(2)); Assert.That(evt.LastShot, Is.False); Assert.That(evt.Finished, Is.False); }