Exemplo n.º 1
0
        public void RepeatClockCutAfterEndTest()
        {
            IClock clock = new RepeatClock(new TestClock(TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(4)), 0.5);
            Assert.AreEqual(TimeSpan.FromSeconds(2), clock.FirstTick);
            Assert.AreEqual(TimeSpan.FromSeconds(4), clock.LastTick);
            Assert.AreEqual(TimeSpan.FromSeconds(5), clock.Duration);

            ClockState state = clock.Tick(TimeSpan.FromSeconds(-1));
            Assert.AreEqual(0, state.Progress);
            Assert.AreEqual(ClockProgressState.BeforeStarted, state.ProgressState);
            Assert.AreEqual(Granular.Compatibility.TimeSpan.MinValue, state.PreviousTick);
            Assert.AreEqual(TimeSpan.FromSeconds(2), state.NextTick);

            state = clock.Tick(TimeSpan.FromSeconds(2));
            Assert.AreEqual(0, state.Progress);
            Assert.AreEqual(ClockProgressState.Active, state.ProgressState);
            Assert.AreEqual(TimeSpan.FromSeconds(2), state.PreviousTick);
            Assert.AreEqual(TimeSpan.FromSeconds(2), state.NextTick);

            state = clock.Tick(TimeSpan.FromSeconds(4));
            Assert.AreEqual(1, state.Progress);
            Assert.AreEqual(ClockProgressState.AfterEnded, state.ProgressState);
            Assert.AreEqual(TimeSpan.FromSeconds(4), state.PreviousTick);
            Assert.AreEqual(Granular.Compatibility.TimeSpan.MaxValue, state.NextTick);

            state = clock.Tick(TimeSpan.FromSeconds(5));
            Assert.AreEqual(1, state.Progress);
            Assert.AreEqual(ClockProgressState.AfterEnded, state.ProgressState);
            Assert.AreEqual(TimeSpan.FromSeconds(4), state.PreviousTick);
            Assert.AreEqual(Granular.Compatibility.TimeSpan.MaxValue, state.NextTick);
        }
Exemplo n.º 2
0
        public void RepeatClockSecondIterationCutActiveTest()
        {
            IClock clock = new RepeatClock(new TestClock(TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(4)), 1.3);
            Assert.AreEqual(TimeSpan.FromSeconds(2), clock.FirstTick);
            Assert.AreEqual(TimeSpan.FromSeconds(13), clock.LastTick);
            Assert.AreEqual(TimeSpan.FromSeconds(13), clock.Duration);

            ClockState state = clock.Tick(TimeSpan.FromSeconds(9));
            Assert.AreEqual(1, state.Progress);
            Assert.AreEqual(ClockProgressState.AfterEnded, state.ProgressState);
            Assert.AreEqual(TimeSpan.FromSeconds(4), state.PreviousTick);
            Assert.AreEqual(TimeSpan.FromSeconds(12), state.NextTick);

            state = clock.Tick(TimeSpan.FromSeconds(12.5));
            Assert.AreEqual(0.25, state.Progress);
            Assert.AreEqual(ClockProgressState.Active, state.ProgressState);
            Assert.AreEqual(TimeSpan.FromSeconds(12.5), state.PreviousTick);
            Assert.AreEqual(TimeSpan.FromSeconds(12.5), state.NextTick);

            state = clock.Tick(TimeSpan.FromSeconds(13));
            Assert.AreEqual(0.5, state.Progress);
            Assert.AreEqual(ClockProgressState.AfterEnded, state.ProgressState);
            Assert.AreEqual(TimeSpan.FromSeconds(13), state.PreviousTick);
            Assert.AreEqual(Granular.Compatibility.TimeSpan.MaxValue, state.NextTick);
        }