示例#1
0
        public void TestF1()
        {
            RoadNetworkXmlOutputter RNO = new RoadNetworkXmlOutputter("map.xml");
            Map theMap;
            theMap = Map.FromFile("map.xml");
            Vertex[] theVertices = new Vertex[4];
            RoadNetwork RN1 = new RoadNetwork(theMap);
                theVertices[0] = ((RoadNetwork)RN1).AddVertex(0, 0);
                theVertices[1] = ((RoadNetwork)RN1).AddVertex(10, 0);
                ((RoadNetwork)RN1).AddEdge(theVertices[0], theVertices[1]);
            RoadNetwork RN2 = new RoadNetwork(theMap);
                theVertices[2] = ((RoadNetwork)RN2).AddVertex(5, 5);
                theVertices[3] = ((RoadNetwork)RN2).AddVertex(10, 10);
                ((RoadNetwork)RN2).AddEdge(theVertices[2], theVertices[3]);
            AATreeGeneration generation = new AATreeGeneration();
            generation.Insert(RN1, 1);
            generation.Insert(RN2, 2);

            XmlWriter writer1 = XmlWriter.Create("test1xml.xml");
            XmlWriter writer2 = XmlWriter.Create("test2xml.xml");
            //Output individuals/generation somehow.
            RN1.WriteXml(writer1);
            writer1.Close();
            RN2.WriteXml(writer2);
            writer2.Close();

            XmlTextReader reader1 = new XmlTextReader("test1xml.xml");
            XmlTextReader reader2= new XmlTextReader("test2xml.xml");
            RoadNetworkReader rnr = new RoadNetworkReader();

            RoadNetwork RNL1 = (RoadNetwork)rnr.ReadIndividual(reader1);
            RoadNetwork RNL2 = (RoadNetwork)rnr.ReadIndividual(reader2);
            Assert.AreEqual(RNL1.GetVertex(0).Coordinates.X, 0);
            Assert.AreEqual(RNL1.GetVertex(0).Coordinates.Y, 0);
            Assert.AreEqual(RNL1.GetVertex(1).Coordinates.X, 10);
            Assert.AreEqual(RNL1.GetVertex(1).Coordinates.Y, 0);
            Assert.AreEqual(RNL2.GetVertex(0).Coordinates.X, 5);
            Assert.AreEqual(RNL2.GetVertex(0).Coordinates.Y, 5);
            Assert.AreEqual(RNL2.GetVertex(1).Coordinates.X, 10);
            Assert.AreEqual(RNL2.GetVertex(1).Coordinates.Y, 10);
            Assert.AreEqual(RNL1.GetEdge(0).Start.Coordinates.X, 0);
            Assert.AreEqual(RNL1.GetEdge(0).Start.Coordinates.Y, 0);
            Assert.AreEqual(RNL1.GetEdge(0).End.Coordinates.X, 10);
            Assert.AreEqual(RNL1.GetEdge(0).End.Coordinates.Y, 0);
            Assert.AreEqual(RNL2.GetEdge(0).Start.Coordinates.X, 5);
            Assert.AreEqual(RNL2.GetEdge(0).Start.Coordinates.Y, 5);
            Assert.AreEqual(RNL2.GetEdge(0).End.Coordinates.X, 10);
            Assert.AreEqual(RNL2.GetEdge(0).End.Coordinates.Y, 10);
        }