Beispiel #1
0
 public void TestMethod1()
 {
     PatternFinder pf = new PatternFinder(new string[] { "a", "ab", "bab", "bc", "bca", "c", "caa" });
     ISearchResult[] results = pf.FindAll("abccab");
     Assert.IsTrue(results.Length == 7);
     Assert.IsTrue(results[0].Index == 0);
     Assert.IsTrue(results[1].Index == 0);
     Assert.IsTrue(results[1].GetValue() == "ab");
     Assert.IsTrue(results[2].Index == 1);
     Assert.IsTrue(results[3].Index == 2);
 }
Beispiel #2
0
        public void FindAll()
        {
            string target = "CADACADACAABRABRADARCCADAADRCADA";
            PatternFinder finder = new PatternFinder("CADA", SearchOptions.Raita);
            var maches = finder.FindAll(target);

            Assert.IsTrue(maches.Length == 4);
            Assert.IsTrue(maches[0].Index == 0);
            Assert.IsTrue(maches[1].Index == 4);
            Assert.IsTrue(maches[2].Index == 21);
            Assert.IsTrue(maches[3].Index == 28);
        }
Beispiel #3
0
 public void OnlyOneMatchAttheEnd()
 {
     string target = "CAABRABRADARCADRCADA";
     PatternFinder finder = new PatternFinder("CADA", SearchOptions.Raita);
     var result = finder.Find(target);
     //
     Assert.IsTrue(result.IsMatch);
     Assert.IsTrue(result.Index == 16);
     while (result.IsMatch)
     {
         result = result.Next();
         Assert.IsFalse(result.IsMatch);
     }
 }
Beispiel #4
0
 public void OnlyOneMatchAtTheMiddle()
 {
     string target = "CAABRABRADARCCADAADR";
     PatternFinder finder = new PatternFinder("CADA", SearchOptions.TunedBM);
     var result = finder.Find(target);
     //
     Assert.IsTrue(result.IsMatch);
     Assert.IsTrue(result.Index == 13);
     while (result.IsMatch)
     {
         result = result.Next();
         Assert.IsFalse(result.IsMatch);
     }
 }
Beispiel #5
0
 public void OnlyOneMatchAtfirstIndex()
 {
     string target = "CADACAABRABRADARCADR";
     PatternFinder finder = new PatternFinder("CADA", SearchOptions.Sunday);
     var result = finder.Find(target);
     //
     Assert.IsTrue(result.IsMatch);
     Assert.IsTrue(result.Index == 0);
     while (result.IsMatch)
     {
         result = result.Next();
         Assert.IsFalse(result.IsMatch);
     }
 }
Beispiel #6
0
 public void TestMoreThanOneWildCard()
 {
     string target = "ABRACADABRA";
     PatternFinder finder = new PatternFinder("??BR", SearchOptions.Wildcard);
     var result = finder.Find(target);
     List<int> matches = new List<int>();
     List<string> patterns = new List<string>();
     while (result.IsMatch)
     {
         matches.Add(result.Index);
         result = result.Next();
     }
     Assert.IsTrue(matches.Count == 1);
     Assert.IsTrue(matches[0] == 6);
 }
Beispiel #7
0
        public void MultipleMatches()
        {
            string target = "CADACADACAABRABRADARCCADAADRCADA";
            PatternFinder finder = new PatternFinder("CADA", SearchOptions.Raita);
            var result = finder.Find(target);
            List<int> maches = new List<int>();
            while (result.IsMatch)
            {
                maches.Add(result.Index);
                result = result.Next();
            }

            Assert.IsTrue(maches.Count == 4);
            Assert.IsTrue(maches[0] == 0);
            Assert.IsTrue(maches[1] == 4);
            Assert.IsTrue(maches[2] == 21);
            Assert.IsTrue(maches[3] == 28);
        }
Beispiel #8
0
        public void FindMatch()
        {
            PatternFinder pf = new PatternFinder(new string[] { "a", "ab", "bab", "bc", "bca", "c", "caa" });
            ISearchResult results = pf.Find("abccab");
            //Assert.IsTrue(results.Length == 7);
            List<ISearchResult> list = new List<ISearchResult>();
            while (results.IsMatch)
            {
                list.Add(results);
                results = results.Next();
            }
            Assert.IsTrue(list.Count() == 7);

            Assert.IsTrue(list[0].Index == 0);
            Assert.IsTrue(list[1].Index == 0);
            Assert.IsTrue(list[2].Index == 1);
            Assert.IsTrue(list[3].Index == 2);
            Assert.IsTrue(list[4].Index == 3);
            Assert.IsTrue(list[5].Index == 4);
            Assert.IsTrue(list[6].Index == 4);
        }
Beispiel #9
0
 public void TargetWithEmptySpaces()
 {
     string target = "ACCAD AAABRABRADARCCADA ADRCADA";
     PatternFinder finder = new PatternFinder("CADA", SearchOptions.Raita);
     var result = finder.Find(target);
     List<int> maches = new List<int>();
     while (result.IsMatch)
     {
         maches.Add(result.Index);
         result = result.Next();
     }
     Assert.IsTrue(maches.Count == 2);
     Assert.IsTrue(maches[0] == 19);
     Assert.IsTrue(maches[1] == 27);
 }