/// <summary> /// Phylogenetic Tree Formatter General Tests /// </summary> /// <param name="nodeName">Xml node Name.</param> /// <param name="formatParam">Additional parameter</param> void PhylogeneticTreeFormatterGeneralTests(string nodeName, FormatterParameters formatParam) { // Gets the expected sequence from the Xml string filePath = string.Empty; NewickParser parser = new NewickParser(); { Tree rootTree; switch (formatParam) { case FormatterParameters.Object: rootTree = GetFormattedObject(); break; default: filePath = _utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FilePathNode); Assert.IsTrue(File.Exists(filePath)); // Logs information to the log file ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Phylogenetic Tree Parser BVT: File Exists in the Path '{0}'.", filePath)); rootTree = parser.Parse(filePath); break; } string outputFilepath = _utilityObj.xmlUtil.GetTextValue(nodeName, Constants.OutputFilePathNode); NewickFormatter format = new NewickFormatter(); switch (formatParam) { case FormatterParameters.Stream: using (var writer = File.Create(outputFilepath)) { format.Format(writer, rootTree); } break; case FormatterParameters.FormatString: // Validate format String var formatString = format.FormatString(rootTree); string expectedFormatString = _utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FormatStringNode); Assert.AreEqual(expectedFormatString, formatString); ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Phylogenetic Tree Parser BVT: Format string '{0}' is as expected.", formatString)); break; default: format.Format(rootTree, outputFilepath); break; } // Validate only if not a Format String if (FormatterParameters.FormatString != formatParam) { // Re-parse the created file and validate the tree. NewickParser newparserObj = new NewickParser(); { Tree newrootTreeObj = null; Assert.IsTrue(File.Exists(outputFilepath)); // Logs information to the log file ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Phylogenetic Tree Parser BVT: New File Exists in the Path '{0}'.", outputFilepath)); newrootTreeObj = newparserObj.Parse(outputFilepath); Node rootNode = newrootTreeObj.Root; string rootBranchCount = _utilityObj.xmlUtil.GetTextValue(nodeName, Constants.RootBranchCountNode); // Validate the root branch count Assert.AreEqual(rootBranchCount, rootNode.Children.Count.ToString((IFormatProvider)null)); ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Phylogenetic Tree Parser BVT: Number of Root Branches found are '{0}'.", rootNode.Children.Count.ToString((IFormatProvider)null))); List<string> leavesName = new List<string>(); List<double> leavesDistance = new List<double>(); // Gets all the leaves in the root node list GetAllNodesAndEdges(rootNode, ref leavesName, ref leavesDistance); string[] expectedLeavesName = _utilityObj.xmlUtil.GetTextValue(nodeName, Constants.NodeNamesNode).Split(','); string[] expectedLeavesDistance = _utilityObj.xmlUtil.GetTextValue(nodeName, Constants.EdgeDistancesNode).Split(','); for (int i = 0; i < expectedLeavesName.Length; i++) { Assert.AreEqual(expectedLeavesName[i], leavesName[i]); } for (int i = 0; i < expectedLeavesDistance.Length; i++) { Assert.AreEqual(expectedLeavesDistance[i], leavesDistance[i].ToString((IFormatProvider)null)); } } ApplicationLog.WriteLine( "Phylogenetic Tree Parser BVT: The Node Names and Distance are as expected."); } if (File.Exists(outputFilepath)) File.Delete(outputFilepath); } }
public void PhylogeneticTreeP1FormatterValidateAllProperties() { NewickFormatter formatter = new NewickFormatter(); string name = formatter.Name; string fileTypes = formatter.SupportedFileTypes; string description = formatter.Description; Assert.AreEqual(Constants.ParserName, name); Assert.AreEqual(Constants.ParserFileTypes, fileTypes); Assert.AreEqual(Constants.FormatDescription, description); ApplicationLog.WriteLine( "Phylogenetic Tree Formatter P1: Validated all properties in Formatter class."); }