Esempio n. 1
0
    public double GetInTimeUnitsNumeric(string ts, TimeUnitTypes tuType)
    {
        TimeUnit t = new TimeUnit(ts);

        switch (tuType)
        {
        case TimeUnitTypes.Seconds:
            return(t.InSecondsAsDouble);

        case TimeUnitTypes.Minutes:
            return(t.InMinutesAsDouble);

        case TimeUnitTypes.Hours:
            return(t.InHoursAsDouble);

        case TimeUnitTypes.Days:
            return(t.InDaysAsDouble);

        case TimeUnitTypes.Weeks:
            return(t.InWeeksAsDouble);

        default:
            throw new ArgumentException("Invalid Test Case Data supplied: " + ts);
        }
    }
Esempio n. 2
0
    public string GetInTimeUnits(string ts, TimeUnitTypes tuType)
    {
        TimeUnit t = new TimeUnit(ts);

        switch (tuType)
        {
        case TimeUnitTypes.Seconds:
            return(t.InSecondsAsString);

        case TimeUnitTypes.Minutes:
            return(t.InMinutesAsString);

        case TimeUnitTypes.Hours:
            return(t.InHoursAsString);

        case TimeUnitTypes.Days:
            return(t.InDaysAsString);

        case TimeUnitTypes.Weeks:
            return(t.InWeeksAsString);

        default:
            return("Invalid Test Case Parameter of " + ts);
        }
    }
Esempio n. 3
0
 private DataRateUnit(DataSizeUnitTypes sizeUnitType, TimeUnitTypes timeUnitType, double multiplier)
     : base(
         (int)UnitTypes.DataRate,
         $"{sizeUnitType.GetDescription()} {timeUnitType.GetDescription()}",
         GetBaseMultiplier(sizeUnitType, timeUnitType),
         multiplier)
 {
 }
Esempio n. 4
0
 private RateUnit(MagnitudeUnitTypes magnitudeUnitType, TimeUnitTypes timeUnitType, double multiplier)
     : base(
         (int)UnitTypes.Rate,
         $"{magnitudeUnitType.GetDescription()} {timeUnitType.GetDescription()}",
         GetBaseMultiplier(magnitudeUnitType, timeUnitType),
         multiplier)
 {
 }
Esempio n. 5
0
 private TimeUnit(TimeUnitTypes unitType, double multiplier)
     : base(
         (int)UnitTypes.Time,
         unitType.GetDescription(),
         GetBaseMultiplier(unitType),
         multiplier)
 {
 }
Esempio n. 6
0
        /// <summary>
        /// Takes a number of seconds and turns it into a TimeUnit value stored as seconds.  Seconds will be the preferred UnitType display.
        /// </summary>
        /// <param name="seconds">The number of seconds the TimeUnit represents</param>
        public TimeUnit(long milliSeconds)
        {
            if (milliSeconds < 0)
            {
                throw new ArgumentException("TimeUnits cannot be negative numbers.");
            }

            _milliSeconds = milliSeconds;
            _unitType     = TimeUnitTypes.Milliseconds;
        }
Esempio n. 7
0
 private static double GetBaseMultiplier(DataSizeUnitTypes sizeUnitType, TimeUnitTypes timeUnitType)
 {
     return(Math.Pow(1024, (int)sizeUnitType) * (double)timeUnitType);
 }
Esempio n. 8
0
 private DataRateUnit(DataSizeUnitTypes sizeUnitType, TimeUnitTypes timeUnitType)
     : this(sizeUnitType, timeUnitType, 1)
 {
 }
Esempio n. 9
0
 public void TimeUnitStringValues_AreCorrect(TimeUnitTypes val, string result)
 {
     Assert.AreEqual(TimeUnit.GetTimeUnitTypeAsString(val), result);
 }
Esempio n. 10
0
 private static double GetBaseMultiplier(TimeUnitTypes unitType)
 {
     return((double)unitType);
 }
Esempio n. 11
0
 private TimeUnit(TimeUnitTypes unitType)
     : this(unitType, 1)
 {
 }
Esempio n. 12
0
        public TimeUnit(string value)
        {
            // First get last character of string.  Must be a letter.
            int len = value.Length;

            // Length must be > 2.
            if (len < 2)
            {
                throw new ArgumentException(
                          "value", "The value of TimeValue must be in the format of <number><TimeType> Where TimeType is a single character.");
            }

            char timeIncrement = value [len - 1];

            // Now get first part of string which is the numeric part.
            string timeDuration = new string(value.TakeWhile(d => !Char.IsLetter(d)).ToArray());


            // Validate we have a number and ultimately convert into a long for storing.
            long numericValue;

            if (!long.TryParse(timeDuration, out numericValue))
            {
                throw new ArgumentException(
                          "value",
                          "Did not contain a valid numeric prefix.  Proper format is <Number><TimeType> where Number is an integer and TimeType is a single character.");
            }


            // To completely validate we have what they sent we build a new string from the 2 components and compare the 2.  Should be equal.
            string snew = numericValue.ToString() + timeIncrement;

            if (snew != value)
            {
                string msg = String.Format(
                    "Argument is in an invalid format - [{0}].  Proper format is <Number><TimeType> where Number is an integer and TimeType is a single character.",
                    value);
                throw new ArgumentException("value", msg);
            }


            // Now we just need to validate the time unit type is correct and convert to seconds.


            // Validate the unit of time is correct.
            switch (timeIncrement)
            {
            case 'd':
                _unitType     = TimeUnitTypes.Days;
                _milliSeconds = MILLISECONDS_IN_DAY * numericValue;
                break;

            case 'm':
                _unitType     = TimeUnitTypes.Minutes;
                _milliSeconds = MILLISECONDS_IN_MINUTE * numericValue;
                break;

            case 'h':
                _unitType     = TimeUnitTypes.Hours;
                _milliSeconds = MILLISECONDS_IN_HOUR * numericValue;
                break;

            case 's':
                _unitType     = TimeUnitTypes.Seconds;
                _milliSeconds = MILLISECONDS_IN_SECOND * numericValue;
                break;

            case 'w':
                _unitType     = TimeUnitTypes.Weeks;
                _milliSeconds = MILLISECONDS_IN_WEEK * numericValue;
                break;

            case 'S':
                _unitType     = TimeUnitTypes.Milliseconds;
                _milliSeconds = numericValue;
                break;

            default: throw new ArgumentException("Invalid TimeUnitType specified.  Must be one of S,s,m,h,d,w.");
            }
        }
Esempio n. 13
0
 private static double GetBaseMultiplier(MagnitudeUnitTypes magnitudeUnitType, TimeUnitTypes timeUnitType)
 {
     return(Math.Pow(10, (int)magnitudeUnitType) * (double)timeUnitType);
 }
Esempio n. 14
0
 private RateUnit(MagnitudeUnitTypes magnitudeUnitType, TimeUnitTypes timeUnitType)
     : this(magnitudeUnitType, timeUnitType, 1)
 {
 }