/// <summary>
 /// Markov algorithm performs
 /// </summary>
 /// <returns></returns>
 public MyString DoingAlgorithm()
 {
     int i = 0;
     int countPerformedSubstitutions = 0;
     MyString resultLine = new MyString(line);
     while(i < substitutions.Count)
     {
         if(resultLine.Find(substitutions[i].Key) != -1)
         {
             resultLine = resultLine.Replace(substitutions[i].Key, substitutions[i].Value);
             i = 0;
             if (countPerformedSubstitutions < N)
             {
                 countPerformedSubstitutions++;
             }
             else
             {
                 throw new InvalidOperationException("Substitutions performed too long.");
             }
         }
         else
         {
             i++;
         }
     }
     return resultLine;
 }
Пример #2
0
 public void TestMethodReplace3()
 {
     MyString a = new MyString();
     MyString b = new MyString();
     MyString c = new MyString();
     a.GetLine("inA.txt");
     b.GetLine("inD.txt");
     c.GetLine("inG.txt");
     Assert.AreEqual(a.Replace(b, c).ToString(), "qwer-2-103");
 }