Exemplo n.º 1
0
        /// <summary>
        /// Writes the expected program outputs to the stdout.
        /// </summary>
        /// <param name="railwaySystem">An instance of <see cref="IRailwaySystem"/>.</param>
        private static void WriteOutput(IRailwaySystem railwaySystem)
        {
            var tripService = new TripService();
            var pathBuilder = new PathBuilder();

            Console.WriteLine();
            SafeWriteOutput(1, () => tripService.ResolveDistance(pathBuilder.Build(railwaySystem, "A", "B", "C")).ToString());
            SafeWriteOutput(2, () => tripService.ResolveDistance(pathBuilder.Build(railwaySystem, "A", "D")).ToString());
            SafeWriteOutput(3, () => tripService.ResolveDistance(pathBuilder.Build(railwaySystem, "A", "D", "C")).ToString());
            SafeWriteOutput(4, () => tripService.ResolveDistance(pathBuilder.Build(railwaySystem, "A", "E", "B", "C", "D")).ToString());
            SafeWriteOutput(5, () => tripService.ResolveDistance(pathBuilder.Build(railwaySystem, "A", "E", "D")).ToString());
            Console.WriteLine($"Output #6: {tripService.Search(railwaySystem.GetTownByName("C"), railwaySystem.GetTownByName("C"), trip => trip.Stops > 3).Count()}");
            Console.WriteLine($"Output #7: {tripService.Search(railwaySystem.GetTownByName("A"), railwaySystem.GetTownByName("C"), trip => trip.Stops > 4, trip => trip.Stops == 4).Count()}");
            SafeWriteOutput(8, () => tripService.FindShortest(railwaySystem, railwaySystem.GetTownByName("A"), railwaySystem.GetTownByName("C")).TotalDistance.ToString());
            SafeWriteOutput(9, () => tripService.FindShortest(railwaySystem, railwaySystem.GetTownByName("B"), railwaySystem.GetTownByName("B")).TotalDistance.ToString());
            Console.WriteLine($"Output #10: {tripService.Search(railwaySystem.GetTownByName("C"), railwaySystem.GetTownByName("C"), trip => trip.TotalDistance >= 30).Count()}");
            Console.WriteLine();
        }