static void defaultTestOutput(MasterNodeList<string> masterNodeList) { Console.Out.WriteLine(); foreach (var node in masterNodeList.AllNodes) { if (node.kind == NodeKind.NullNode) { continue; } string typ = (node.kind == NodeKind.GateNode ? "Gate" : "Value:"); string outStr = node.SequenceNumber + " " + typ + " "; if (node.kind == NodeKind.ValueNode) { outStr += (node as ValueNode<string>).Value; } Console.Out.WriteLine(outStr); foreach (EdgeRoute route in node.OutgoingEdges) { outStr = " .." + route.connectedNodes.ElementAt(1).SequenceNumber + " if already " + route.edge.requisiteLink.from.SequenceNumber + ".." + route.edge.requisiteLink.to.SequenceNumber; Console.Out.WriteLine(outStr); } } }
static void loadFile(string filename,MasterNodeList<string> masterNodeList,bool quiet,bool splitLetters) { List<string> sentences; List<string> words; DataChunkRouteBlazer<string> blazer; using (TextReader reader = new StreamReader(new FileStream(filename, FileMode.Open, FileAccess.Read))) { sentences = SentenceChunkLoader.ToSentenceChunks(reader); } foreach (string sentence in sentences) { words = SentenceChunkLoader.ToWordValues(sentence); if (splitLetters) { foreach (string wordChunk in words) { blazer = new DataChunkRouteBlazer<string>(charStringsOf(wordChunk), masterNodeList); blazer.computeFullRoute(); Console.Out.WriteLine("Added word starting with " + wordChunk.Substring(0,1) + " at start node " + blazer.chunkRoute.startNode.SequenceNumber); } } else { blazer = new DataChunkRouteBlazer<string>(words, masterNodeList); blazer.computeFullRoute(); if (!quiet) { Console.Out.WriteLine("Added sentence starting with " + words.First() + " at start node " + blazer.chunkRoute.startNode.SequenceNumber); } } } }
public void getNodeAndReqSpecs() { MasterNodeList<string> nodeList = new MasterNodeList<string>(); Dictionary<Node, List<Route>> prefixD = new Dictionary<Node, List<Route>>(); DataChunkRouteBlazerTest.threeThreeChunks(nodeList, prefixD); IList<NodeAndReqSpec> specs = nodeList.AllNodeAndReqSpecs; Assert.AreEqual(12, specs.Count); }
public static void threeThreeChunks(MasterNodeList<string> inList, Dictionary<Node, List<Route>> inRoutePrefixDictionary) { DataChunkRouteBlazerTest test = new DataChunkRouteBlazerTest(); test.list = inList; test.routePrefixDictionary = inRoutePrefixDictionary; test.dataSetup13(); test.setup13append(); }
public static void threeSixChunks(MasterNodeList<string> inList, Dictionary<Node, List<Route>> inRoutePrefixDictionary) { DataChunkRouteBlazerTest test = new DataChunkRouteBlazerTest(); test.list = inList; test.routePrefixDictionary = inRoutePrefixDictionary; test.dataSetup46(); test.chunkRouteAppendThriceOther(); }
public void getAndSetNodeSpecs() { MasterNodeList<string> nodeListExporter = threeSixNodeList(); MasterNodeList<string> nodeListImporter = new MasterNodeList<string>(); nodeListImporter.reloadNodesFromSpecs(nodeListExporter.AllNodeSpecs); Assert.AreEqual(nodeListExporter.AllNodes.Count(), nodeListImporter.AllNodes.Count()); Assert.AreEqual(nodeListExporter.AllNodes.OfType<GateNode>().Count(), nodeListImporter.AllNodes.OfType<GateNode>().Count()); Assert.AreEqual(nodeListExporter.AllNodes.OfType<ValueNode<string>>().ElementAt(5).Value, nodeListImporter.AllNodes.OfType<ValueNode<string>>().ElementAt(5).Value); }
public void produceAndSendNewDelta() { MasterNodeList<string> localNodeList = new MasterNodeList<string>(); DataChunkRouteBlazerTest.threeThreeChunks(localNodeList, new Dictionary<Node, List<Route>>()); StringReader rdr = new StringReader(DeltaDirectoryTest.CURBASE); MemoryStream resStream = new MemoryStream(); DeltaRequestResultKind result = DeltaRequestHandler.handleDeltaRequest(deltaDir, new MasterNodeList<string>(), localNodeList, new ToStringNodeValueExporter<string>(), rdr, resStream); Assert.AreEqual(DeltaRequestResultKind.Deltas, result); using (FileStream fileStream = new FileStream("testNew.tar.gz", FileMode.Create)) { new MemoryStream(resStream.ToArray()).CopyTo(fileStream); } }
public void testNewDeltaResponse() { MasterNodeList<string> localNodeList = new MasterNodeList<string>(); DataChunkRouteBlazerTest.threeThreeChunks(localNodeList, new Dictionary<Node, List<Route>>()); MasterNodeList<string> baseNodeList = new MasterNodeList<string>(); MasterNodeList<string> newLocalNodeList; using (FileStream fileStream = new FileStream("testNewDelt.tar.gz", FileMode.Open)) { DeltaResponseResultKind result = DeltaResponseHandler.handleDeltaArchiveResponse(localNodeList, deltaDir, baseNodeList, new StringNodeValueParser(), new ToStringNodeValueExporter<string>(), fileStream,out newLocalNodeList); Assert.AreEqual(DeltaResponseResultKind.Acceptance, result); Assert.Greater(baseNodeList.DataChunkCount, 0); } }
public void testRewriteResponse() { MasterNodeList<string> localNodeList = new MasterNodeList<string>(); Dictionary<Node, List<Route>> dict = new Dictionary<Node,List<Route>>(); localNodeList.nodeRoutesDictionary = dict; DataChunkRouteBlazerTest.threeThreeChunks(localNodeList,dict); MasterNodeList<string> baseNodeList = new MasterNodeList<string>(); MasterNodeList<string> newLocalNodeList; // testRewrite contains a delta archive for the threeThreeChunks graph using (FileStream fileStream = new FileStream("testRewrite.tar.gz", FileMode.Open)) { DeltaResponseResultKind result = DeltaResponseHandler.handleDeltaArchiveResponse(localNodeList, deltaDir, baseNodeList, new StringNodeValueParser(), new ToStringNodeValueExporter<string>(), fileStream, out newLocalNodeList); Assert.AreEqual(DeltaResponseResultKind.Rewrite, result); Assert.Greater(newLocalNodeList.DataChunkCount, localNodeList.DataChunkCount); } }
public void threeThreeTest() { MasterNodeList<string> nodeList = new MasterNodeList<string>(); Dictionary<Node, List<Route>> prefixD = new Dictionary<Node, List<Route>>(); DataChunkRouteBlazerTest.threeThreeChunks(nodeList, prefixD); int origCount = nodeList.AllNodes.Count(); int origEdgeCount = nodeList.AllEdgeSpecs.Count(); Assert.AreEqual(3, nodeList.enumerateDataChunkRoutes().Count()); BinaryAndTXTFormat<string> format = new BinaryAndTXTFormat<string>("nodesEdges.dat", "values.csv"); format.nodeValueParser = new StringNodeValueParser(); format.ToBinaryAndTXTFiles(nodeList); nodeList = new MasterNodeList<string>(); prefixD = new Dictionary<Node, List<Route>>(); nodeList = format.ToNodeListFromFiles(); Assert.AreEqual(origCount, nodeList.AllNodes.Count()); Assert.AreEqual(3, nodeList.enumerateDataChunkRoutes().Count()); Assert.AreEqual(origEdgeCount, nodeList.AllEdgeSpecs.Count()); }
public void SetUp() { nodeList = new MasterNodeList<string>(); vn = nodeList.newValueNodeFromValue("A"); vn2 = nodeList.newValueNodeFromValue("B"); vn3 = nodeList.newValueNodeFromValue("C"); edge = new Edge() { link = new DirectedPair() { from = vn, to = vn2 } }; edge2 = new Edge() { link = new DirectedPair() { from = vn3, to = vn } }; routeFactory = new RouteFactory<string>(); routeFactory.newRouteFromEdge(edge); }
public void SetUp() { list = new MasterNodeList<string>(); routePrefixDictionary = new Dictionary<Node, List<Route>>(); dataSetUp(); }
static void Main(string[] args) { Args arguments = new Args(); ICommandLineParser parser = new CommandLineParser(new CommandLineParserSettings(Console.Error)); if (parser.ParseArguments(args, arguments)) { if (arguments.HandCodedList != -1 && (arguments.InDatFile != null || arguments.InTxtFile != null || arguments.InXMLFile != null)) { Console.Out.WriteLine("Hand-coded graph is in place of loading a primary graph."); } else if (arguments.HandCodedList == -1 && arguments.InXMLFile == null && arguments.InDatFile == null && arguments.InSrcFile == null && arguments.InSrcLetterFile == null) { Console.Out.WriteLine("Must specify a primary graph, and/or a sentence source file to split."); } else if (arguments.Quiet && arguments.OutXMLFile == null && arguments.OutDatFile == null && arguments.OutTxtFile == null && arguments.OutChunkFile == null) { Console.Out.WriteLine("Quiet display and nowhere to send file output. Nothing to do."); } else if (arguments.InXMLFile != null && (arguments.InDatFile != null || arguments.InTxtFile != null)) { Console.Out.WriteLine("For primary graph, specify XML file, or both edge data file and value text file."); } else if ((arguments.InDatFile == null && arguments.InTxtFile != null) || (arguments.InDatFile != null && arguments.InTxtFile == null)) { Console.Out.WriteLine("Primary graph edge data file must be paired with a values text file."); } else if (arguments.OutXMLFile != null && (arguments.OutDatFile != null || arguments.OutTxtFile != null)) { Console.Out.WriteLine("For output file, specify XML filename, or both edge data filename and value text filename."); } else if ((arguments.OutDatFile == null && arguments.OutTxtFile != null) || (arguments.OutDatFile != null && arguments.OutDatFile == null)) { Console.Out.WriteLine("Output edge data file must be paired with a values text file."); } else if ((arguments.InSrcFile != null || arguments.InSrcLetterFile != null) && (arguments.InXMLFile2 != null || arguments.InDatFile2 != null || arguments.InTxtFile2 != null)) { Console.Out.WriteLine("Sentence source file cannot be processed simultaneously with a secondary graph."); } else if (arguments.InXMLFile2 != null && (arguments.InDatFile2 != null || arguments.InTxtFile2 != null)) { Console.Out.WriteLine("For secondary graph, specify XML filename, or both edge data filename and value text filename."); } else if ((arguments.InDatFile2 == null && arguments.InTxtFile2 != null) || (arguments.InDatFile2 != null && arguments.InTxtFile2 == null)) { Console.Out.WriteLine("Secondary graph data file must be paired with a values text file."); } else { // automatically switch on verbose graph reporting if no other output // passing delta directory parameter will produce its own output/effects if (arguments.OutDatFile == null && arguments.OutTxtFile == null && arguments.OutXMLFile == null && arguments.OutChunkFile == null && arguments.DeltaDirectory == null) { arguments.Verbose = true; } // ---- stage 1 MasterNodeList<string> firstList; MasterNodeList<string> secondList = null; bool dupeList = false; if ((arguments.InSrcFile != null || arguments.InSrcLetterFile != null) && arguments.Missing) { dupeList = true; } if (arguments.InXMLFile != null) { XMLGraphFormat<string> inXml = new XMLGraphFormat<string>(arguments.InXMLFile); inXml.nodeValueParser = new StringNodeValueParser(); firstList = inXml.ToNodeListFromFile(); if (dupeList) { secondList = inXml.ToNodeListFromFile(); } } else if (arguments.InDatFile != null && arguments.InTxtFile != null) { BinaryAndTXTFormat<string> inOth = new BinaryAndTXTFormat<string>(arguments.InDatFile, arguments.InTxtFile); inOth.nodeValueParser = new StringNodeValueParser(); firstList = inOth.ToNodeListFromFiles(); if (dupeList) { secondList = inOth.ToNodeListFromFiles(); } } else if (arguments.HandCodedList == 0) { firstList = setupNodeList33(); if (dupeList) { secondList = setupNodeList33(); } } else if (arguments.HandCodedList == 1) { firstList = setupNodeList(); if (dupeList) { secondList = setupNodeList(); } } else { firstList = new MasterNodeList<string>(); if (dupeList) { secondList = new MasterNodeList<string>(); } } // ---- stage 2 IList<NodeAndReqSpec> nodeReqSpecs = null; IList<NodeSpec> nodeSpecs = null; IList<EdgeRouteSpec> edgeSpecs = null; MasterNodeList<string> commonBaseList = null; if (arguments.BaseXMLFile != null || (arguments.BaseDatFile != null && arguments.BaseTxtFile != null)) { if (arguments.BaseXMLFile != null) { XMLGraphFormat<string> inXml3 = new XMLGraphFormat<string>(arguments.BaseXMLFile); inXml3.nodeValueParser = new StringNodeValueParser(); commonBaseList = inXml3.ToNodeListFromFile(); secondList = inXml3.ToNodeListFromFile(); } else if (arguments.BaseDatFile != null && arguments.BaseTxtFile != null) { BinaryAndTXTFormat<string> inOth3 = new BinaryAndTXTFormat<string>(arguments.BaseDatFile, arguments.BaseTxtFile); inOth3.nodeValueParser = new StringNodeValueParser(); commonBaseList = inOth3.ToNodeListFromFiles(); secondList = inOth3.ToNodeListFromFiles(); } } if (arguments.InXMLFile2 != null) { XMLGraphFormat<string> inXml2 = new XMLGraphFormat<string>(arguments.InXMLFile2); inXml2.nodeValueParser = new StringNodeValueParser(); MasterNodeList<string> tempList; if (commonBaseList != null && !arguments.ReapplyLater) { tempList = inXml2.ToNodeListFromFile(); secondList.reloadNodesThenRoutesFromSpecs(tempList.AllNodeSpecs, tempList.AllEdgeSpecs); firstList.addLaterChunksThanBaseToOtherList(commonBaseList, secondList); firstList = secondList; } else if (arguments.Chunk == -1 && !arguments.Missing && arguments.LeastChunk == -1) { tempList = inXml2.ToNodeListFromFile(); firstList.reloadNodesThenRoutesFromSpecs(tempList.AllNodeSpecs, tempList.AllEdgeSpecs); } else { secondList = inXml2.ToNodeListFromFile(); } } else if (arguments.InDatFile2 != null && arguments.InTxtFile2 != null) { BinaryAndTXTFormat<string> inOth2 = new BinaryAndTXTFormat<string>(arguments.InDatFile2, arguments.InTxtFile2); inOth2.nodeValueParser = new StringNodeValueParser(); if (commonBaseList != null && !arguments.ReapplyLater) { inOth2.ToNodeListFromFiles(secondList); firstList.addLaterChunksThanBaseToOtherList(commonBaseList, secondList); firstList = secondList; } else if (arguments.Chunk == -1 && !arguments.Missing && arguments.LeastChunk == -1 && !arguments.ReapplyLater) { inOth2.ToNodeListFromFiles(firstList); // means to merge 2nd into 1st } else { secondList = inOth2.ToNodeListFromFiles(); } } if (arguments.InSrcFile != null || arguments.InSrcLetterFile != null) { string inFileNym = (arguments.InSrcFile != null ? arguments.InSrcFile : arguments.InSrcLetterFile); loadFile(inFileNym, firstList, arguments.Quiet, arguments.InSrcLetterFile != null); } if (secondList != null && commonBaseList == null) { if (arguments.Chunk != -1) { DataChunkRoute<string> nthRoute = firstList.nthDataChunkRoute(arguments.Chunk - 1); if (arguments.OutDatFile != null || arguments.OutXMLFile == null) { nodeReqSpecs = nthRoute.comboSpecsForMissingComponents(secondList); } if (arguments.OutXMLFile != null) { var missing = nthRoute.specsForMissingComponents(secondList); nodeSpecs = missing.Item1; edgeSpecs = missing.Item2; } } else if (arguments.Missing) { if (arguments.OutDatFile != null || arguments.OutXMLFile == null) { nodeReqSpecs = firstList.getSpecsAbsentIn(secondList); } if (arguments.OutXMLFile != null) { var missing = firstList.getSegregatedSpecsAbsentIn(secondList); nodeSpecs = missing.Item1; edgeSpecs = missing.Item2; } } } else if (arguments.Chunk != -1) { secondList = new MasterNodeList<string>(); DataChunkRoute<string> nthRoute = firstList.nthDataChunkRoute(arguments.Chunk - 1); if (arguments.OutXMLFile != null) { var missing = nthRoute.specsForMissingComponents(secondList); nodeSpecs = missing.Item1; edgeSpecs = missing.Item2; } else if (arguments.OutDatFile != null && arguments.OutTxtFile != null) { nodeReqSpecs = nthRoute.comboSpecsForMissingComponents(secondList); } secondList = new MasterNodeList<string>(); } else if (arguments.LeastChunk != -1) { if (arguments.OutDatFile != null || arguments.OutXMLFile == null) { nodeReqSpecs = firstList.getRoutePartsForChunksStarting(arguments.LeastChunk - 1); } if (arguments.OutXMLFile != null) { var missing = firstList.getSegregatedRoutePartsForChunksStarting(arguments.LeastChunk - 1); nodeSpecs = missing.Item1; edgeSpecs = missing.Item2; } secondList = new MasterNodeList<string>(); } else if (arguments.ReapplyLater && commonBaseList != null) { secondList.addLaterChunksThanBaseToOtherList(commonBaseList, firstList); } else if (arguments.DeltaDirectory != null) { NodeValueParser<string> nodeValueParser = new StringNodeValueParser(); NodeValueExporter<string> nodeValueExporter = new ToStringNodeValueExporter<string>(); DeltaDirectory deltaDir = new DeltaDirectory(arguments.DeltaDirectory); DeltaRequestResultKind requestResultKind; DeltaResponseResultKind responseResultKind; MasterNodeList<string> newLocalNodeList; if (arguments.InitDeltaDirectory) { deltaDir.initDirectory(firstList, nodeValueExporter); Console.Out.WriteLine("Initialized delta directory "); } else if (arguments.MakeDeltaRequest) { DeltaRequest newReq = new DeltaRequest(deltaDir); string newFilename = deltaDir.CurrentBase + ".base"; using (TextWriter textWriter = new StreamWriter(new FileStream(newFilename, FileMode.Create))) { newReq.writeDefaultRequest(textWriter); } Console.Out.WriteLine("Wrote new delta request to " + newFilename); } else if (arguments.DeltaRequest != null) { using (TextReader textReader = new StreamReader(new FileStream(arguments.DeltaRequest, FileMode.Open, FileAccess.Read))) { MemoryStream outReq = new MemoryStream(); requestResultKind = DeltaRequestHandler.handleDeltaRequest(deltaDir, deltaDir.getLastFullGraph(nodeValueParser, nodeValueExporter), firstList, nodeValueExporter, textReader, outReq); if (requestResultKind == DeltaRequestResultKind.Deltas) { string newFilename = DateTime.Now.ToString("yyyy-MM-dd'T'HH-mm-ss'Z'") + ".tar.gz"; using (FileStream fileStream = new FileStream(newFilename, FileMode.Create)) { new MemoryStream(outReq.ToArray()).CopyTo(fileStream); } Console.Out.WriteLine("Wrote archive response to " + newFilename); } else { StreamReader resRdr = new StreamReader(new MemoryStream(outReq.ToArray())); string[] deltArr = DeltaList.readList(resRdr); if (File.Exists(deltArr[0] + ".base")) { Console.Out.WriteLine("New delta request already exists: " + deltArr[0] + ".base"); } else { using (FileStream fileStream = new FileStream(deltArr[0] + ".base", FileMode.Create)) { new MemoryStream(outReq.ToArray()).CopyTo(fileStream); } Console.Out.WriteLine("Wrote .base counter-request response " + deltArr[0] + ".base"); } } } } else if (arguments.BaseResponseToRequest != null) { using (TextReader textReader = new StreamReader(new FileStream(arguments.BaseResponseToRequest, FileMode.Open, FileAccess.Read))) { MemoryStream outReq = new MemoryStream(); responseResultKind = DeltaResponseHandler.handleDeltaBaseResponse(deltaDir, textReader, new StreamWriter(outReq)); if (responseResultKind == DeltaResponseResultKind.UpdateRequest) { StreamReader resRdr = new StreamReader(new MemoryStream(outReq.ToArray())); string[] deltArr = DeltaList.readList(resRdr); if (File.Exists(deltArr[0] + ".base")) { Console.Out.WriteLine("New delta request already exists: " + deltArr[0] + ".base"); } else { using (FileStream fileStream = new FileStream(deltArr[0] + ".base", FileMode.Create)) { new MemoryStream(outReq.ToArray()).CopyTo(fileStream); } Console.Out.WriteLine("Wrote new delta request to " + deltArr[0] + ".base"); } } else { Console.Out.WriteLine("Matching .base response indicates no new deltas. No action taken."); } } } else if (arguments.ArchiveResponseToRequest != null) { using (FileStream fs = new FileStream(arguments.ArchiveResponseToRequest, FileMode.Open, FileAccess.Read)) { responseResultKind = DeltaResponseHandler.handleDeltaArchiveResponse(firstList, deltaDir, nodeValueParser, nodeValueExporter, fs, out newLocalNodeList); if (responseResultKind == DeltaResponseResultKind.Acceptance || responseResultKind == DeltaResponseResultKind.Rewrite) { Console.Out.WriteLine("Delta archive has been loaded."); firstList = newLocalNodeList; } else { Console.Out.WriteLine("Delta archive has been ignored."); } } } } // ---- stage 3 if (arguments.Verbose && arguments.Chunk == -1 && arguments.LeastChunk == -1) { defaultTestOutput(firstList); printEnumeratedChunks(firstList); } if (arguments.Chunk != -1 && !arguments.Quiet) { printChunk(firstList.nthDataChunkRoute(arguments.Chunk - 1)); } if (arguments.LeastChunk != -1 && !arguments.Quiet) { foreach (var chRoute in firstList.chunkRoutesStartingAt(arguments.LeastChunk - 1)) { printChunk(chRoute); } } if ((arguments.Chunk != -1 || arguments.LeastChunk != -1) && arguments.Verbose && nodeReqSpecs != null) { nodeAndReqOutput(nodeReqSpecs); } if (arguments.Missing && !arguments.Quiet && nodeReqSpecs != null) { nodeAndReqOutput(nodeReqSpecs); } // ---- stage 4 if (arguments.OutXMLFile != null) { XMLGraphFormat<string> outX = new XMLGraphFormat<string>(arguments.OutXMLFile); if (nodeSpecs != null) { outX.ToXMLFile(secondList, nodeSpecs, edgeSpecs); } else { outX.ToXMLFile(firstList); } } if (arguments.OutDatFile != null && arguments.OutTxtFile != null) { BinaryAndTXTFormat<string> outOth = new BinaryAndTXTFormat<string>(arguments.OutDatFile, arguments.OutTxtFile); if (nodeReqSpecs != null) { outOth.ToBinaryAndTXTFiles(firstList, secondList, nodeReqSpecs); } else { outOth.ToBinaryAndTXTFiles(firstList); } } if (arguments.OutChunkFile != null) { IEnumerable<IEnumerable<string>> dumpChunks = Enumerable.Empty<IEnumerable<string>>(); if (arguments.Chunk != -1) { DataChunkRoute<string> dumpedChunk = firstList.nthDataChunkRoute(arguments.Chunk - 1); dumpChunks = new List<IEnumerable<string>>() { dumpedChunk.dataChunk }; } else if (arguments.LeastChunk != -1) { dumpChunks = firstList.chunkRoutesStartingAt(arguments.LeastChunk - 1) .Select(chRoute => chRoute.dataChunk); } else if (arguments.Missing) { dumpChunks = firstList.dataChunksLaterThan(secondList); } using (TextWriter textWriter = new StreamWriter(new FileStream(arguments.OutChunkFile, FileMode.Create))) { foreach (var dumpChunk in dumpChunks) { foreach (var dumpVal in dumpChunk) { textWriter.Write(dumpVal + " "); } textWriter.WriteLine("."); } } } } } }
static MasterNodeList<string> setupNodeList33() { MasterNodeList<string> masterNodeList = new MasterNodeList<string>(); Dictionary<Node, List<Route>> routePrefixDictionary = new Dictionary<Node, List<Route>>(); threeThreeRoutes(masterNodeList, routePrefixDictionary); return masterNodeList; }
static void printEnumeratedChunks(MasterNodeList<string> masterNodeList) { Console.Out.WriteLine(); Console.Out.WriteLine("------ Chunks in graph: "); var ind = 1; foreach (DataChunkRoute<string> route in masterNodeList.enumerateDataChunkRoutes()) { Console.Out.Write("#" + ind + ": "); printChunk(route); ind++; } }
public void testEmptyNodeList() { MasterNodeList<int> nodeList = new MasterNodeList<int>(); XmlDocument emptyDoc = new XMLGraphFormat<int>().ToXMLDocument(nodeList); Assert.AreEqual(XMLGraphFormat<int>.ROOTELEM, emptyDoc.DocumentElement.LocalName); }
public void threeSix() { MasterNodeList<string> nodeList = new MasterNodeList<string>(); Dictionary<Node, List<Route>> prefixD = new Dictionary<Node, List<Route>>(); DataChunkRouteBlazerTest.threeSixChunks(nodeList, prefixD); XmlDocument threeSixDoc = new XMLGraphFormat<string>().ToXMLDocument(nodeList); XmlNode nodesElement = threeSixDoc.DocumentElement.ChildNodes[0]; Assert.AreEqual(XMLGraphFormat<int>.NODESROOTELEM, nodesElement.LocalName); XmlNodeList nodeElements = nodesElement.ChildNodes; XmlNode firstStartNode = nodeElements[0]; Assert.AreEqual(XMLGraphFormat<int>.NODEELEM, firstStartNode.LocalName); Assert.AreEqual("0", firstStartNode.Attributes[XMLGraphFormat<int>.SEQNUMATTR].Value); Assert.AreEqual(NodeKind.GateNode.ToString(), firstStartNode.Attributes[XMLGraphFormat<int>.NODEKINDATTR].Value); XmlNode firstValueNode = nodeElements[3]; Assert.AreEqual("3", firstValueNode.Attributes[XMLGraphFormat<int>.SEQNUMATTR].Value); Assert.AreEqual(NodeKind.ValueNode.ToString(), firstValueNode.Attributes[XMLGraphFormat<int>.NODEKINDATTR].Value); Assert.AreEqual("A", firstValueNode.InnerText); XmlNode edgesElement = threeSixDoc.DocumentElement.ChildNodes[1]; Assert.AreEqual(XMLGraphFormat<int>.EDGESROOTELEM, edgesElement.LocalName); XmlNodeList edgeElements = edgesElement.ChildNodes; XmlNode firstEdge = edgeElements[0]; Assert.AreEqual(XMLGraphFormat<int>.EDGEELEM, firstEdge.LocalName); Assert.AreEqual("0", firstEdge.Attributes[XMLGraphFormat<int>.FROMATTR].Value); Assert.AreEqual("3", firstEdge.Attributes[XMLGraphFormat<int>.TOATTR].Value); Assert.AreEqual("-1,-1", firstEdge.Attributes[XMLGraphFormat<int>.REQATTR].Value); }
public void reuseNodeValueByRef() { MasterNodeList<string> nodeList = new MasterNodeList<string>(); Dictionary<Node, List<Route>> prefixD = new Dictionary<Node, List<Route>>(); DataChunkRouteBlazerTest.threeThreeChunks(nodeList, prefixD); XmlDocument threeThreeDoc = new XMLGraphFormat<string>().ToXMLDocument(nodeList); XmlNode nodesElement = threeThreeDoc.DocumentElement.ChildNodes[0]; XmlNodeList nodeElements = nodesElement.ChildNodes; int firstAIndex = nodeList.getValueNodesByValue("A").ElementAt(0).SequenceNumber; int secondAIndex = nodeList.getValueNodesByValue("A").ElementAt(1).SequenceNumber; XmlNode secondAXmlElem = nodeElements[secondAIndex]; Assert.AreEqual(firstAIndex.ToString(), secondAXmlElem.Attributes[XMLGraphFormat<ushort>.VALUEREFATTR].Value); Assert.AreEqual("", secondAXmlElem.InnerText); MasterNodeList<string> destinationList = new MasterNodeList<string>(); Dictionary<Node, List<Route>> destinationDict = new Dictionary<Node, List<Route>>(); DataChunkRoute<string> firstRoute = nodeList.nthDataChunkRoute(0); var missingComponents = firstRoute.specsForMissingComponents(destinationList); Assert.AreEqual(4, missingComponents.Item1.Count); Assert.AreEqual(3, missingComponents.Item2.Count); destinationList.reloadNodesThenRoutesFromSpecs(missingComponents.Item1, missingComponents.Item2); DataChunkRoute<string> secondRoute = nodeList.nthDataChunkRoute(1); Assert.AreEqual(3,secondRoute.componentEdges.Count); Assert.AreEqual(1, secondRoute.componentEdges[0].edge.link.from.SequenceNumber); Assert.AreEqual(3, secondRoute.componentEdges[1].edge.link.from.SequenceNumber); Assert.AreEqual(6, secondRoute.componentEdges[2].edge.link.from.SequenceNumber); Assert.AreEqual(7, secondRoute.componentEdges[2].edge.link.to.SequenceNumber); foreach(EdgeRoute rt in secondRoute.componentEdges) { Assert.AreNotEqual(0, rt.edge.link.from.SequenceNumber); Assert.AreNotEqual(0, rt.edge.link.to.SequenceNumber); } var secondMissingComponents = secondRoute.specsForMissingComponents(destinationList); var secondMissingNodeSpecs = secondMissingComponents.Item1; Assert.AreEqual(3, secondMissingNodeSpecs.Count); var secondMissingEdgeSpecs = secondMissingComponents.Item2; XmlDocument secondMissingDoc = new XMLGraphFormat<string>().ToXMLDocument(destinationList, secondMissingNodeSpecs, secondMissingEdgeSpecs); Assert.AreEqual(2, secondMissingDoc.DocumentElement.ChildNodes.Count); nodesElement = secondMissingDoc.DocumentElement.ChildNodes[0]; nodeElements = nodesElement.ChildNodes; Assert.AreEqual(3, nodeElements.Count); Assert.AreEqual(NodeKind.GateNode.ToString(), nodeElements[0].Attributes[XMLGraphFormat<bool>.NODEKINDATTR].Value); Assert.AreEqual(NodeKind.ValueNode.ToString(), nodeElements[1].Attributes[XMLGraphFormat<bool>.NODEKINDATTR].Value); XmlNode AXmlElem = nodeElements[1]; Assert.AreEqual(6, Convert.ToInt32(AXmlElem.Attributes[XMLGraphFormat<bool>.SEQNUMATTR].Value)); Assert.AreEqual("", AXmlElem.InnerText); Assert.AreEqual(firstAIndex.ToString(), AXmlElem.Attributes[XMLGraphFormat<long>.VALUEREFATTR].Value); DataChunkRouteBlazer<string> blaz = new DataChunkRouteBlazer<string>(new List<string> { "G", "G", "G" }, nodeList); blaz.computeFullRoute(); DataChunkRoute<string> GGG = nodeList.nthDataChunkRoute(3); secondMissingComponents = GGG.specsForMissingComponents(destinationList); secondMissingNodeSpecs = secondMissingComponents.Item1; Assert.AreEqual(4, secondMissingNodeSpecs.Count); secondMissingDoc = new XMLGraphFormat<string>().ToXMLDocument(destinationList, secondMissingNodeSpecs, secondMissingEdgeSpecs); nodesElement = secondMissingDoc.DocumentElement.ChildNodes[0]; nodeElements = nodesElement.ChildNodes; XmlNode G2Elem = nodeElements[2]; Assert.AreEqual(NodeKind.ValueNode.ToString(), G2Elem.Attributes[XMLGraphFormat<bool>.NODEKINDATTR].Value); Assert.AreEqual("", G2Elem.InnerText); Assert.IsNotNull(G2Elem.Attributes[XMLGraphFormat<bool>.VALUEREFATTR]); }
static void threeSixRoutes(MasterNodeList<string> masterNodeList, Dictionary<Node, List<Route>> routePrefixDictionary) { List<string> srcData4List = new List<string>() { "A", "B", "C", "D", "E", "F" }; DataChunkRouteBlazer<string> chunkRoute4 = new DataChunkRouteBlazer<string>(srcData4List, masterNodeList); chunkRoute4.computeFullRoute(); List<string> srcData5List = new List<string>() { "G", "B", "C", "D", "J", "K" }; DataChunkRouteBlazer<string> chunkRoute5 = new DataChunkRouteBlazer<string>(srcData5List, masterNodeList); chunkRoute5.computeFullRoute(); List<string> srcData6List = new List<string>() { "G", "B", "D", "M", "N", "O" }; DataChunkRouteBlazer<string> chunkRoute6 = new DataChunkRouteBlazer<string>(srcData6List, masterNodeList); chunkRoute6.computeFullRoute(); }
static void threeThreeRoutes(MasterNodeList<string> masterNodeList, Dictionary<Node, List<Route>> routePrefixDictionary) { List<string> srcDataList = new List<string>() { "A", "B", "C" }; List<string> srcData2List = new List<string>() { "A", "A", "D" }; List<string> srcData3List = new List<string>() { "A", "A", "E" }; DataChunkRouteBlazer<string> chunkRoute = new DataChunkRouteBlazer<string>(srcDataList, masterNodeList); DataChunkRouteBlazer<string> chunkRoute2 = new DataChunkRouteBlazer<string>(srcData2List, masterNodeList); DataChunkRouteBlazer<string> chunkRoute3 = new DataChunkRouteBlazer<string>(srcData3List, masterNodeList); chunkRoute.computeFullRoute(); chunkRoute2.computeFullRoute(); chunkRoute3.computeFullRoute(); }
public void findMissingRouteComponents() { setup13append(); MasterNodeList<string> destinationList = new MasterNodeList<string>(); Dictionary<Node,List<Route>> destinationDict = new Dictionary<Node, List<Route>>(); DataChunkRoute<string> ABC = list.nthDataChunkRoute(0); Tuple<IList<NodeSpec>, IList<EdgeRouteSpec>> missingComponents = ABC.specsForMissingComponents(destinationList); IEnumerable<NodeSpec> missingNodes = missingComponents.Item1; IEnumerable<EdgeRouteSpec> missingEdges = missingComponents.Item2; NodeSpec missingGate = missingNodes.First(node => node.kind == NodeKind.GateNode); Assert.AreEqual(1, missingNodes.Where(node => node.kind == NodeKind.GateNode).Count()); Assert.AreEqual(0, missingGate.SequenceNumber); NodeSpec newValueSpec = missingNodes.First(node => node.kind == NodeKind.ValueNode); Assert.AreEqual(6, newValueSpec.SequenceNumber); Assert.AreEqual(3, missingNodes.Where(node => node.kind == NodeKind.ValueNode).Count()); Assert.AreEqual(1, missingEdges.Where(edge => edge.FromNumber == missingGate.SequenceNumber).Count()); destinationList.reloadNodesThenRoutesFromSpecs(missingNodes, missingEdges); ValueNode<string> Anode = destinationList.getValueNodesByValue("A").First(); Assert.AreEqual("A", Anode.Value); Assert.AreEqual(6, Anode.SequenceNumber); DataChunkRoute<string> AAE = list.nthDataChunkRoute(2); missingComponents = AAE.specsForMissingComponents(destinationList); missingNodes = missingComponents.Item1; missingEdges = missingComponents.Item2; destinationList.reloadNodesThenRoutesFromSpecs(missingNodes, missingEdges); Assert.AreEqual(2, destinationList.getValueNodesByValue("A").Count()); int DnodeIndex = list.getValueNodesByValue("D").First().SequenceNumber; Assert.AreEqual(NodeKind.NullNode,destinationList.nodeByNumber(DnodeIndex).kind); }
public void SetUp() { list = new MasterNodeList<string>(); list.newValueNodeFromValue("A"); list.newValueNodeFromValue("B"); }
private MasterNodeList<string> threeSixNodeList() { MasterNodeList<string> nodeList = new MasterNodeList<string>(); DataChunkRouteBlazerTest.threeSixChunks(nodeList, new Dictionary<Node, List<Route>>()); return nodeList; }
public void SetUp() { list = new MasterNodeList<string>(); nodeA = list.newValueNodeFromValue("A"); nodeB = list.newValueNodeFromValue("B"); nodeC = list.newValueNodeFromValue("C"); nodeD = list.newValueNodeFromValue("D"); nodeD2 = list.newValueNodeFromValue("D"); nodeD3 = list.newValueNodeFromValue("D"); routeFactory = new RouteFactory<string>(); edgeAB = new Edge() { link = new DirectedPair() { from = nodeA, to = nodeB } }; edgeBC = new Edge() { link = new DirectedPair() { from = nodeB, to = nodeC } }; edgeCD = new Edge() { link = new DirectedPair() { from = nodeC, to = nodeD }, requisiteLink = new DirectedPair() { from = nodeA, to = nodeB } }; edgeBD = new Edge() { link = new DirectedPair() { from = nodeB, to = nodeD }, requisiteLink = new DirectedPair() { from = nodeA, to = nodeB } }; edgeBD2 = new Edge() { link = new DirectedPair() { from = nodeB, to = nodeD2 }, requisiteLink = new DirectedPair() { from = nodeC, to = nodeB } }; edgeCB = new Edge() { link = new DirectedPair() { from = nodeC, to = nodeB } }; routeCB = routeFactory.newRouteFromEdge(edgeCB); routeAB = routeFactory.newRouteFromEdge(edgeAB); routeBC = routeFactory.newRouteFromEdge(edgeBC); routeCD = routeFactory.newRouteFromEdge(edgeCD); routeBD = routeFactory.newRouteFromEdge(edgeBD); routeBD2 = routeFactory.newRouteFromEdge(edgeBD2); routeABC = routeFactory.newRouteFromConnectedRoutes(routeAB, routeBC); routeABCD = routeFactory.newRouteFromConnectedRoutes(routeABC, routeCD); }