コード例 #1
0
ファイル: Duration.cs プロジェクト: via5/Synergy
        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);
        }
コード例 #2
0
ファイル: Duration.cs プロジェクト: via5/Synergy
        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);
        }
コード例 #3
0
ファイル: Duration.cs プロジェクト: via5/Synergy
        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);
        }
コード例 #4
0
ファイル: Duration.cs プロジェクト: via5/Synergy
        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);
        }
コード例 #5
0
        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);
            }));
        }
コード例 #6
0
ファイル: Duration.cs プロジェクト: via5/Synergy
        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);
        }