Esempio n. 1
0
        public WorkOut GetMostMilesTraveled()
        {
            var     mostMiles       = 0;
            WorkOut FurthestWorkout = null;

            foreach (var workout in _workOuts)
            {
                if (workout.Miles > mostMiles)
                {
                    FurthestWorkout = workout;
                    mostMiles       = workout.Miles;
                }
            }
            return(FurthestWorkout);
        }
Esempio n. 2
0
        public WorkOut GetWorkoutWithBestSpeed()
        {
            double  bestSpeed   = 0;
            WorkOut bestWorkout = null;

            foreach (var workout in _workOuts)
            {
                double workoutSpeed = GetMilesPerMinute(workout);

                bestWorkout = (workoutSpeed > bestSpeed) ? workout : bestWorkout;
                bestSpeed   = (workoutSpeed > bestSpeed) ? workoutSpeed : bestSpeed;

                // refactor to an if block, show how you forget to update bestspeed
                // and your live unit test catches the slip up and you can fix immediately
            }
            return(bestWorkout);
        }
Esempio n. 3
0
 public static string GetWorkoutIntensity(WorkOut workout)
 {
     if (workout == null)
     {
         return("No Workout");
     }
     if ((workout.Duration <= TimeSpan.FromMinutes(30) &&
          workout.Miles >= 10) ||
         workout.Miles >= 20)
     {
         return("Hard");
     }
     else if (workout.Duration < TimeSpan.FromMinutes(30) ||
              workout.Miles < 10)
     {
         return("Easy");
     }
     else
     {
         return("Medium");
     }
 }
Esempio n. 4
0
 public double GetMilesPerMinute(WorkOut workout)
 {
     return(workout.Miles / workout.Duration.TotalMinutes);
 }