소스 검색

Add test for ACAutomaton

Olivier Marty 8 년 전
부모
커밋
0a7a48a825
2개의 변경된 파일18개의 추가작업 그리고 2개의 파일을 삭제
  1. 2 2
      code/ACAutomaton.cpp
  2. 16 0
      code/ACAutomaton_test.cpp

+ 2 - 2
code/ACAutomaton.cpp

@@ -15,7 +15,7 @@ struct Trie {
     L=0;
     root = newnode();
   }
-  void insert(char buf[]) {
+  void insert(const char buf[]) {
     int len = strlen(buf);
     int now = root;
     for (int i = 0; i < len; i++) {
@@ -47,7 +47,7 @@ struct Trie {
       }
     }
   }
-  int query(char buf[]) {
+  int query(const char buf[]) {
     int len = strlen(buf);
     int now = root;
     int res = 0;

+ 16 - 0
code/ACAutomaton_test.cpp

@@ -0,0 +1,16 @@
+#include <bits/stdc++.h>
+using namespace std;
+
+#include "ACAutomaton.cpp"
+
+Trie ac;
+
+int main() {
+  ac.init();
+  ac.insert("hel");
+  ac.insert("llo");
+  ac.insert("world");
+  ac.build();
+  assert(ac.query("hello world !") == 3);
+  return 0;
+}