public void RepeatClockCutBeforeStartTest() { IClock clock = new RepeatClock(new TestClock(TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(4)), 0.1); Assert.AreEqual(TimeSpan.Zero, clock.FirstTick); Assert.AreEqual(TimeSpan.FromSeconds(1), clock.LastTick); Assert.AreEqual(TimeSpan.FromSeconds(1), 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.Zero, state.NextTick); state = clock.Tick(TimeSpan.Zero); Assert.AreEqual(0, state.Progress); Assert.AreEqual(ClockProgressState.BeforeStarted, state.ProgressState); Assert.AreEqual(TimeSpan.Zero, state.PreviousTick); Assert.AreEqual(TimeSpan.FromSeconds(1), state.NextTick); state = clock.Tick(TimeSpan.FromSeconds(1)); Assert.AreEqual(0, state.Progress); Assert.AreEqual(ClockProgressState.AfterEnded, state.ProgressState); Assert.AreEqual(TimeSpan.FromSeconds(1), state.PreviousTick); Assert.AreEqual(Granular.Compatibility.TimeSpan.MaxValue, state.NextTick); }
private static IClock CreateClock(IClock baseClock, Timeline timeline) { if (timeline.Duration.HasTimeSpan) { baseClock = new DurationClock(baseClock, timeline.Duration.TimeSpan); } if (timeline.AutoReverse) { baseClock = new ReverseClock(baseClock); } if (timeline.RepeatBehavior != RepeatBehavior.OneTime) { double iterationsCount = timeline.RepeatBehavior.Count.DefaultIfNaN((double)timeline.RepeatBehavior.Duration.Ticks / baseClock.Duration.Ticks); baseClock = new RepeatClock(baseClock, iterationsCount); } if (timeline.BeginTime != TimeSpan.Zero) { baseClock = new OffsetClock(baseClock, timeline.BeginTime); } return(baseClock); }
private static IClock CreateClock(IClock baseClock, Timeline timeline) { if (timeline.Duration.HasTimeSpan) { baseClock = new DurationClock(baseClock, timeline.Duration.TimeSpan); } if (timeline.AutoReverse) { baseClock = new ReverseClock(baseClock); } if (timeline.RepeatBehavior != RepeatBehavior.OneTime) { double iterationsCount = timeline.RepeatBehavior.Count.DefaultIfNaN((double)timeline.RepeatBehavior.Duration.Ticks / baseClock.Duration.Ticks); baseClock = new RepeatClock(baseClock, iterationsCount); } if (timeline.BeginTime != TimeSpan.Zero) { baseClock = new OffsetClock(baseClock, timeline.BeginTime); } return baseClock; }
public void RepeatClockSecondIterationCutAfterEndTest() { IClock clock = new RepeatClock(new TestClock(TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(4)), 1.5); Assert.AreEqual(TimeSpan.FromSeconds(2), clock.FirstTick); Assert.AreEqual(TimeSpan.FromSeconds(14), clock.LastTick); Assert.AreEqual(TimeSpan.FromSeconds(15), 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(13)); Assert.AreEqual(0.5, state.Progress); Assert.AreEqual(ClockProgressState.Active, state.ProgressState); Assert.AreEqual(TimeSpan.FromSeconds(13), state.PreviousTick); Assert.AreEqual(TimeSpan.FromSeconds(13), state.NextTick); state = clock.Tick(TimeSpan.FromSeconds(15)); Assert.AreEqual(1, state.Progress); Assert.AreEqual(ClockProgressState.AfterEnded, state.ProgressState); Assert.AreEqual(TimeSpan.FromSeconds(14), state.PreviousTick); Assert.AreEqual(Granular.Compatibility.TimeSpan.MaxValue, state.NextTick); }