Procházet zdrojové kódy

add test to SuffixArray

Olivier Marty před 8 roky
rodič
revize
c65971acbc
3 změnil soubory, kde provedl 31 přidání a 2 odebrání
  1. 1 1
      code/SuffixArray.cpp
  2. 29 0
      code/SuffixArray_test.cpp
  3. 1 1
      main.tex

+ 1 - 1
code/SuffixArray.cc → code/SuffixArray.cpp

@@ -38,7 +38,7 @@ struct SuffixArray {
     return len;
   }
 };
-int main() {
+int test() {
   // bobocel is the 0'th suffix
   //  obocel is the 5'th suffix
   //   bocel is the 1'st suffix

+ 29 - 0
code/SuffixArray_test.cpp

@@ -0,0 +1,29 @@
+#include <bits/stdc++.h>
+using namespace std;
+
+typedef vector<int> VI;
+typedef vector<VI> VVI;
+typedef pair<int, int> PII;
+
+#include "SuffixArray.cpp"
+
+int main() {
+  // bobocel is the 0'th suffix
+  //  obocel is the 5'th suffix
+  //   bocel is the 1'st suffix
+  //    ocel is the 6'th suffix
+  //     cel is the 2'nd suffix
+  //      el is the 3'rd suffix
+  //       l is the 4'th suffix
+  SuffixArray suffix("bobocel");
+  VI v = suffix.GetSuffixArray();
+  assert(v[0] == 0);
+  assert(v[1] == 5);
+  assert(v[2] == 1);
+  assert(v[3] == 6);
+  assert(v[4] == 2);
+  assert(v[5] == 3);
+  assert(v[6] == 4);
+  assert(suffix.LongestCommonPrefix(0, 2) == 2);
+  return 0;
+}

+ 1 - 1
main.tex

@@ -138,7 +138,7 @@ Temps de cuisson : $O(n)$
 \section{Structures de données}
 
 \subsection{Suffix arrays}
-{\scriptsize\lstinputlisting{code/SuffixArray.cc}} % TODO pourquoi un vector<vector<int>> ? Pourquoi dans le code de Shendan best[20][MAXN] ? Si on garde celui de JJ rajouter RMQ etc
+{\scriptsize\lstinputlisting{code/SuffixArray.cpp}} % TODO pourquoi un vector<vector<int>> ? Pourquoi dans le code de Shendan best[20][MAXN] ? Si on garde celui de JJ rajouter RMQ etc
 
 \subsection{Binary Indexed Tree}
 {\scriptsize\lstinputlisting{code/BIT.cc}}