/// <summary>
 /// Checks whether the specified speed is in range.
 /// </summary>
 /// <param name="speed">The speed.</param>
 /// <param name="parameterName">Name of the parameter.</param>
 /// <param name="usage">The usage.</param>
 internal static void VerifySpeedInRange(Speed speed, string parameterName = null, string usage = null)
 {
     if (speed.CompareTo(Speed.MinValue) < 0 || speed.CompareTo(Speed.MaxValue) > 0)
     {
         throw new ArgumentException($"{usage ?? "Speed"} must be between {Speed.MinValue.Value} and {Speed.MaxValue.Value} inclusive.", parameterName ?? nameof(speed));
     }
 }
예제 #2
0
        public void CompareToIsImplemented()
        {
            Speed meterpersecond = Speed.FromMetersPerSecond(1);

            Assert.Equal(0, meterpersecond.CompareTo(meterpersecond));
            Assert.True(meterpersecond.CompareTo(Speed.Zero) > 0);
            Assert.True(Speed.Zero.CompareTo(meterpersecond) < 0);
        }
예제 #3
0
        public void CompareToIsImplemented()
        {
            Speed meterpersecond = Speed.FromMetersPerSecond(1);

            Assert.AreEqual(0, meterpersecond.CompareTo(meterpersecond));
            Assert.Greater(meterpersecond.CompareTo(Speed.Zero), 0);
            Assert.Less(Speed.Zero.CompareTo(meterpersecond), 0);
        }
예제 #4
0
        public void CompareToThrowsOnNull()
        {
            Speed meterpersecond = Speed.FromMetersPerSecond(1);

// ReSharper disable once ReturnValueOfPureMethodIsNotUsed
            meterpersecond.CompareTo(null);
        }
예제 #5
0
        public void CompareToThrowsOnTypeMismatch()
        {
            Speed meterpersecond = Speed.FromMetersPerSecond(1);

// ReSharper disable once ReturnValueOfPureMethodIsNotUsed
            meterpersecond.CompareTo(new object());
        }
        private void _scrollTimer_Tick(object sender, EventArgs e)
        {
            _ticksElapsed++;

            if (!Paused && Speed.CompareTo(0) != 0)
            {
                MainScrollerVerticalOffset = MainScrollerVerticalOffset + Speed;
            }
            else if (TotalBoostAmount.CompareTo(0) != 0)
            {
                MainScrollerVerticalOffset = MainScrollerVerticalOffset +
                                             TotalBoostAmount;
            }



            //Only update calculations every 10 timer ticks (100 ms)
            if (_ticksElapsed % 10 == 0)
            {
                //Calculate pixels per second (velocity)
                if (DateTime.Now - _prevTime > TimeSpan.FromSeconds(1))
                {
                    CalcEta();
                }

                PercentComplete = ((MainScrollerVerticalOffset + EyelinePosition) /
                                   (MainScrollerExtentHeight + EyelinePosition)) * 100;
            }
        }
예제 #7
0
 public void CompareToDoubleTest()
 {
     Speed target = new Speed(10F);
     double value = 10F;
     int expected = 0;
     int actual;
     actual = target.CompareTo(value);
     Assert.AreEqual(expected, actual);
 }
예제 #8
0
 public void CompareToObjectTest()
 {
     Speed target = new Speed(10F);
     object value = new Speed(10F);
     int expected = 0;
     int actual;
     actual = target.CompareTo(value);
     Assert.AreEqual(expected, actual);
 }
예제 #9
0
        public int CompareTo(Unit unit)
        {
            int compare = Type.CompareTo(unit.Type);

            if (compare != 0)
            {
                return(compare);
            }
            compare = string.CompareOrdinal(Name, unit.Name);
            if (compare != 0)
            {
                return(compare);
            }
            compare = Speed.CompareTo(unit.Speed);
            if (compare != 0)
            {
                return(compare);
            }
            compare = Damage.CompareTo(unit.Damage);
            return(compare);
        }
예제 #10
0
        public void CompareToThrowsOnNull()
        {
            Speed meterpersecond = Speed.FromMetersPerSecond(1);

            Assert.Throws <ArgumentNullException>(() => meterpersecond.CompareTo(null));
        }
예제 #11
0
        public void CompareToThrowsOnTypeMismatch()
        {
            Speed meterpersecond = Speed.FromMetersPerSecond(1);

            Assert.Throws <ArgumentException>(() => meterpersecond.CompareTo(new object()));
        }
예제 #12
0
        // Column specific sort
        public int CompareTo(RecordWrapper a2, RecordComparer.ComparisonType comparisonMethod, RecordComparer.Order sortOrder)
        {
            int result = 0;

            switch (comparisonMethod)
            {
            case RecordComparer.ComparisonType.Distance:
                if (ActualDistance != a2.ActualDistance)
                {
                    result = ActualDistance.CompareTo(a2.ActualDistance);
                }
                else
                {
                    result = StartDateTime.CompareTo(a2.StartDateTime);
                }

                break;

            case RecordComparer.ComparisonType.StartDistance:
                if (StartDistance != a2.StartDistance)
                {
                    result = StartDistance.CompareTo(a2.StartDistance);
                }
                else
                {
                    result = StartDateTime.CompareTo(a2.StartDateTime);
                }

                break;

            case RecordComparer.ComparisonType.EndDistance:
                if (EndDistance != a2.EndDistance)
                {
                    result = EndDistance.CompareTo(a2.EndDistance);
                }
                else
                {
                    result = StartDateTime.CompareTo(a2.StartDateTime);
                }

                break;

            case RecordComparer.ComparisonType.Location:
                if (Location != a2.Location)
                {
                    result = Location.CompareTo(a2.Location);
                }
                else
                {
                    result = StartDateTime.CompareTo(a2.StartDateTime);
                }

                break;

            case RecordComparer.ComparisonType.ElevationChange:
                if (ElevationChange != a2.ElevationChange)
                {
                    result = ElevationChange.CompareTo(a2.ElevationChange);
                }
                else
                {
                    result = StartDateTime.CompareTo(a2.StartDateTime);
                }

                break;

            case RecordComparer.ComparisonType.TotalAscend:
                if (TotalAscend != a2.TotalAscend)
                {
                    result = TotalAscend.CompareTo(a2.TotalAscend);
                }
                else
                {
                    result = StartDateTime.CompareTo(a2.StartDateTime);
                }

                break;

            case RecordComparer.ComparisonType.TotalDescend:
                if (TotalDescend != a2.TotalDescend)
                {
                    result = TotalDescend.CompareTo(a2.TotalDescend);
                }
                else
                {
                    result = StartDateTime.CompareTo(a2.StartDateTime);
                }

                break;

            case RecordComparer.ComparisonType.Temp:
                if (Temp != a2.Temp)
                {
                    result = Temp.CompareTo(a2.Temp);
                }
                else
                {
                    result = StartDateTime.CompareTo(a2.StartDateTime);
                }

                break;

            case RecordComparer.ComparisonType.Rank:
                if (Rank != a2.Rank)
                {
                    result = Rank.CompareTo(a2.Rank);
                }
                else
                {
                    result = StartDateTime.CompareTo(a2.StartDateTime);
                }

                break;

            case RecordComparer.ComparisonType.AvgPace:
                if (AvgPace != a2.AvgPace)
                {
                    result = AvgPace.CompareTo(a2.AvgPace);
                }
                else
                {
                    result = StartDateTime.CompareTo(a2.StartDateTime);
                }

                break;

            case RecordComparer.ComparisonType.AvgSpeed:
                if (Speed != a2.Speed)
                {
                    result = Speed.CompareTo(a2.Speed);
                }
                else
                {
                    result = StartDateTime.CompareTo(a2.StartDateTime);
                }

                break;

            case RecordComparer.ComparisonType.AvgHR:
                if (AvgHR != a2.AvgHR)
                {
                    result = AvgHR.CompareTo(a2.AvgHR);
                }
                else
                {
                    result = StartDateTime.CompareTo(a2.StartDateTime);
                }

                break;

            case RecordComparer.ComparisonType.MaxHR:
                if (MaxHR != a2.MaxHR)
                {
                    result = MaxHR.CompareTo(a2.MaxHR);
                }
                else
                {
                    result = StartDateTime.CompareTo(a2.StartDateTime);
                }

                break;

            case RecordComparer.ComparisonType.StartDateTime:
            default:
                result = StartDateTime.CompareTo(a2.StartDateTime);
                break;
            }

            if (sortOrder == RecordComparer.Order.Descending)
            {
                return(result * -1);
            }
            else
            {
                return(result);
            }
        }
예제 #13
0
        // Column specific sort
        public int CompareTo(Record a2, RecordComparer.ComparisonType comparisonMethod, RecordComparer.Order sortOrder)
        {
            int result = 0;

            switch (comparisonMethod)
            {
            // Define all different sort methods
            case RecordComparer.ComparisonType.AvgPower:
                if (AvgPower != a2.AvgPower)
                {
                    result = AvgPower.CompareTo(a2.AvgPower);
                }
                else
                {
                    result = StartDateTime.CompareTo(a2.StartDateTime);
                }

                break;

            case RecordComparer.ComparisonType.MaxPower:
                if (MaxPower != a2.MaxPower)
                {
                    result = MaxPower.CompareTo(a2.MaxPower);
                }
                else
                {
                    result = StartDateTime.CompareTo(a2.StartDateTime);
                }

                break;

            case RecordComparer.ComparisonType.Category:
                if (CategoryName != a2.CategoryName)
                {
                    result = CategoryName.CompareTo(a2.CategoryName);
                }
                else
                {
                    // TODO: WTF is this?
                    switch (Category.Type)
                    {
                    case RecordCategory.RecordType.DistancePace:
                        result = AvgPace.CompareTo(a2.AvgPace);
                        break;

                    case RecordCategory.RecordType.MaxTemperature:
                        result = Temp.CompareTo(a2.Temp);
                        break;
                    }
                }

                break;

            case RecordComparer.ComparisonType.Distance:
                if (ActualDistance != a2.ActualDistance)
                {
                    result = ActualDistance.CompareTo(a2.ActualDistance);
                }
                else
                {
                    result = StartDateTime.CompareTo(a2.StartDateTime);
                }

                break;

            case RecordComparer.ComparisonType.StartDistance:
                if (StartDistance != a2.StartDistance)
                {
                    result = StartDistance.CompareTo(a2.StartDistance);
                }
                else
                {
                    result = StartDateTime.CompareTo(a2.StartDateTime);
                }

                break;

            case RecordComparer.ComparisonType.EndDistance:
                if (EndDistance != a2.EndDistance)
                {
                    result = EndDistance.CompareTo(a2.EndDistance);
                }
                else
                {
                    result = StartDateTime.CompareTo(a2.StartDateTime);
                }

                break;

            case RecordComparer.ComparisonType.Location:
                if (Location != a2.Location)
                {
                    result = Location.CompareTo(a2.Location);
                }
                else
                {
                    result = StartDateTime.CompareTo(a2.StartDateTime);
                }

                break;

            case RecordComparer.ComparisonType.ActivityCategory:
                if (ActivityCategory != a2.ActivityCategory)
                {
                    result = ActivityCategory.CompareTo(a2.ActivityCategory);
                }
                else
                {
                    result = StartDateTime.CompareTo(a2.StartDateTime);
                }

                break;

            case RecordComparer.ComparisonType.Name:
                if (Name != a2.Name)
                {
                    result = Name.CompareTo(a2.Name);
                }
                else
                {
                    result = StartDateTime.CompareTo(a2.StartDateTime);
                }

                break;

            case RecordComparer.ComparisonType.TotalTime:
                if (TotalTime != a2.TotalTime)
                {
                    result = TotalTime.CompareTo(a2.TotalTime);
                }
                else
                {
                    result = StartDateTime.CompareTo(a2.StartDateTime);
                }

                break;

            case RecordComparer.ComparisonType.ElevationChange:
                if (ElevationChange != a2.ElevationChange)
                {
                    result = ElevationChange.CompareTo(a2.ElevationChange);
                }
                else
                {
                    result = StartDateTime.CompareTo(a2.StartDateTime);
                }

                break;

            case RecordComparer.ComparisonType.TotalAscend:
                if (TotalAscend != a2.TotalAscend)
                {
                    result = TotalAscend.CompareTo(a2.TotalAscend);
                }
                else
                {
                    result = StartDateTime.CompareTo(a2.StartDateTime);
                }

                break;

            case RecordComparer.ComparisonType.TotalDescend:
                if (TotalDescend != a2.TotalDescend)
                {
                    result = TotalDescend.CompareTo(a2.TotalDescend);
                }
                else
                {
                    result = StartDateTime.CompareTo(a2.StartDateTime);
                }

                break;

            case RecordComparer.ComparisonType.Temp:
                if (Temp != a2.Temp)
                {
                    result = Temp.CompareTo(a2.Temp);
                }
                else
                {
                    result = StartDateTime.CompareTo(a2.StartDateTime);
                }

                break;

            case RecordComparer.ComparisonType.Rank:
                if (Rank != a2.Rank)
                {
                    result = Rank.CompareTo(a2.Rank);
                }
                else
                {
                    result = StartDateTime.CompareTo(a2.StartDateTime);
                }

                break;

            case RecordComparer.ComparisonType.AvgPace:
                if (AvgPace != a2.AvgPace)
                {
                    result = AvgPace.CompareTo(a2.AvgPace);
                }
                else
                {
                    result = StartDateTime.CompareTo(a2.StartDateTime);
                }

                break;

            case RecordComparer.ComparisonType.Speed:
                if (Speed != a2.Speed)
                {
                    result = Speed.CompareTo(a2.Speed);
                }
                else
                {
                    result = StartDateTime.CompareTo(a2.StartDateTime);
                }

                break;

            case RecordComparer.ComparisonType.AvgHR:
                if (AvgHR != a2.AvgHR)
                {
                    result = AvgHR.CompareTo(a2.AvgHR);
                }
                else
                {
                    result = StartDateTime.CompareTo(a2.StartDateTime);
                }

                break;

            case RecordComparer.ComparisonType.TotalCalories:
                if (TotalCalories != a2.TotalCalories)
                {
                    result = TotalCalories.CompareTo(a2.TotalCalories);
                }
                else
                {
                    result = StartDateTime.CompareTo(a2.StartDateTime);
                }

                break;

            case RecordComparer.ComparisonType.AvgCadence:
                if (AvgCadence != a2.AvgCadence)
                {
                    result = AvgCadence.CompareTo(a2.AvgCadence);
                }
                else
                {
                    result = StartDateTime.CompareTo(a2.StartDateTime);
                }

                break;

            case RecordComparer.ComparisonType.MaxSpeed:
                if (MaxSpeed != a2.MaxSpeed)
                {
                    result = MaxSpeed.CompareTo(a2.MaxSpeed);
                }
                else
                {
                    result = StartDateTime.CompareTo(a2.StartDateTime);
                }

                break;

            case RecordComparer.ComparisonType.MaxHR:
                if (MaxHR != a2.MaxHR)
                {
                    result = MaxHR.CompareTo(a2.MaxHR);
                }
                else
                {
                    result = StartDateTime.CompareTo(a2.StartDateTime);
                }

                break;

            case RecordComparer.ComparisonType.MaxElevation:
                if (MaxElevation != a2.MaxElevation)
                {
                    result = MaxElevation.CompareTo(a2.MaxElevation);
                }
                else
                {
                    result = StartDateTime.CompareTo(a2.StartDateTime);
                }

                break;

            case RecordComparer.ComparisonType.MinElevation:
                if (MinElevation != a2.MinElevation)
                {
                    result = MinElevation.CompareTo(a2.MinElevation);
                }
                else
                {
                    result = StartDateTime.CompareTo(a2.StartDateTime);
                }

                break;

            case RecordComparer.ComparisonType.MaxCadence:
                if (MaxCadence != a2.MaxCadence)
                {
                    result = MaxCadence.CompareTo(a2.MaxCadence);
                }
                else
                {
                    result = StartDateTime.CompareTo(a2.StartDateTime);
                }

                break;

            case RecordComparer.ComparisonType.MaxGrade:
                if (MaxGrade != a2.MaxGrade)
                {
                    result = MaxGrade.CompareTo(a2.MaxGrade);
                }
                else
                {
                    result = StartDateTime.CompareTo(a2.StartDateTime);
                }

                break;

            case RecordComparer.ComparisonType.MinGrade:
                if (MinGrade != a2.MinGrade)
                {
                    result = MinGrade.CompareTo(a2.MinGrade);
                }
                else
                {
                    result = StartDateTime.CompareTo(a2.StartDateTime);
                }

                break;

            case RecordComparer.ComparisonType.StartDateTime:
            default:
                result = StartDateTime.CompareTo(a2.StartDateTime);
                break;
            }

            if (sortOrder == RecordComparer.Order.Descending)
            {
                return(result * -1);
            }
            else
            {
                return(result);
            }
        }