Пример #1
0
 public void Find_PatternDoesNotExistInText_NoResultExists(string text, string pattern)
 {
     var array = new SuffixArray(_encoder.GetBytes(text));
       array.Initialize();
       var results = array.Find(_encoder.GetBytes(pattern));
       Assert.AreEqual(0, results.OccurrencesCount);
 }
Пример #2
0
        public void Find_arrayIsNotInitialized_ThrowInvalidOperationException()
        {
            const string text = "banana";
              var array = new SuffixArray(_encoder.GetBytes(text));

              Assert.Throws<InvalidOperationException>(() => array.Find(_encoder.GetBytes("an")));
        }
Пример #3
0
 public void Find_an()
 {
     const string text = "banana";
       var array = new SuffixArray(_encoder.GetBytes(text));
       array.Initialize();
       var results = array.Find(_encoder.GetBytes("an"));
       Assert.AreEqual(2, results.OccurrencesCount);
       Assert.AreEqual(1, results.Indices[0]);
       Assert.AreEqual(3, results.Indices[1]);
 }
Пример #4
0
 public void Initialize_ReturnComparisonsCount()
 {
     const string text = "banana";
       var array = new SuffixArray(_encoder.GetBytes(text));
       var comparisonsCount = array.Initialize();
       Assert.Greater(comparisonsCount, 0);
 }
Пример #5
0
 public void Find_sba()
 {
     const string text = "sasbasaasba";
       var array = new SuffixArray(_encoder.GetBytes(text));
       array.Initialize();
       var results = array.Find(_encoder.GetBytes("sba"));
       Assert.AreEqual(2, results.OccurrencesCount);
 }
Пример #6
0
 public void Find_PatternEqualText_ReturnIndexZero(string s)
 {
     var array = new SuffixArray(_encoder.GetBytes(s));
       array.Initialize();
       var results = array.Find(_encoder.GetBytes(s));
       Assert.AreEqual(0, results.Indices[0]);
 }
Пример #7
0
 public void Find_PatternEqualText_OneResultExists(string s)
 {
     var array = new SuffixArray(_encoder.GetBytes(s));
       array.Initialize();
       var results = array.Find(_encoder.GetBytes(s));
       Assert.AreEqual(1, results.OccurrencesCount);
 }
Пример #8
0
        static void Main(string[] args)
        {
            var encoder = new ByteStringEncoder();
              var operationTimeTester = new OperationTimeTester();

              var text = File.ReadAllBytes(@"..\doc\pan_wolodyjowski_line_kopia.t");
              var pattern = File.ReadAllBytes(@"..\doc\Pattern_kopia.t");
              var patternString = encoder.GetString(pattern);
              var patternSize = pattern.Length;
              var textSize = text.Length;

              var brute = new BrutePatternSearcher();
              var result = operationTimeTester.Test(brute.Search, pattern, text);
              Show("Pan Wołodyjowski", textSize, "Brute", patternString, patternSize, result);

              Pause();

              var rabinkarpModulo13 = new RabinKarpPatternSearcher(new HashingService(256, 13));
              result = operationTimeTester.Test(rabinkarpModulo13.Search, pattern, text);
              Show("Pan Wołodyjowski", textSize, "Rabin-Karp with hashing modulo 13", patternString, patternSize, result);

              Pause();

              var rabinkarpModulo101 = new RabinKarpPatternSearcher(new HashingService(256, 101));
              result = operationTimeTester.Test(rabinkarpModulo101.Search, pattern, text);
              Show("Pan Wołodyjowski", textSize, "Rabin-Karp with hashing modulo 101", patternString, patternSize, result);

              Pause();

              var rabinkarpModulo2147483647 = new RabinKarpPatternSearcher(new HashingService(256, 2147483647));
              result = operationTimeTester.Test(rabinkarpModulo2147483647.Search, pattern, text);
              Show("Pan Wołodyjowski", textSize, "Rabin-Karp with hashing modulo 2147483647", patternString, patternSize, result);

              Pause();

              var suffixTree = new SuffixTree(text);
              System.Console.Out.WriteLine("Suffix tree building start...");
              var suffixTreeBuildingResult = operationTimeTester.Test(suffixTree.Initialize);
              System.Console.Out.WriteLine("Comparisons count: {0}", suffixTreeBuildingResult.OperationResult);
              System.Console.Out.WriteLine("Suffix tree building finished.");
              System.Console.Out.WriteLine("Elapsed: {0}", suffixTreeBuildingResult.Elapsed);
              System.Console.Out.WriteLine();

              Pause();

              result = operationTimeTester.Test(suffixTree.Find, pattern);
              Show("Pan Wołodyjowski", textSize, "Suffix Tree", patternString, patternSize, result);

              Pause();

              var suffixArray = new SuffixArray(text);
              System.Console.Out.WriteLine("Suffix array building start...");
              var suffixArrayBuildingResult = operationTimeTester.Test(suffixArray.Initialize);
              System.Console.Out.WriteLine("Comparisons count: {0}", suffixArrayBuildingResult.OperationResult);
              System.Console.Out.WriteLine("Suffix array building finished.");
              System.Console.Out.WriteLine("Elapsed: {0}", suffixArrayBuildingResult.Elapsed);
              System.Console.Out.WriteLine();

              Pause();

              result = operationTimeTester.Test(suffixArray.Find, pattern);
              Show("Pan Wołodyjowski", textSize, "Suffix Array", patternString, patternSize, result);

              Pause();
        }