From b9681594380333a0a3f0011b40ac6542e7022d98 Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Sun, 8 Feb 2015 17:54:09 +0100 Subject: Deleted DynamicTokenTree class, replaced by TokenTrie --- test/plugins/plain/DynamicTokenTreeTest.cpp | 94 ----------------------------- test/plugins/plain/TokenTrieTest.cpp | 92 ++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+), 94 deletions(-) delete mode 100644 test/plugins/plain/DynamicTokenTreeTest.cpp create mode 100644 test/plugins/plain/TokenTrieTest.cpp (limited to 'test/plugins') diff --git a/test/plugins/plain/DynamicTokenTreeTest.cpp b/test/plugins/plain/DynamicTokenTreeTest.cpp deleted file mode 100644 index 5ae414c..0000000 --- a/test/plugins/plain/DynamicTokenTreeTest.cpp +++ /dev/null @@ -1,94 +0,0 @@ -/* - Ousía - Copyright (C) 2014 Benjamin Paaßen, Andreas Stöckel - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include - -#include - -namespace ousia { - -static const TokenDescriptor *d1 = reinterpret_cast(1); -static const TokenDescriptor *d2 = reinterpret_cast(2); -static const TokenDescriptor *d3 = reinterpret_cast(3); -static const TokenDescriptor *d4 = reinterpret_cast(4); - -TEST(DynamicTokenTree, registerToken) -{ - DynamicTokenTree tree; - - ASSERT_TRUE(tree.registerToken("a", d1)); - ASSERT_TRUE(tree.registerToken("ab", d2)); - ASSERT_TRUE(tree.registerToken("b", d3)); - ASSERT_TRUE(tree.registerToken("hello", d4)); - - ASSERT_FALSE(tree.registerToken("", d1)); - ASSERT_FALSE(tree.registerToken("a", d4)); - ASSERT_FALSE(tree.registerToken("ab", d4)); - ASSERT_FALSE(tree.registerToken("b", d4)); - ASSERT_FALSE(tree.registerToken("hello", d4)); - - ASSERT_EQ(d1, tree.hasToken("a")); - ASSERT_EQ(d2, tree.hasToken("ab")); - ASSERT_EQ(d3, tree.hasToken("b")); - ASSERT_EQ(d4, tree.hasToken("hello")); - ASSERT_EQ(nullptr, tree.hasToken("")); - ASSERT_EQ(nullptr, tree.hasToken("abc")); -} - -TEST(DynamicTokenTree, unregisterToken) -{ - DynamicTokenTree tree; - - ASSERT_TRUE(tree.registerToken("a", d1)); - ASSERT_FALSE(tree.registerToken("a", d4)); - - ASSERT_TRUE(tree.registerToken("ab", d2)); - ASSERT_FALSE(tree.registerToken("ab", d4)); - - ASSERT_TRUE(tree.registerToken("b", d3)); - ASSERT_FALSE(tree.registerToken("b", d4)); - - ASSERT_EQ(d1, tree.hasToken("a")); - ASSERT_EQ(d2, tree.hasToken("ab")); - ASSERT_EQ(d3, tree.hasToken("b")); - - ASSERT_TRUE(tree.unregisterToken("a")); - ASSERT_FALSE(tree.unregisterToken("a")); - - ASSERT_EQ(nullptr, tree.hasToken("a")); - ASSERT_EQ(d2, tree.hasToken("ab")); - ASSERT_EQ(d3, tree.hasToken("b")); - - ASSERT_TRUE(tree.unregisterToken("b")); - ASSERT_FALSE(tree.unregisterToken("b")); - - ASSERT_EQ(nullptr, tree.hasToken("a")); - ASSERT_EQ(d2, tree.hasToken("ab")); - ASSERT_EQ(nullptr, tree.hasToken("b")); - - ASSERT_TRUE(tree.unregisterToken("ab")); - ASSERT_FALSE(tree.unregisterToken("ab")); - - ASSERT_EQ(nullptr, tree.hasToken("a")); - ASSERT_EQ(nullptr, tree.hasToken("ab")); - ASSERT_EQ(nullptr, tree.hasToken("b")); -} - - -} - diff --git a/test/plugins/plain/TokenTrieTest.cpp b/test/plugins/plain/TokenTrieTest.cpp new file mode 100644 index 0000000..d378fdf --- /dev/null +++ b/test/plugins/plain/TokenTrieTest.cpp @@ -0,0 +1,92 @@ +/* + Ousía + Copyright (C) 2014 Benjamin Paaßen, Andreas Stöckel + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include + +#include + +namespace ousia { + +static const TokenTypeId t1 = 0; +static const TokenTypeId t2 = 1; +static const TokenTypeId t3 = 2; +static const TokenTypeId t4 = 3; + +TEST(TokenTrie, registerToken) +{ + TokenTrie tree; + + ASSERT_TRUE(tree.registerToken("a", t1)); + ASSERT_TRUE(tree.registerToken("ab", t2)); + ASSERT_TRUE(tree.registerToken("b", t3)); + ASSERT_TRUE(tree.registerToken("hello", t4)); + + ASSERT_FALSE(tree.registerToken("", t1)); + ASSERT_FALSE(tree.registerToken("a", t4)); + ASSERT_FALSE(tree.registerToken("ab", t4)); + ASSERT_FALSE(tree.registerToken("b", t4)); + ASSERT_FALSE(tree.registerToken("hello", t4)); + + ASSERT_EQ(t1, tree.hasToken("a")); + ASSERT_EQ(t2, tree.hasToken("ab")); + ASSERT_EQ(t3, tree.hasToken("b")); + ASSERT_EQ(t4, tree.hasToken("hello")); + ASSERT_EQ(EmptyToken, tree.hasToken("")); + ASSERT_EQ(EmptyToken, tree.hasToken("abc")); +} + +TEST(TokenTrie, unregisterToken) +{ + TokenTrie tree; + + ASSERT_TRUE(tree.registerToken("a", t1)); + ASSERT_FALSE(tree.registerToken("a", t4)); + + ASSERT_TRUE(tree.registerToken("ab", t2)); + ASSERT_FALSE(tree.registerToken("ab", t4)); + + ASSERT_TRUE(tree.registerToken("b", t3)); + ASSERT_FALSE(tree.registerToken("b", t4)); + + ASSERT_EQ(t1, tree.hasToken("a")); + ASSERT_EQ(t2, tree.hasToken("ab")); + ASSERT_EQ(t3, tree.hasToken("b")); + + ASSERT_TRUE(tree.unregisterToken("a")); + ASSERT_FALSE(tree.unregisterToken("a")); + + ASSERT_EQ(EmptyToken, tree.hasToken("a")); + ASSERT_EQ(t2, tree.hasToken("ab")); + ASSERT_EQ(t3, tree.hasToken("b")); + + ASSERT_TRUE(tree.unregisterToken("b")); + ASSERT_FALSE(tree.unregisterToken("b")); + + ASSERT_EQ(EmptyToken, tree.hasToken("a")); + ASSERT_EQ(t2, tree.hasToken("ab")); + ASSERT_EQ(EmptyToken, tree.hasToken("b")); + + ASSERT_TRUE(tree.unregisterToken("ab")); + ASSERT_FALSE(tree.unregisterToken("ab")); + + ASSERT_EQ(EmptyToken, tree.hasToken("a")); + ASSERT_EQ(EmptyToken, tree.hasToken("ab")); + ASSERT_EQ(EmptyToken, tree.hasToken("b")); +} +} + -- cgit v1.2.3