예제 #1
0
        private void runTestCaseDefinedInXmlFileWithPathIncludingDirectory(
            string pathToResourceXmlFile,
            IList <PathFinderFactory> pathFinderFactories,
            bool shouldAlsoTestResultsWithImplementationsAgainstEachOther = true
            )
        {
            XmlDocument document = xmlFileReader.GetResourceFileAsXmlDocument(pathToResourceXmlFile);
            XmlNodeList nodeList = xmlFileReader.GetNodeListMatchingXPathExpression(document, "graphTestData/graphDefinition");

            Assert.NotNull(nodeList);
            Assert.AreEqual(1, nodeList.Count);         // should only be one graph definition per file

            XmlNode nodeWithGraphDefinition = nodeList.Item(0);

            Assert.NotNull(nodeWithGraphDefinition);

            IList <Edge> edgesForGraphPotentiallyIncludingDuplicatedEdges = edgeParser.FromMultiLinedStringToListOfEdges(nodeWithGraphDefinition.InnerText);
            //		System.out.println("efetr fromMultiLinedStringToListOfEdges  " + edgesForGraphPotentiallyIncludingDuplicatedEdges.get(0).getClass());
            //System.out.println("edgesForGraphPotentiallyIncludingDuplicatedEdges " + edgesForGraphPotentiallyIncludingDuplicatedEdges.size());
            // There can be duplicates in the list of edges, whcih would cause exception at validation,
            // so therefore below instead remove duplicated with a chosen strategy
            // and one example file with many duplicated edges is "small_road_network_01.xml"
            IList <Edge> edgesForGraph = edgeUtility.GetEdgesWithoutDuplicates(edgesForGraphPotentiallyIncludingDuplicatedEdges, SelectionStrategyWhenEdgesAreDuplicated.FIRST_IN_LIST_OF_EDGES);
            //System.out.println("edgesForGraph " + edgesForGraph.size());
            // edgesForGraphPotentiallyIncludingDuplicatedEdges 28524
            // edgesForGraph 28320
            // The above output was the result when running tests for the file "small_road_network_01.xml"

            //		System.out.println("efetr getEdgesWithoutDuplicates  " + edgesForGraph.get(0).getClass());

            PathParser <Path, Edge, Vertex, Weight> pathParser = PathParser <Path, Edge, Vertex, Weight> .CreatePathParserDefault(edgesForGraph);

            XmlNodeList nodeListWithTestCases = xmlFileReader.GetNodeListMatchingXPathExpression(document, "graphTestData/testCase");

            Assert.NotNull(nodeListWithTestCases);         // shouold be zero rather than null i.e. this is okay to test
            //assertEquals(1, nodeListWithTestCases.getLength()); // can be many (or zero, then just validat implementatins against each other)
            for (int i = 0; i < nodeListWithTestCases.Count; i++)
            {
                XmlNode     itemWithTestCase  = nodeListWithTestCases.Item(i);
                XmlNodeList nodeListWithInput = xmlFileReader.GetNodeListMatchingXPathExpression(itemWithTestCase, "input");
                string      outputExpectedAsMultiLinedString = xmlFileReader.GetTextContentNodeOfFirstSubNode(itemWithTestCase, "outputExpected");
                //			System.out.println("outputExpectedAsMultiLinedString " + outputExpectedAsMultiLinedString);
                //List fromStringToListOfPaths = pathParser.fromStringToListOfPaths(outputExpectedAsMultiLinedString);
                IList <Path> expectedListOfPaths = outputExpectedAsMultiLinedString == null || outputExpectedAsMultiLinedString.Trim().Equals("") ? null : pathParser.FromStringToListOfPaths(outputExpectedAsMultiLinedString);

                GraphEdgesValidator <Path, Edge, Vertex, Weight> edgeGraphEdgesValidator = GraphEdgesValidator <Path, Edge, Vertex, Weight> .CreateGraphEdgesValidator <Path, Edge, Vertex, Weight>();

                edgeGraphEdgesValidator.ValidateEdgesAsAcceptableInputForGraphConstruction(edgesForGraph);
                if (expectedListOfPaths != null)
                {
                    edgeGraphEdgesValidator.ValidateAllPathsOnlyContainEdgesDefinedInGraph(expectedListOfPaths, edgesForGraph);
                }

                Assert.AreEqual(1, nodeListWithInput.Count);             // should only be one input element
                XmlNode nodeWithInputForTestCase = nodeListWithInput.Item(0);
                //final NodeList nodeListWithInput = xmlFileReader.getNodeListMatchingXPathExpression(itemWithTestCase, "input");
                string startVertexId = xmlFileReader.GetTextContentNodeOfFirstSubNode(nodeWithInputForTestCase, "startVertex");
                string endVertexId   = xmlFileReader.GetTextContentNodeOfFirstSubNode(nodeWithInputForTestCase, "endVertex");
                //			System.out.println("startVertexId " + startVertexId);
                //			System.out.println("endVertexId " + endVertexId);
                string maxNumberOfPathsAsString = xmlFileReader.GetTextContentNodeOfFirstSubNode(nodeWithInputForTestCase, "maxNumberOfPaths");
                int    maxNumberOfPaths         = int.Parse(maxNumberOfPathsAsString);

                //			System.out.println("maxNumberOfPaths " + maxNumberOfPaths);
                //			System.out.println("innan graphShortestPathAssertionHelper.testResultsWithImplementationsAgainstEachOther " + edgesForGraph.get(0).getClass());

                // pathToResourceXmlFile
                graphShortestPathAssertionHelper.AssertExpectedResultsOrAssertImplementationsWithEachOther(
                    edgesForGraph,
                    CreateVertex(startVertexId),
                    CreateVertex(endVertexId),
                    maxNumberOfPaths,
                    pathFinderFactories,
                    expectedListOfPaths,                 // null, // expectedListOfPaths , use null when we do not want to fail because of expected output according to xml but maybe instyead want to print output with below paaraeter
                    pathToResourceXmlFile,
                    shouldAlsoTestResultsWithImplementationsAgainstEachOther
                    );
            }
        }