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

• ### Question

• ```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);

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

• Moved by Tuesday, January 14, 2020 1:40 PM looking for forum
Tuesday, January 14, 2020 1:23 PM

Richard Mueller - MVP Enterprise Mobility (Identity and Access)

Tuesday, January 14, 2020 1:39 PM
• I'd try asking for help over here.

https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?category=vslanguages

Regards, Dave Patrick ....
Microsoft Certified Professional
Microsoft MVP [Windows Server] Datacenter Management

Disclaimer: This posting is provided "AS IS" with no warranties or guarantees, and confers no rights.

Tuesday, January 14, 2020 1:39 PM

### All replies

Richard Mueller - MVP Enterprise Mobility (Identity and Access)

Tuesday, January 14, 2020 1:39 PM
• I'd try asking for help over here.

https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?category=vslanguages

Regards, Dave Patrick ....
Microsoft Certified Professional
Microsoft MVP [Windows Server] Datacenter Management

Disclaimer: This posting is provided "AS IS" with no warranties or guarantees, and confers no rights.

Tuesday, January 14, 2020 1:39 PM