private void TickSecondHalfTest(RandomDuration d, float progress) { Assert.AreEqual(1, d.FirstHalfProgress); Assert.AreEqual((progress - 0.5f) * 2, d.SecondHalfProgress, D); Assert.IsFalse(d.InFirstHalf); Assert.IsTrue(d.FirstHalfFinished); Assert.AreEqual((progress - 0.5f) * 2, d.TotalProgress, D); Assert.IsFalse(d.InFirstHalfTotal); Assert.IsFalse(d.Finished); Assert.AreEqual(1.0f - progress, d.TimeRemaining, D); Assert.AreEqual(1.0f - progress, d.TimeRemainingInHalf, D); // constant Assert.AreEqual(1, d.Current); }
public void DefaultCtor() { var d = new RandomDuration(); Assert.AreEqual(0, d.FirstHalfProgress); Assert.AreEqual(0, d.SecondHalfProgress); Assert.IsTrue(d.InFirstHalf); Assert.IsFalse(d.FirstHalfFinished); Assert.AreEqual(0, d.TotalProgress); Assert.IsTrue(d.InFirstHalfTotal); Assert.IsFalse(d.Finished); Assert.AreEqual(1, d.TimeRemaining); Assert.AreEqual(0.5, d.TimeRemainingInHalf); Assert.AreEqual(1, d.Current); }
private void TickFinishedTest(RandomDuration d) { Assert.AreEqual(1, d.FirstHalfProgress); Assert.AreEqual(1, d.SecondHalfProgress); Assert.IsFalse(d.InFirstHalf); Assert.IsTrue(d.FirstHalfFinished); Assert.AreEqual(1, d.TotalProgress); Assert.IsFalse(d.InFirstHalfTotal); Assert.IsTrue(d.Finished); Assert.AreEqual(0, d.TimeRemaining); Assert.AreEqual(0, d.TimeRemainingInHalf); // constant Assert.AreEqual(1, d.Current); }
public void TickAndReset() { var d = new RandomDuration(1); TickFirstHalfTest(d, 0); d.Tick(0.2f); TickFirstHalfTest(d, 0.2f); d.Tick(0.2f); TickFirstHalfTest(d, 0.4f); d.Tick(0.2f); TickSecondHalfTest(d, 0.6f); d.Tick(0.2f); TickSecondHalfTest(d, 0.8f); d.Tick(0.3f); TickFinishedTest(d); d.Reset(); TickFirstHalfTest(d, 0); d.Tick(0.2f); TickFirstHalfTest(d, 0.2f); d.Tick(0.2f); TickFirstHalfTest(d, 0.4f); d.Tick(0.2f); TickSecondHalfTest(d, 0.6f); d.Tick(0.2f); TickSecondHalfTest(d, 0.8f); d.Tick(0.3f); TickFinishedTest(d); }
public static IObservable <long> RandomTimer( Duration dueTime, Duration minPeriod, Duration maxPeriod, IScheduler scheduler = null) { return(Observable.Create <long>(o => { scheduler = scheduler ?? Scheduler.Default; var rand = new RandomDuration(minPeriod, maxPeriod); long value = 0; IObservable <long> initial = Observable.Timer(dueTime, scheduler).Select(_ => value++); IObservable <long> rest = Observable.Return(0, scheduler) .SelectMany(_ => Observable.Timer(TimeSpan.FromMilliseconds(rand.Next()), scheduler)) .Select(_ => value++) .Repeat(); return initial.Concat(rest).Subscribe(o); })); }
public void Tick1() { var d = new RandomDuration(1); TickFirstHalfTest(d, 0); d.Tick(0.1f); TickFirstHalfTest(d, 0.1f); d.Tick(0.1f); TickFirstHalfTest(d, 0.2f); d.Tick(0.1f); TickFirstHalfTest(d, 0.3f); d.Tick(0.1f); TickFirstHalfTest(d, 0.4f); d.Tick(0.1f); TickFirstHalfTest(d, 0.5f); d.Tick(0.1f); TickSecondHalfTest(d, 0.6f); d.Tick(0.1f); TickSecondHalfTest(d, 0.7f); d.Tick(0.1f); TickSecondHalfTest(d, 0.8f); d.Tick(0.1f); TickSecondHalfTest(d, 0.9f); d.Tick(0.1f); TickFinishedTest(d); }