aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Kummerländer2014-02-05 16:57:49 +0100
committerAdrian Kummerländer2014-02-05 16:57:49 +0100
commit6ad51b897a223e95ee852321b3c5c0ec23b1ee64 (patch)
tree44235b5d93efd5542f01d5a34f73c5c399b7c04f
parent85b17dca6e62fc43517506c281f16dd91f53f0ae (diff)
downloadTrie-6ad51b897a223e95ee852321b3c5c0ec23b1ee64.tar
Trie-6ad51b897a223e95ee852321b3c5c0ec23b1ee64.tar.gz
Trie-6ad51b897a223e95ee852321b3c5c0ec23b1ee64.tar.bz2
Trie-6ad51b897a223e95ee852321b3c5c0ec23b1ee64.tar.lz
Trie-6ad51b897a223e95ee852321b3c5c0ec23b1ee64.tar.xz
Trie-6ad51b897a223e95ee852321b3c5c0ec23b1ee64.tar.zst
Trie-6ad51b897a223e95ee852321b3c5c0ec23b1ee64.zip
Added CMake build instructions and test cases
* Test cases are based on GoogleTest and are executed automatically after each compile * Updated README.md accordingly
-rw-r--r--CMakeLists.txt26
-rw-r--r--README.md2
-rw-r--r--test.cc71
3 files changed, 83 insertions, 16 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..342dbc8
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,26 @@
+cmake_minimum_required(VERSION 2.8)
+project(Trie)
+
+set(
+ CMAKE_CXX_FLAGS
+ "-std=c++11 -W -Wall -Wextra -Winline -pedantic"
+)
+
+include_directories(
+ src/
+)
+
+add_executable(
+ test
+ test.cc
+)
+
+target_link_libraries(
+ test
+ gtest
+)
+
+add_custom_command(
+ TARGET test
+ POST_BUILD COMMAND ./test
+)
diff --git a/README.md b/README.md
index db5d4f7..9e03d6b 100644
--- a/README.md
+++ b/README.md
@@ -7,4 +7,4 @@
- Specializable tree element type
- Adding, removing and resolving paths in the prefix tree
- Builds on the standard library
-
+- Unit tests based on GoogleTest
diff --git a/test.cc b/test.cc
index 5105f09..2c38a3f 100644
--- a/test.cc
+++ b/test.cc
@@ -1,24 +1,65 @@
#include "trie.h"
-#include <cassert>
+#include "gtest/gtest.h"
+
#include <cstdint>
-int main() {
- Trie<uint8_t> test;
+class TrieTest : public ::testing::Test { };
+
+TEST_F(TrieTest, Basic) {
+ Trie<uint8_t> trie;
+
+ trie.add({1, 1, 1, 1});
+ trie.add({1, 2, 1, 2});
+ trie.add({2, 3, 4, 5});
+ trie.add({2, 3, 1, 2});
+
+ EXPECT_EQ(trie.resolve({1, 1, 1, 1}).first, true);
+ EXPECT_NE(trie.resolve({1, 1, 1, 1}).second, nullptr);
+
+ EXPECT_EQ(trie.resolve({1, 2, 1, 2}).first, true);
+ EXPECT_NE(trie.resolve({1, 2, 1, 2}).second, nullptr);
+
+ EXPECT_EQ(trie.resolve({1, 2}).first, true);
+ EXPECT_NE(trie.resolve({1, 2}).second, nullptr);
+
+ EXPECT_EQ(trie.resolve({1, 1, 2, 3}).first, false);
+ EXPECT_EQ(trie.resolve({1, 1, 2, 3}).second, nullptr);
+
+ EXPECT_EQ(trie.resolve({2, 1, 4}).first, false);
+ EXPECT_EQ(trie.resolve({2, 1, 4}).second, nullptr);
+}
- test.add({1, 2, 3});
- test.add({1, 2, 4});
- test.add({2, 1});
- test.add({2, 1, 1});
+TEST_F(TrieTest, Remove) {
+ Trie<uint8_t> trie;
- assert(test.resolve({1, 2}).second != nullptr);
- assert(test.resolve({1, 2, 3}).second != nullptr);
- assert(test.resolve({1, 2, 4}).second != nullptr);
- assert(test.resolve({3}).second == nullptr);
+ trie.add({1, 1, 1, 1});
+ trie.add({1, 2, 1, 2});
+ trie.add({2, 3, 4, 5});
+ trie.add({2, 3, 1, 2});
+
+ trie.remove({1, 1, 1, 1});
+
+ EXPECT_EQ(trie.resolve({1, 1, 1, 1}).first, false);
+ EXPECT_EQ(trie.resolve({1, 1, 1, 1}).second, nullptr);
+
+ EXPECT_EQ(trie.resolve({1, 2, 1, 2}).first, true);
+ EXPECT_NE(trie.resolve({1, 2, 1, 2}).second, nullptr);
+
+ trie.remove({2, 3});
+
+ EXPECT_EQ(trie.resolve({2, 3, 4, 5}).first, false);
+ EXPECT_EQ(trie.resolve({2, 3, 4, 5}).second, nullptr);
+
+ EXPECT_EQ(trie.resolve({2, 3}).first, false);
+ EXPECT_EQ(trie.resolve({2, 3}).second, nullptr);
+
+ EXPECT_EQ(trie.resolve({2}).first, true);
+ EXPECT_NE(trie.resolve({2}).second, nullptr);
+}
- test.remove({1, 2});
+int main(int argc, char **argv) {
+ testing::InitGoogleTest(&argc, argv);
- assert(test.resolve({1, 2, 4}).second == nullptr);
- assert(test.resolve({1, 2, 3}).second == nullptr);
- assert(test.resolve({1, 2}).second == nullptr);
+ return RUN_ALL_TESTS();
}