コード例 #1
0
ファイル: Program.cs プロジェクト: moeentahir/Trains
        static async Task MainAsync(string[] args)
        {
            try
            {
                // Step 1: Validate command line arguments and build Path
                var filePath = new InputValidator(args).Build();

                // Step 2: Build map
                var mapDataReader = new MapRawDataReaderFromFile(filePath);
                var map           = await new MapBuilder(mapDataReader).Build();

                // Step 3: Plan different routs
                var planningResult = await new JourneyPlanner(
                    map,
                    new DistanceCalculator(map),
                    new ShortestPathFinderRecursive(map),
                    new RouteFinderRecursive(map)
                    ).Plan();

                // Step 4: Display results
                DisplayResult(planningResult);
            }
            catch (ValidationException ex)
            {
                Console.WriteLine(ex.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"An error occured while processing your request. Error: {ex.Message}");
            }
        }
コード例 #2
0
        public async Task Plan_Journey_On_Official_Map()
        {
            // Step 1: Build map
            var mapDataReader = new MapRawDataReaderFromFile("OfficialMap.txt");
            var map           = await new MapBuilder(mapDataReader).Build();

            // Step 2: Plan different routs
            var plan = await new JourneyPlanner(
                map,
                new DistanceCalculator(map),
                new ShortestPathFinderIterative(map),
                new RouteFinderRecursive(map)
                ).Plan();

            Assert.AreEqual(plan[1], "9");             //The distance of the route A-B-C.
            Assert.AreEqual(plan[2], "5");             //The distance of the route A-D.
            Assert.AreEqual(plan[3], "13");            //The distance of the route A-D-C.
            Assert.AreEqual(plan[4], "22");            //The distance of the route A-E-B-C-D.
            Assert.AreEqual(plan[5], "No such route"); //The distance of the route A-E-D.
            Assert.AreEqual(plan[6], "2");             //The number of trips starting at C and ending at C with a maximum of 3 stops.
            Assert.AreEqual(plan[7], "3");             //The number of trips starting at A and ending at C with exactly 4 stops.
            Assert.AreEqual(plan[8], "9");             //The length of the shortest route (in terms of distance to travel) from A to C.
            Assert.AreEqual(plan[9], "9");             // The length of the shortest route (in terms of distance to travel) from B to B.
            Assert.AreEqual(plan[10], "7");            //The number of different routes from C to C with a distance of less than 30
        }
コード例 #3
0
        public async Task Build_Longer_Path_WithLess_Cost_Map()
        {
            var fileDataReader = new MapRawDataReaderFromFile("LongerPathWithLessCost.txt");
            var map            = await new MapBuilder(fileDataReader).Build();
            var totalRoutes    = map.Towns.SelectMany(m => m.Routes).Count();

            Assert.AreEqual(5, map.Towns.Count);
            Assert.AreEqual(totalRoutes, map.TotalRoutes);
            Assert.AreEqual(6, totalRoutes);
        }
コード例 #4
0
        public async Task Build_Complete_Map()
        {
            var fileDataReader = new MapRawDataReaderFromFile("CompleteMap.txt");
            var map            = await new MapBuilder(fileDataReader).Build();
            var totalRoutes    = map.Towns.SelectMany(m => m.Routes).Count();

            Assert.AreEqual(5, map.Towns.Count);
            Assert.AreEqual(totalRoutes, map.TotalRoutes);
            Assert.AreEqual(20, totalRoutes);
            Console.Out.WriteLine("test finished");
        }
コード例 #5
0
        public async Task Build_Official_Map()
        {
            var fileDataReader = new MapRawDataReaderFromFile("OfficialMap.txt");
            var map            = await new MapBuilder(fileDataReader).Build();

            var actual      = map.Towns.Count;
            var expected    = 5;
            var totalRoutes = map.Towns.SelectMany(m => m.Routes).Count();

            Assert.AreEqual(expected, actual);
            Assert.AreEqual(totalRoutes, map.TotalRoutes);
            Assert.AreEqual(9, totalRoutes);
        }