/// <summary> /// Validate general segmented sequences methods /// Add,Clear,replace,copyTo,Remove,Contains,Range, /// Insert,IndexOf,Replace,RemoveAt,InsertRange,ReplaceRange. /// <param name="nodeName">xml node name.</param /// <param name="methodName">Method Name</param> /// </summary> void ValidateGeneralMethodsOfSegmentedSequence( string nodeName, SegmentedSequenceParameters methodName) { // Gets the alphabet from the Xml string alphabet = _utilityObj._xmlUtil.GetTextValue( nodeName, Constants.AlphabetNameNode); string expectedSegSeqCount = _utilityObj._xmlUtil.GetTextValue( nodeName, Constants.SegmetedSeqCount); string inputSequence1 = _utilityObj._xmlUtil.GetTextValue( nodeName, Constants.Sequence1); string expectedSegmentedSeqAfterAddingNucleotide = _utilityObj._xmlUtil.GetTextValue( nodeName, Constants.ExpectedSeqAfterAdd); string expectedSegmentedSeqCountAfterAddingNucleotide = _utilityObj._xmlUtil.GetTextValue( nodeName, Constants.ExpectedSequenceCountAfterSeqAdd); string expectedIndexValue = _utilityObj._xmlUtil.GetTextValue( nodeName, Constants.ExpectedIndexValue); string insertSeq = _utilityObj._xmlUtil.GetTextValue( nodeName, Constants.InsertSeq); string expectedInsertSeq = _utilityObj._xmlUtil.GetTextValue( nodeName, Constants.ExpectedInsertSeq); string expectedRangeSeq = _utilityObj._xmlUtil.GetTextValue( nodeName, Constants.RangeSeq); string expectedSeqAfterRemoveSeqItem = _utilityObj._xmlUtil.GetTextValue( nodeName, Constants.SequenceAfterRemove); string expectedSeqAfterRemoveSeq = _utilityObj._xmlUtil.GetTextValue( nodeName, Constants.SeqAfterRemoveSeqRange); string expectedSeqAfterReplace = _utilityObj._xmlUtil.GetTextValue( nodeName, Constants.SequenceAfterReplace); string expectedSeqAfterReplaceSeqRange = _utilityObj._xmlUtil.GetTextValue( nodeName, Constants.SequenceAfterReplaceRange); int index = 0; int j = 1; string expectedSeqAfterInsert = inputSequence1[0] + inputSequence1; Sequence seq = null; SegmentedSequence segmentedSeq = null; // create a Isequence. seq = new Sequence(Utility.GetAlphabet(alphabet), inputSequence1); seq.IsReadOnly = false; // create a Segmented seqeunce segmentedSeq = new SegmentedSequence(seq); Assert.AreEqual(seq.ToString(), segmentedSeq.ToString()); switch (methodName) { case SegmentedSequenceParameters.Add: // Add all sequence items to the end of the sequence. foreach (ISequenceItem item in Utility.GetAlphabet(alphabet)) { segmentedSeq.Add(item); } // validate segmented sequence after adding sequence item. Assert.AreEqual(segmentedSeq.ToString(), expectedSegmentedSeqAfterAddingNucleotide); Assert.AreEqual(segmentedSeq.Count.ToString((IFormatProvider)null), expectedSegmentedSeqCountAfterAddingNucleotide); break; case SegmentedSequenceParameters.Clear: // Clear all sequence items in segmented sequence. segmentedSeq.Clear(); // validate segmented sequence after adding sequence item. Assert.IsTrue(string.IsNullOrEmpty(segmentedSeq.ToString())); break; case SegmentedSequenceParameters.CopyTo: // Copy sequence items to array. ISequenceItem[] iseqItems = new ISequenceItem[895990]; segmentedSeq.CopyTo(iseqItems, index); Assert.IsNotNull(iseqItems); // Validate array. foreach (ISequenceItem item in Utility.GetAlphabet(alphabet)) { Assert.AreEqual(iseqItems[index], segmentedSeq[index]); Assert.AreEqual(iseqItems[index], segmentedSeq[index]); Assert.AreEqual(iseqItems[index].Symbol, segmentedSeq[index].Symbol); index++; } break; case SegmentedSequenceParameters.Remove: //Remove sequence items in segmented sequence. foreach (ISequenceItem item in segmentedSeq) { segmentedSeq.Remove(segmentedSeq[index]); Assert.AreEqual(segmentedSeq.Count, Convert.ToInt32(expectedSegSeqCount, (IFormatProvider)null) - j); j++; index++; Console.WriteLine(string.Format((IFormatProvider)null, "Segmented Sequence P1: Segmented Sequence{0} is as expected.", segmentedSeq.ToString())); } break; case SegmentedSequenceParameters.Contains: //Validate wheather sequence item present in the segmented sequence foreach (ISequenceItem item in seq) { bool seqItemPresent = segmentedSeq.Contains(seq[index]); Assert.IsTrue(seqItemPresent); index++; } break; case SegmentedSequenceParameters.GetEnumerator: //Get enumerator of the segmented sequence. IEnumerator <ISequenceItem> segSeqEnumerator = segmentedSeq.GetEnumerator(); Assert.IsNotNull(segSeqEnumerator); break; case SegmentedSequenceParameters.IndexOf: // Validate index of seg sequence items. int indexValue = segmentedSeq.IndexOf(seq[6]); Assert.AreEqual(indexValue, Convert.ToInt32(expectedIndexValue, (IFormatProvider)null)); break; case SegmentedSequenceParameters.InsertChar: // Validate insertion of sequence items in segmeted sequence. segmentedSeq.Insert(0, inputSequence1[0]); Assert.AreEqual(segmentedSeq.ToString(), expectedSeqAfterInsert); Assert.AreEqual(segmentedSeq.Count, Convert.ToInt32(expectedSegSeqCount, (IFormatProvider)null) + 1); break; case SegmentedSequenceParameters.InsertRange: // Validate insertion of sequence items in segmeted sequence. segmentedSeq.InsertRange(10, insertSeq); Assert.AreEqual(segmentedSeq.ToString(), expectedInsertSeq); Assert.AreEqual(segmentedSeq.Count, Convert.ToInt32(expectedSegSeqCount, (IFormatProvider)null) + insertSeq.Length); break; case SegmentedSequenceParameters.Range: // Validate range of segmented sequence. ISequence rangeSeq = segmentedSeq.Range(20, 20); Assert.AreEqual(rangeSeq.ToString(), expectedRangeSeq); break; case SegmentedSequenceParameters.RemoveAt: // Validate range of segmented sequence. segmentedSeq.RemoveAt(70); Assert.AreEqual(segmentedSeq.ToString(), expectedSeqAfterRemoveSeqItem); break; case SegmentedSequenceParameters.RemoveRange: // Validate range of segmented sequence. segmentedSeq.RemoveRange(0, 10); Assert.AreEqual(segmentedSeq.ToString(), expectedSeqAfterRemoveSeq); break; case SegmentedSequenceParameters.ToString: // Validate Tostring. Assert.AreEqual(segmentedSeq.ToString(), inputSequence1); break; case SegmentedSequenceParameters.ReplaceChar: // Validate replacement of sequence items in segmeted sequence. segmentedSeq.Replace(15, inputSequence1[0]); Assert.AreEqual(segmentedSeq.ToString(), expectedSeqAfterReplace); break; case SegmentedSequenceParameters.ReplaceRange: // Validate replacement of sequence items in segmeted sequence. segmentedSeq.ReplaceRange(0, insertSeq); Assert.AreEqual(segmentedSeq.ToString(), expectedSeqAfterReplaceSeqRange); break; default: break; } Console.WriteLine(string.Format((IFormatProvider)null, "Segmented Sequence P1: Segmented Sequence{0} is as expected.", segmentedSeq.ToString())); Console.WriteLine(string.Format((IFormatProvider)null, "Segmented Sequence P1: Segmented Sequence count{0} is as expected.", segmentedSeq.Count.ToString((IFormatProvider)null))); }
/// <summary> /// General method to validate creation of Segmented seqeunce. /// <param name="nodeName">xml node name.</param> /// <param name="methodName">Method Name</param> /// </summary> void ValidateSegmentedSequenceCreation( string nodeName, SegmentedSequenceParameters methodName, bool IsCloneMethod) { // Gets the alphabet from the Xml string alphabet = _utilityObj._xmlUtil.GetTextValue( nodeName, Constants.AlphabetNameNode); string expectedSegmentedSeq = _utilityObj._xmlUtil.GetTextValue( nodeName, Constants.ExpectedSequence); string inputSequence1 = _utilityObj._xmlUtil.GetTextValue( nodeName, Constants.Sequence1); string inputSequence2 = _utilityObj._xmlUtil.GetTextValue( nodeName, Constants.Sequence2); string inputSequence3 = _utilityObj._xmlUtil.GetTextValue( nodeName, Constants.Sequence3); string inputSequence4 = _utilityObj._xmlUtil.GetTextValue( nodeName, Constants.Sequence4); string expectedSegSeqCount = _utilityObj._xmlUtil.GetTextValue( nodeName, Constants.SegmetedSeqCount); string expectedSeguencesCount = _utilityObj._xmlUtil.GetTextValue( nodeName, Constants.SequencesCount); ISequence seq = null; List <ISequence> seqList = new List <ISequence>(); SegmentedSequence segmentedSeq = null; ISequence segSeq = null; // Logs information to the log file ApplicationLog.WriteLine(string.Format((IFormatProvider)null, "Segmented Sequence P1: Sequence {0} is expected.", alphabet)); switch (methodName) { case SegmentedSequenceParameters.SegmentedSeqList: // create a Isequence. ISequence seq1 = new Sequence(Utility.GetAlphabet(alphabet), inputSequence1); ISequence seq2 = new Sequence(Utility.GetAlphabet(alphabet), inputSequence2); ISequence seq3 = new Sequence(Utility.GetAlphabet(alphabet), inputSequence3); ISequence seq4 = new Sequence(Utility.GetAlphabet(alphabet), inputSequence4); // Add all sequences to sequence list. seqList.Add(seq1); seqList.Add(seq2); seqList.Add(seq3); seqList.Add(seq4); // create a Segmented seqeunce with sequence list. segmentedSeq = new SegmentedSequence(seqList); // validate created segmented sequence list. Assert.AreEqual(expectedSegmentedSeq, segmentedSeq.ToString()); Assert.AreSame(seq1, segmentedSeq.Sequences[0]); Assert.AreSame(seq2, segmentedSeq.Sequences[1]); Assert.AreSame(seq3, segmentedSeq.Sequences[2]); Assert.AreSame(seq4, segmentedSeq.Sequences[3]); Console.WriteLine(string.Format((IFormatProvider)null, "Segmented Sequence P1: Segmented Sequence{0} is as expected.", segmentedSeq.ToString())); break; case SegmentedSequenceParameters.SegmentedSeq: // create a Isequence. seq = new Sequence(Utility.GetAlphabet(alphabet), inputSequence1); // create a Segmented seqeunce segmentedSeq = new SegmentedSequence(seq); // validate expected segmented sequence. Assert.AreEqual(seq.ToString(), segmentedSeq.ToString()); Console.WriteLine(string.Format((IFormatProvider)null, "Segmented Sequence P1: Segmented Sequence{0} is as expected.", segmentedSeq.ToString())); break; case SegmentedSequenceParameters.Clone: // create a Isequence. seq = new Sequence(Utility.GetAlphabet(alphabet), inputSequence1); segSeq = new SegmentedSequence(seq); ICloneable cloneableSegSeq = new SegmentedSequence(seq); // Create a copy of segmented sequence and validate. ISequence cloneSeq = segSeq.Clone(); object iCloneSegSeq = cloneableSegSeq.Clone(); Assert.AreEqual(cloneSeq.ToString(), segSeq.ToString()); Assert.AreEqual(iCloneSegSeq.ToString(), segSeq.ToString()); Console.WriteLine(string.Format((IFormatProvider)null, "Segmented Sequence P1: Segmented Sequence{0} is as expected.", cloneSeq.ToString())); break; default: break; } if (!IsCloneMethod) { // Validate the created segmented Sequence Assert.AreEqual(segmentedSeq.Count.ToString((IFormatProvider)null), expectedSegSeqCount); Assert.AreEqual(segmentedSeq.Sequences.Count.ToString((IFormatProvider)null), expectedSeguencesCount); Assert.AreSame(Utility.GetAlphabet(alphabet), segmentedSeq.Alphabet); // Logs to the NUnit GUI (Console.Out) window Console.WriteLine(string.Format((IFormatProvider)null, "Segmented Sequence P1: Segmented Sequence count{0} is as expected.", segmentedSeq.Sequences.Count.ToString((IFormatProvider)null))); Console.WriteLine(string.Format((IFormatProvider)null, "Segmented Sequence P1: Segmented Sequences count{0} is as expected.", segmentedSeq.Count.ToString((IFormatProvider)null))); // Logs to the NUnit GUI (Console.Out) window ApplicationLog.WriteLine( "Segmented Sequence P1: Segmented Sequence validation is completed successfully."); } }