public double GetAverageFuelConsumption(IRace Race) { var averageFuelConsumption = 0.0; for (int i=0; i< Race.Waypoints.Count(); i++) { // Check Instruction if not null in case value sent from Unit testing var instruction = Race.Waypoints.ElementAt(i).Instruction ?? WayPointInstructionsHelper.GetWayPointInstruction(Race.Waypoints.ElementAt(i), Race.Waypoints.ToList()); SetCurrentSpeed(instruction); var distance = 0.0; // no need for calculate distance in last wayoint assuming that last point is Race end point if(i != Race.Waypoints.Count() - 1) distance = Race.GetDistanceForLeg(Race.Waypoints.ElementAt(i).Position, Race.Waypoints.ElementAt(i + 1).Position); // What If current Speed not in low or high range How to calculate Consumption ?? if (LowSpeedConsumption.Range.IsWithinRange(this.CurrentSpeed)) averageFuelConsumption += LowSpeedConsumption.Consumption * distance; else if (HighSpeedConsumption.Range.IsWithinRange(this.CurrentSpeed)) averageFuelConsumption += HighSpeedConsumption.Consumption * distance; } return averageFuelConsumption; }