Example #1
0
        [TestMethod] // ReSharper disable once InconsistentNaming
        public void GetEnumerator_Iterating_DifferenceBetweenIterationsMatchesStepSize()
        {
            Period    length = RandomPeriod(MinPeriod, MaxPeriod, true, false);
            LocalDate start  = RandomLocalDate(MinLocalDate, MaxLocalDate - length);
            LocalDate end    = start + length;
            // note that the number of steps is limited to 100 or fewer
            Period step = PeriodDivideApprox(length, Random.Next(4, 100), false);

            LocalDateRange localRange = new LocalDateRange(start, end, step);

            LocalDate?previous = null;

            foreach (LocalDate d in localRange)
            {
                if (previous.HasValue)
                {
                    IComparer <Period> comparer = Period.CreateComparer(previous.Value.At(new LocalTime()));

                    Assert.AreEqual(
                        0,
                        comparer.Compare(Period.Between(previous.Value, d), step),
                        "Difference between iteration values should match the step value supplied");
                }
                previous = d;
            }
        }
Example #2
0
        public void Comparer_DurationablePeriods()
        {
            var bigger   = Period.FromHours(25);
            var smaller  = Period.FromDays(1);
            var comparer = Period.CreateComparer(new LocalDateTime(2000, 1, 1, 0, 0));

            Assert.That(comparer.Compare(bigger, smaller), Is.GreaterThan(0));
            Assert.That(comparer.Compare(smaller, bigger), Is.LessThan(0));
            Assert.AreEqual(0, comparer.Compare(bigger, bigger));
        }
Example #3
0
        public void Comparer_NonDurationablePeriods()
        {
            var month = Period.FromMonths(1);
            var days  = Period.FromDays(30);
            // At the start of January, a month is longer than 30 days
            var januaryComparer = Period.CreateComparer(new LocalDateTime(2000, 1, 1, 0, 0));

            Assert.That(januaryComparer.Compare(month, days), Is.GreaterThan(0));
            Assert.That(januaryComparer.Compare(days, month), Is.LessThan(0));
            Assert.AreEqual(0, januaryComparer.Compare(month, month));

            // At the start of February, a month is shorter than 30 days
            var februaryComparer = Period.CreateComparer(new LocalDateTime(2000, 2, 1, 0, 0));

            Assert.That(februaryComparer.Compare(month, days), Is.LessThan(0));
            Assert.That(februaryComparer.Compare(days, month), Is.GreaterThan(0));
            Assert.AreEqual(0, februaryComparer.Compare(month, month));
        }
Example #4
0
        public void Comparer_NonNullWithNull()
        {
            var comparer = Period.CreateComparer(new LocalDateTime(2000, 1, 1, 0, 0));

            Assert.That(comparer.Compare(Period.Zero, null), Is.GreaterThan(0));
        }
Example #5
0
        public void Comparer_NullWithNonNull()
        {
            var comparer = Period.CreateComparer(new LocalDateTime(2000, 1, 1, 0, 0));

            Assert.That(comparer.Compare(null, Period.Zero), Is.LessThan(0));
        }
Example #6
0
        public void Comparer_NullWithNull()
        {
            var comparer = Period.CreateComparer(new LocalDateTime(2000, 1, 1, 0, 0));

            Assert.AreEqual(0, comparer.Compare(null, null));
        }
Example #7
0
        public static int CompareDuration(Variable vA, Variable vB)
        {
            var comparer = Period.CreateComparer(new LocalDateTime(0, 1, 1, 0, 0));

            return(comparer.Compare(vA.DurationVal, vB.DurationVal));
        }