diff options
author | Adrian Kummerländer | 2014-02-05 16:57:49 +0100 |
---|---|---|
committer | Adrian Kummerländer | 2014-02-05 16:57:49 +0100 |
commit | 6ad51b897a223e95ee852321b3c5c0ec23b1ee64 (patch) | |
tree | 44235b5d93efd5542f01d5a34f73c5c399b7c04f | |
parent | 85b17dca6e62fc43517506c281f16dd91f53f0ae (diff) | |
download | Trie-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.txt | 26 | ||||
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | test.cc | 71 |
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 +) @@ -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 @@ -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(); } |