コード例 #1
0
        public void Execute_InvalidArguments_ThrowsException()
        {
            var graph      = new Graph <char>();
            var calculator = new RouteDistanceCalculator <char>(graph);

            char[] route = null;

            var result = calculator.Execute(route);
        }
コード例 #2
0
        public void Execute_DifferentSourceAndDestination_CorrectResult(char [] route, int expectedResult)
        {
            var graph      = TestUtils.BuildDefaultTestGraph();
            var calculator = new RouteDistanceCalculator <char>(graph);

            var result = calculator.Execute(route);

            Assert.AreEqual(expectedResult, result);
        }
コード例 #3
0
        public void Execute_EmptyRoute_CorrectResult()
        {
            var graph      = new Graph <char>();
            var calculator = new RouteDistanceCalculator <char>(graph);

            var route          = new char[] { };
            var expectedResult = 0;

            var result = calculator.Execute(route);

            Assert.AreEqual(expectedResult, result);
        }
コード例 #4
0
        public void Execute_SourceNotExists_DefaultResult()
        {
            var graph      = new Graph <char>();
            var calculator = new RouteDistanceCalculator <char>(graph);

            var route          = new char[] { 'A', 'B' };
            var expectedResult = -1;

            var result = calculator.Execute(route);

            Assert.AreEqual(expectedResult, result);
        }
コード例 #5
0
        public void Execute_EdgeNotExists_DefaultResult()
        {
            var graphBuilder = new DirectedGraphBuilder <char>();

            graphBuilder.AddEdge('A', 'C', 5);

            var calculator = new RouteDistanceCalculator <char>(graphBuilder.GetGraph());

            var route          = new char[] { 'A', 'B' };
            var expectedResult = -1;

            var result = calculator.Execute(route);

            Assert.AreEqual(expectedResult, result);
        }
コード例 #6
0
        private void RunTestCases1To5(Graph <char> graph)
        {
            var calculator = new RouteDistanceCalculator <char>(graph);

            var routes = new char[][]
            {
                new char[] { 'A', 'B', 'C' },
                new char[] { 'A', 'D' },
                new char[] { 'A', 'D', 'C' },
                new char[] { 'A', 'E', 'B', 'C', 'D' },
                new char[] { 'A', 'E', 'D' }
            };

            for (int i = 0; i < routes.Length; i++)
            {
                var distance = calculator.Execute(routes[i]);
                var result   = distance != -1 ? distance.ToString() : "NO SUCH ROUTE";

                OutputResult(i + 1, result);
            }
        }