コード例 #1
0
        public void TestComputeDelta()
        {
            TimePeriodComputeConstGivenCalAddEval addMonth = new TimePeriodComputeConstGivenCalAddEval();

            addMonth.TimeZone   = TimeZoneInfo.Utc;
            addMonth.TimeAbacus = TimeAbacusMilliseconds.INSTANCE;
            TimePeriodAdder[] adders = new TimePeriodAdder[1];
            adders[0]                  = new TimePeriodAdderMonth();
            addMonth.Adders            = adders;
            addMonth.Added             = new int[] { 1 };
            addMonth.IndexMicroseconds = -1;

            Assert.AreEqual(28 * 24 * 60 * 60 * 1000L, addMonth.DeltaAdd(Parse("2002-02-15T09:00:00.000"), null, true, null));
            Assert.AreEqual(28 * 24 * 60 * 60 * 1000L, addMonth.DeltaSubtract(Parse("2002-03-15T09:00:00.000"), null, true, null));

            TimePeriodDeltaResult result = addMonth.DeltaAddWReference(
                Parse("2002-02-15T09:00:00.000"), Parse("2002-02-15T09:00:00.000"), null, true, null);

            Assert.AreEqual(Parse("2002-03-15T09:00:00.000") - Parse("2002-02-15T09:00:00.000"), result.Delta);
            Assert.AreEqual(Parse("2002-02-15T09:00:00.000"), result.LastReference);

            result = addMonth.DeltaAddWReference(
                Parse("2002-03-15T09:00:00.000"), Parse("2002-02-15T09:00:00.000"), null, true, null);
            Assert.AreEqual(Parse("2002-04-15T09:00:00.000") - Parse("2002-03-15T09:00:00.000"), result.Delta);
            Assert.AreEqual(Parse("2002-03-15T09:00:00.000"), result.LastReference);

            result = addMonth.DeltaAddWReference(
                Parse("2002-04-15T09:00:00.000"), Parse("2002-03-15T09:00:00.000"), null, true, null);
            Assert.AreEqual(Parse("2002-05-15T09:00:00.000") - Parse("2002-04-15T09:00:00.000"), result.Delta);
            Assert.AreEqual(Parse("2002-04-15T09:00:00.000"), result.LastReference);

            // try future reference
            result = addMonth.DeltaAddWReference(
                Parse("2002-02-15T09:00:00.000"), Parse("2900-03-15T09:00:00.000"), null, true, null);
            Assert.AreEqual(Parse("2002-03-15T09:00:00.000") - Parse("2002-02-15T09:00:00.000"), result.Delta);
            Assert.AreEqual(Parse("2002-02-15T09:00:00.000"), result.LastReference);

            // try old reference
            result = addMonth.DeltaAddWReference(
                Parse("2002-02-15T09:00:00.000"), Parse("1980-03-15T09:00:00.000"), null, true, null);
            Assert.AreEqual(Parse("2002-03-15T09:00:00.000") - Parse("2002-02-15T09:00:00.000"), result.Delta);
            Assert.AreEqual(Parse("2002-02-15T09:00:00.000"), result.LastReference);

            // try different-dates
            result = addMonth.DeltaAddWReference(
                Parse("2002-02-18T09:00:00.000"), Parse("1980-03-15T09:00:00.000"), null, true, null);
            Assert.AreEqual(Parse("2002-03-15T09:00:00.000") - Parse("2002-02-18T09:00:00.000"), result.Delta);
            Assert.AreEqual(Parse("2002-02-15T09:00:00.000"), result.LastReference);

            result = addMonth.DeltaAddWReference(
                Parse("2002-02-11T09:00:00.000"), Parse("2980-03-15T09:00:00.000"), null, true, null);
            Assert.AreEqual(Parse("2002-02-15T09:00:00.000") - Parse("2002-02-11T09:00:00.000"), result.Delta);
            Assert.AreEqual(Parse("2002-01-15T09:00:00.000"), result.LastReference);

            result = addMonth.DeltaAddWReference(
                Parse("2002-04-05T09:00:00.000"), Parse("2002-02-11T09:01:02.003"), null, true, null);
            Assert.AreEqual(Parse("2002-04-11T09:01:02.003") - Parse("2002-04-05T09:00:00.000"), result.Delta);
            Assert.AreEqual(Parse("2002-03-11T09:01:02.003"), result.LastReference);
        }
コード例 #2
0
        public void TestComputeDelta()
        {
            TimePeriodComputeConstGivenDeltaEval delta500 = new TimePeriodComputeConstGivenDeltaEval(500);

            Assert.AreEqual(500, delta500.DeltaAdd(0, null, true, null));
            Assert.AreEqual(500, delta500.DeltaSubtract(0, null, true, null));

            TimePeriodComputeConstGivenDeltaEval delta10k = new TimePeriodComputeConstGivenDeltaEval(10000);

            Assert.AreEqual(10000, delta10k.DeltaAdd(0, null, true, null));
            Assert.AreEqual(10000, delta10k.DeltaSubtract(0, null, true, null));

            // With current=2300, ref=1000, and interval=500, expect 2500 as next interval and 200 as solution
            // the reference will stay the same since the computation is cheap without updated reference
            TimePeriodDeltaResult result = delta500.DeltaAddWReference(2300, 1000, null, true, null);

            Assert.AreEqual(200, result.Delta);
            Assert.AreEqual(1000, result.LastReference);

            result = delta500.DeltaAddWReference(2300, 4200, null, true, null);
            Assert.AreEqual(400, result.Delta);
            Assert.AreEqual(4200, result.LastReference);

            result = delta500.DeltaAddWReference(2200, 4200, null, true, null);
            Assert.AreEqual(500, result.Delta);
            Assert.AreEqual(4200, result.LastReference);

            result = delta500.DeltaAddWReference(2200, 2200, null, true, null);
            Assert.AreEqual(500, result.Delta);
            Assert.AreEqual(2200, result.LastReference);

            result = delta500.DeltaAddWReference(2201, 2200, null, true, null);
            Assert.AreEqual(499, result.Delta);
            Assert.AreEqual(2200, result.LastReference);

            result = delta500.DeltaAddWReference(2600, 2200, null, true, null);
            Assert.AreEqual(100, result.Delta);
            Assert.AreEqual(2200, result.LastReference);

            result = delta500.DeltaAddWReference(2699, 2200, null, true, null);
            Assert.AreEqual(1, result.Delta);
            Assert.AreEqual(2200, result.LastReference);

            result = delta500.DeltaAddWReference(2699, 2700, null, true, null);
            Assert.AreEqual(1, result.Delta);
            Assert.AreEqual(2700, result.LastReference);

            result = delta10k.DeltaAddWReference(2699, 2700, null, true, null);
            Assert.AreEqual(1, result.Delta);
            Assert.AreEqual(2700, result.LastReference);

            result = delta10k.DeltaAddWReference(2700, 2700, null, true, null);
            Assert.AreEqual(10000, result.Delta);
            Assert.AreEqual(2700, result.LastReference);

            result = delta10k.DeltaAddWReference(2700, 6800, null, true, null);
            Assert.AreEqual(4100, result.Delta);
            Assert.AreEqual(6800, result.LastReference);

            result = delta10k.DeltaAddWReference(23050, 16800, null, true, null);
            Assert.AreEqual(3750, result.Delta);
            Assert.AreEqual(16800, result.LastReference);
        }