summaryrefslogtreecommitdiffstats
path: root/test/src/test-trie.cpp
diff options
context:
space:
mode:
authorStefan Radomski <radomski@tk.informatik.tu-darmstadt.de>2014-04-22 14:02:03 (GMT)
committerStefan Radomski <radomski@tk.informatik.tu-darmstadt.de>2014-04-22 14:02:03 (GMT)
commit1fb6bcf30f954e426f2d3002d14887574fb941dd (patch)
tree08cff7f2b879c50efe79e3c04d255075522af862 /test/src/test-trie.cpp
parent71c334bf4e35559496feac3f3cf00b72ceb88812 (diff)
downloaduscxml-1fb6bcf30f954e426f2d3002d14887574fb941dd.zip
uscxml-1fb6bcf30f954e426f2d3002d14887574fb941dd.tar.gz
uscxml-1fb6bcf30f954e426f2d3002d14887574fb941dd.tar.bz2
Major refactoring
- Moved tests - Changes to promela datamodel - Implemented Trie
Diffstat (limited to 'test/src/test-trie.cpp')
-rw-r--r--test/src/test-trie.cpp92
1 files changed, 92 insertions, 0 deletions
diff --git a/test/src/test-trie.cpp b/test/src/test-trie.cpp
new file mode 100644
index 0000000..8c7ab15
--- /dev/null
+++ b/test/src/test-trie.cpp
@@ -0,0 +1,92 @@
+#include "uscxml/util/Trie.h"
+#include <iostream>
+#include <assert.h>
+
+using namespace uscxml;
+
+int main(int argc, char** argv) {
+ {
+ Trie trie;
+ int nrTokens = 0;
+ size_t offset = 0;
+ std::string word = "this is to be tokenized";
+ std::string token;
+ while((offset = trie.getNextToken(word, offset, token)) != std::string::npos) {
+ std::cout << "\"" << token << "\" ";
+ nrTokens++;
+ }
+ std::cout << std::endl;
+ assert(nrTokens == word.length());
+ }
+
+ {
+ Trie trie(" ");
+ int nrTokens = 0;
+ size_t offset = 0;
+ std::string word = "this is to be tokenized";
+ std::string token;
+ while(offset = trie.getNextToken(word, offset, token), token.length() > 0) {
+ std::cout << "\"" << token << "\" ";
+ nrTokens++;
+ }
+ std::cout << std::endl;
+ assert(nrTokens == 5);
+ }
+
+ {
+ Trie trie("#");
+ int nrTokens = 0;
+ size_t offset = 0;
+ std::string word = "#bb#bbbb#b#bbb#bb#b#";
+ std::string token;
+ while(offset = trie.getNextToken(word, offset, token), token.length() > 0) {
+ std::cout << "\"" << token << "\" ";
+ nrTokens++;
+ }
+ std::cout << std::endl;
+ assert(nrTokens == 6);
+ }
+
+ {
+ Trie trie(" ");
+ int nrTokens = 0;
+ size_t offset = 0;
+ std::string word = " this is to be tokenized";
+ std::string token;
+ while(offset = trie.getNextToken(word, offset, token), token.length() > 0) {
+ std::cout << "\"" << token << "\" ";
+ nrTokens++;
+ }
+ std::cout << std::endl;
+ assert(nrTokens == 3);
+ }
+
+ {
+ Trie trie("");
+ trie.addWord("a");
+ trie.addWord("b");
+
+ trie.dump();
+ }
+
+ {
+ Trie trie(".");
+ trie.addWord("foo.bar");
+ trie.addWord("foo.foo");
+ trie.addWord("foo.foo.baz");
+ trie.addWord("foz.foo.baz");
+ trie.addWord("foz.foo");
+
+ trie.dump();
+
+ std::list<TrieNode*> childs;
+
+ childs = trie.getChildsWithWords(trie.root);
+ assert(childs.size() == 5);
+
+ assert(trie.getNodeWithPrefix("") == trie.root);
+
+ childs = trie.getWordsWithPrefix("");
+ assert(childs.size() == 5);
+ }
+} \ No newline at end of file