コード例 #1
0
ファイル: WiggleBvtTestCases.cs プロジェクト: cpatmoore/bio
        /// <summary>
        /// Validate Wiggle Formatter for fixed and variable steps.
        /// </summary>
        /// <param name="nodeName">Nodename</param>
        /// <param name="formatType">Write using a stream/File Name.</param>
        private void ValidateWiggleFormatter(string nodeName, FormatType formatType)
        {
            // Gets the filepath.
            String filePath = this.utilityObj.xmlUtil.GetTextValue(nodeName, Constants.FilePathNode);
            Assert.IsTrue(File.Exists(filePath));
            WiggleAnnotation annotation = null, annotationNew = null;

            string[] expectedValues = this.utilityObj.xmlUtil.GetTextValue(nodeName,
                                     Constants.ExpectedValuesNode).Split(',');
            string[] expectedPoints = this.utilityObj.xmlUtil.GetTextValue(nodeName,
                                     Constants.ExpectedKeysNode).Split(',');

            //Parse the file.
            WiggleParser parser = new WiggleParser();
            annotation = parser.ParseOne(filePath);

            WiggleFormatter formatter = null;

            //Write to a new file.                    
            switch (formatType)
            {
                case FormatType.Stream:
                    using (var writer = File.Create(Constants.WiggleTempFileName))
                    {
                        formatter = new WiggleFormatter();
                        formatter.Format(writer, annotation);
                        formatter.Close();
                    }
                    break;
                default:
                    formatter = new WiggleFormatter();
                    formatter.Format(annotation, Constants.WiggleTempFileName);
                    formatter.Close();
                    break;
            }

            //Read the new file and then compare the annotations.
            WiggleParser parserNew = new WiggleParser();
            annotationNew = parserNew.ParseOne(Constants.WiggleTempFileName);
            int index = 0;

            //Validate keys and values of the parsed file.
            foreach (KeyValuePair<long, float> keyvaluePair in annotationNew)
            {
                Assert.AreEqual(long.Parse(expectedPoints[index],
                            CultureInfo.InvariantCulture), keyvaluePair.Key);
                Assert.AreEqual(float.Parse(expectedValues[index],
                            CultureInfo.InvariantCulture), keyvaluePair.Value);
                index++;
            }
            File.Delete(Constants.WiggleTempFileName);
            ApplicationLog.WriteLine(string.Format((IFormatProvider)null,
               "Wiggle Formatter BVT: Successfully validated the written file"));
        }