How to count a distance when travelling through several stations on the same line?

  • Thread starter Thread starter BarbraFleg
  • Start date Start date
B

BarbraFleg

Guest
public double TravelTimeOnSameLine(IStation from, IStation to, int speed)
{
//check values
if (from == to || from == null || to == null || speed <= 0)
throw new ArgumentException();

var commonLines = from.Lines.Intersect(to.Lines);
if (!commonLines.Any())
{
throw new ArgumentException();
}

var line = commonLines.First();
var distance = 0.0;

//Calcul path between stations (find the stations)

if (to == line.Next(to))
{
foreach (var finalStation in _stations)
//for (int numberOfStations = 0; numberOfStations > 1; numberOfStations++)
//{
// numberOfStations++;
//}
//return GetDistancebtween(x1: from.X, y1: from.Y, x2: to.X, y2: to.Y);
return GetDistancebtween(x1: from.X, y1: from.Y, x2: to.X, y2: to.Y);
}

//then calcul distance (between all the stations)

double dis = GetDistancebtween(x1: from.X, y1: from.Y, x2: to.X, y2: to.Y);
distance += dis;
var travelTime = distance / speed;
return travelTime;
}


I am trying to pass a last unit test and I am missing the calculation when I count a travel time through multiple stations.


public void T3_travel_time_on_more_stations()
{
ICity city = CityFactory.CreateCity("Paris");

IStation a = city.AddStation("A", 0, 0);
IStation b = city.AddStation("B", 0, 10);
IStation c = city.AddStation("C", 10, 10);
IStation d = city.AddStation("D", 10, 0);

ILine l1 = city.AddLine("ligne 1");

l1.AddBefore(a);
l1.AddBefore(b);
l1.AddBefore(c);
l1.AddBefore(d);

city.TravelTimeOnSameLine( a, d, 1).Should().Be(30.0);
}



Continue reading...
 
Back
Top