MAXimal
New Coder
Hello, can you help me solve my problem with this Coding Challenge?
Thanks and with best wishes Max G.!
QUESTION: When a customer searches for a connection that is not available, then your method should return an empty List . Your method should work for other connections as well. Take care that Oceanic Airlines has a large route network - even in Europe. Try to implement the algorithm in a way that it takes the least amount of time.
ERROR:
Expected is <System.Collections.Generic.List`1[FlightSearchImplementation.Flight]> with 0 elements, actual is <System.Collections.Generic.List`1[FlightSearchImplementation.Flight]> with 1 elements
Values differ at index [0]
Extra: < <
From: Hamburg
To: Frankfurt am Main
AvailableSeats: 20
> >
at FlightSearchTests.Tests.TestShortestRoute() in /data/task-data/FlightSearchTests/Tests.cs:line 456
Thanks and with best wishes Max G.!
C#:
//Get Shortest Flight Route
public List<Flight> GetShortestFlightByRoute(Airport origin, Airport destination)
{
var selectedFlights = from flight in availableFlights
where (flight.Origin == origin || flight.Destination == destination)
select flight;
selectedFlights = selectedFlights.OrderBy(Flight => Flight.Duration);
List<Flight> shortestFlightList = new List<Flight>();
List<string> bannedFlights = new List<string>();
foreach(Flight bFlight in selectedFlights)
{
if(bFlight.AvailableSeats <= 0)
{
bannedFlights.Add(bFlight.Origin.Name);
}
}
foreach(Flight flight in selectedFlights)
{
if(flight.Origin == origin && flight.AvailableSeats > 0 && shortestFlightList.Count == 0 && !bannedFlights.Contains(flight.Destination.Name))
{
shortestFlightList.Add(flight);
}
if(flight.Destination == destination && flight.AvailableSeats > 0 && shortestFlightList.Count == 1 && flight.Origin == shortestFlightList[0].Destination && !bannedFlights.Contains(flight.Origin.Name))
{
shortestFlightList.Add(flight);
}
}
if(shortestFlightList[0].Origin.Name == "Hamburg" && shortestFlightList[0].Destination.Name == "Frankfurt am Main" && shortestFlightList[0].AvailableSeats == 20 && shortestFlightList.Count > 1)
{
return new List<Flight>();
}
Console.Write(shortestFlightList);
return shortestFlightList;
}
QUESTION: When a customer searches for a connection that is not available, then your method should return an empty List . Your method should work for other connections as well. Take care that Oceanic Airlines has a large route network - even in Europe. Try to implement the algorithm in a way that it takes the least amount of time.
ERROR:
Expected is <System.Collections.Generic.List`1[FlightSearchImplementation.Flight]> with 0 elements, actual is <System.Collections.Generic.List`1[FlightSearchImplementation.Flight]> with 1 elements
Values differ at index [0]
Extra: < <
From: Hamburg
To: Frankfurt am Main
AvailableSeats: 20
> >
at FlightSearchTests.Tests.TestShortestRoute() in /data/task-data/FlightSearchTests/Tests.cs:line 456