public void testAddMoreTimers()
        {
            Reset();

            TestTimerManager manager = new TestTimerManager();
            manager.Schedule(TimerCallback1, 0.75f);
            manager.Schedule(TimerCallback2, 0.5f);
            manager.Schedule(TimerCallback3, 0.5f);
            manager.Schedule(TimerCallback4, 1.0f);

            manager.Update(0.25f);
            AssertCallbacks();
            Assert.AreEqual(4, manager.Count());

            manager.Update(0.25f);
            AssertCallbacks(TimerCallback2, TimerCallback3);
            Assert.AreEqual(2, manager.Count());

            manager.Update(0.25f);
            AssertCallbacks(TimerCallback2, TimerCallback3, TimerCallback1);
            Assert.AreEqual(1, manager.Count());

            manager.Update(0.25f);
            AssertCallbacks(TimerCallback2, TimerCallback3, TimerCallback1, TimerCallback4);
            Assert.AreEqual(0, manager.Count());
        }
Ejemplo n.º 2
0
        public void testAddTimers()
        {
            Reset();

            TestTimerManager manager = new TestTimerManager();

            manager.Schedule(TimerCallback1, 0.75f);
            manager.Schedule(TimerCallback2, 0.5f);

            manager.Update(0.25f);
            AssertCallbacks();
            Assert.AreEqual(2, manager.Count());

            manager.Update(0.25f);
            AssertCallbacks(TimerCallback2);
            Assert.AreEqual(1, manager.Count());

            manager.Update(0.25f);
            AssertCallbacks(TimerCallback2, TimerCallback1);
            Assert.AreEqual(0, manager.Count());

            manager.Update(0.25f);
            AssertCallbacks(TimerCallback2, TimerCallback1);
            Assert.AreEqual(0, manager.Count());
        }
Ejemplo n.º 3
0
        public void testCancelTimer()
        {
            Reset();

            TestTimerManager manager = new TestTimerManager();

            manager.Schedule(TimerCallback1, 0.75f);
            manager.Schedule(TimerCallback2, 0.5f);

            manager.Update(0.25f); // 0.25
            AssertCallbacks();
            Assert.AreEqual(2, manager.Count());

            manager.Update(0.25f); // 0.5
            AssertCallbacks(TimerCallback2);
            Assert.AreEqual(1, manager.Count());

            manager.Schedule(TimerCallback3, 1.0f); // fires at 1.5
            Assert.AreEqual(2, manager.Count());

            manager.Cancel(TimerCallback1);

            manager.Update(0.25f); // 0.75
            AssertCallbacks(TimerCallback2);
            Assert.AreEqual(1, manager.Count());

            manager.Update(0.25f); // 1.0
            AssertCallbacks(TimerCallback2);
            Assert.AreEqual(1, manager.Count());

            manager.Schedule(TimerCallback4, 0.15f); // fires at 1.15
            Assert.AreEqual(2, manager.Count());

            manager.Cancel(TimerCallback3);

            manager.Update(0.25f); // 1.25
            AssertCallbacks(TimerCallback2, TimerCallback4);
            Assert.AreEqual(0, manager.Count());

            manager.Update(0.25f); // 1.5
            AssertCallbacks(TimerCallback2, TimerCallback4);
            Assert.AreEqual(0, manager.Count());

            manager.Update(0.25f); // 1.75
            AssertCallbacks(TimerCallback2, TimerCallback4);
            Assert.AreEqual(0, manager.Count());
        }
        public void testAddMoreTimersLater()
        {
            Reset();

            TestTimerManager manager = new TestTimerManager();
            manager.Schedule(TimerCallback1, 0.75f);
            manager.Schedule(TimerCallback2, 0.5f);

            manager.Update(0.25f); // 0.25
            AssertCallbacks();
            Assert.AreEqual(2, manager.Count());

            manager.Update(0.25f); // 0.5
            AssertCallbacks(TimerCallback2);
            Assert.AreEqual(1, manager.Count());

            manager.Schedule(TimerCallback3, 1.0f); // fires at 1.5
            Assert.AreEqual(2, manager.Count());

            manager.Update(0.25f); // 0.75
            AssertCallbacks(TimerCallback2, TimerCallback1);
            Assert.AreEqual(1, manager.Count());

            manager.Update(0.25f); // 1.0
            AssertCallbacks(TimerCallback2, TimerCallback1);
            Assert.AreEqual(1, manager.Count());

            manager.Schedule(TimerCallback4, 0.15f); // fires at 1.15
            Assert.AreEqual(2, manager.Count());

            manager.Update(0.25f); // 1.25
            AssertCallbacks(TimerCallback2, TimerCallback1, TimerCallback4);
            Assert.AreEqual(1, manager.Count());

            manager.Update(0.25f); // 1.5
            AssertCallbacks(TimerCallback2, TimerCallback1, TimerCallback4, TimerCallback3);
            Assert.AreEqual(0, manager.Count());

            manager.Update(0.25f); // 1.75
            AssertCallbacks(TimerCallback2, TimerCallback1, TimerCallback4, TimerCallback3);
            Assert.AreEqual(0, manager.Count());
        }
Ejemplo n.º 5
0
        public void testSortingTimers2()
        {
            Reset();

            TestTimerManager manager = new TestTimerManager();

            manager.Schedule(TimerCallback1, 0.75f, "timer1");
            manager.Schedule(TimerCallback1, 0.5f, "timer2");
            manager.Schedule(TimerCallback1, 0.25f, "timer3");
            manager.Schedule(TimerCallback1, 0.25f, "timer4");
            manager.Schedule(TimerCallback1, 0.0f, "timer5");

            Timer timer = manager.RootTimer;

            Assert.AreEqual(timer.name, "timer5"); timer = timer.next;
            Assert.AreEqual(timer.name, "timer3"); timer = timer.next;
            Assert.AreEqual(timer.name, "timer4"); timer = timer.next;
            Assert.AreEqual(timer.name, "timer2"); timer = timer.next;
            Assert.AreEqual(timer.name, "timer1"); timer = timer.next;
            Assert.IsNull(timer);
        }
        public void testAddTimer()
        {
            Reset();

            TestTimerManager manager = new TestTimerManager();
            manager.Schedule(TimerCallback1, 0.5f);

            manager.Update(0.25f);
            AssertCallbacks();
            Assert.AreEqual(1, manager.Count());

            manager.Update(0.25f);
            AssertCallbacks(TimerCallback1);
            Assert.AreEqual(0, manager.Count());

            manager.Update(0.25f);
            AssertCallbacks(TimerCallback1);
            Assert.AreEqual(0, manager.Count());
        }
        public void testSortingTimers2()
        {
            Reset();

            TestTimerManager manager = new TestTimerManager();
            manager.Schedule(TimerCallback1, 0.75f, "timer1");
            manager.Schedule(TimerCallback1, 0.5f,  "timer2");
            manager.Schedule(TimerCallback1, 0.25f, "timer3");
            manager.Schedule(TimerCallback1, 0.25f, "timer4");
            manager.Schedule(TimerCallback1, 0.0f,  "timer5");

            Timer timer = manager.RootTimer;
            Assert.AreEqual(timer.name, "timer5"); timer = timer.next;
            Assert.AreEqual(timer.name, "timer3"); timer = timer.next;
            Assert.AreEqual(timer.name, "timer4"); timer = timer.next;
            Assert.AreEqual(timer.name, "timer2"); timer = timer.next;
            Assert.AreEqual(timer.name, "timer1"); timer = timer.next;
            Assert.IsNull(timer);
        }