private string GetRoundingText(Rounding rounding)
 {
     var roundingText = string.Empty;
     if (rounding != null)
         roundingText += string.Format(" ({0} {1}) ", GetRoundingStyleText(rounding), rounding.Step);
     return roundingText;
 }
Beispiel #2
0
        protected override ComparerResult CompareObjects(object x, object y, Rounding rounding)
        {
            if (!(rounding is DateTimeRounding))
                throw new ArgumentException("Rounding must be of type 'DateTimeRounding'");

            return CompareObjects(x, y, (DateTimeRounding)rounding);
        }
Beispiel #3
0
        public ComparerResult Compare(object x, object y, Rounding rounding)
        {
            var eq = CompareBasic(x, y);
            if (eq != null)
                return eq;

            return CompareObjects(x, y, rounding);
        }
Beispiel #4
0
        public NumericRounding(double step, Rounding.RoundingStyle style)
            : base(step.ToString(NumberFormatInfo.InvariantInfo), style)
        {
            if (step <= 0)
                throw new ArgumentException("The parameter '{0}' must be a value greater than zero.", "step");

            this.step = step;
        }
        public virtual string GetText(ColumnRole role, ColumnType type, Tolerance tolerance, Rounding rounding)
        {
            var roleText = GetRoleText(role);
            var typeText = GetTypeText(type);
            var toleranceText = GetToleranceText(tolerance);
            var roundingText = GetRoundingText(rounding);

            var value = string.Format("{0} ({1}){2}{3}{4}", roleText, typeText, (toleranceText + roundingText).Length > 0 ? " " : "", toleranceText, roundingText);

            return value;
        }
        public DateTimeRounding(TimeSpan step, Rounding.RoundingStyle style)
            : base(step.ToString(), style)
        {
            if (step.Ticks <= 0)
                throw new ArgumentException("The parameter 'step' must be a value greater than zero.", "step");

            if (step.TotalDays > 1)
                throw new ArgumentException("The parameter 'step' must be less or equal to one day", "step");

            this.step = step;
        }
 private string GetRoundingStyleText(Rounding rounding)
 {
     switch (rounding.Style)
     {
         case Rounding.RoundingStyle.None:
             return string.Empty;
         case Rounding.RoundingStyle.Floor:
             return "floor";
         case Rounding.RoundingStyle.Round:
             return "round";
         case Rounding.RoundingStyle.Ceiling:
             return "ceiling";
     }
     return "?";
 }
        public void GetValue_ValueStepStyle_NewValue(decimal value, int step, Rounding.RoundingStyle roundingStyle, decimal newValue)
        {
            var rounder = new NumericRounding(step, roundingStyle);

            Assert.That(rounder.GetValue(value), Is.EqualTo(newValue));
        }
Beispiel #9
0
 protected abstract ComparerResult CompareObjects(object x, object y, Rounding rounding);
Beispiel #10
0
 protected override ComparerResult CompareObjects(object x, object y, Rounding rounding)
 {
     throw new NotImplementedException("You cannot compare with a boolean comparer and a rounding.");
 }
        public void GetValue_ValueQuarterHourRoundingStyle_NewValue(DateTime value, Rounding.RoundingStyle roundingStyle, DateTime newValue)
        {
            var rounder = new DateTimeRounding(new TimeSpan(0, 0, 15, 0), roundingStyle);

            Assert.That(rounder.GetValue(value), Is.EqualTo(newValue));
        }
Beispiel #12
0
 protected override ComparerResult CompareObjects(object x, object y, Rounding rounding)
 {
     throw new NotImplementedException("You cannot compare with a text comparer and a rounding.");
 }