diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 000000000..1f0c2545d --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,24 @@ +cmake_minimum_required(VERSION 3.0) + +# set directory name as the project name +# get directory name +get_filename_component(ProjectId ${CMAKE_SOURCE_DIR} NAME) +# replace whitespaces with underscores +string(REPLACE " " "_" ProjectId ${ProjectId}) +# set project name +project(${ProjectId}) + +INCLUDE(ExternalProject) + +# compiler options +SET(COMPILE_OPTIONS "-O0 -g3 -Wall -Werror -fmessage-length=0") + +# add all cpp file recursive into sourceFiles varibale +FILE(GLOB_RECURSE sourceFiles ${CMAKE_HOME_DIRECTORY}/src/*.cpp) + +# print list of source files +# MESSAGE(STATUS "All source files are: ${sourceFiles}") + +INCLUDE_DIRECTORIES(${CMAKE_HOME_DIRECTORY}/src) +ENABLE_TESTING() +ADD_SUBDIRECTORY(tests) diff --git a/libs/.gitignore b/libs/.gitignore new file mode 100644 index 000000000..d6b7ef32c --- /dev/null +++ b/libs/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/src/config/config.hpp b/src/config/config.hpp index 407354258..5f3dfadaf 100644 --- a/src/config/config.hpp +++ b/src/config/config.hpp @@ -7,6 +7,5 @@ namespace config constexpr const char * COMPILE_CPU_PATH = "compile_cpu_path"; constexpr const char * TEMPLATE_CPU_CPP_PATH = "template_cpu_cpp_path"; -constexpr const char * TEMPLATE_CPU_HPP_PATH = "template_cpu_hpp_path"; } diff --git a/src/cypher/debug/tree_print.hpp b/src/cypher/debug/tree_print.hpp index 135ff8529..5cd6fd44b 100644 --- a/src/cypher/debug/tree_print.hpp +++ b/src/cypher/debug/tree_print.hpp @@ -28,7 +28,7 @@ public: Entry(Printer& printer) : printer(printer), valid(true) { printer.level++; - + for(size_t i = 1; i < printer.level; ++i) printer.stream << "| "; @@ -36,12 +36,12 @@ public: } Entry(const Entry&) = delete; - + Entry(Entry&& other) : printer(other.printer), valid(true) { other.valid = false; } - + ~Entry() { if(valid) @@ -87,7 +87,7 @@ public: auto entry = printer.advance("Start"); Traverser::visit(start); } - + void visit(ast::ReadQuery& read_query) override { auto entry = printer.advance("Read Query"); diff --git a/src/utils/config/config.hpp b/src/utils/config/config.hpp index edd43748a..9d685467c 100644 --- a/src/utils/config/config.hpp +++ b/src/utils/config/config.hpp @@ -11,6 +11,7 @@ #include #include #include +#include namespace config { @@ -27,12 +28,14 @@ private: // 3. ENV var | // 4. program argument \ / // _config = YAML::LoadFile("config.yaml"); + + // env -> std::getenv("NAME") + // somehow inject (int argc, char* argv[]) } public: static Config& instance() { - // TODO resolve multithreading problems static Config config; return config; } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 000000000..04053305c --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,36 @@ +cmake_minimum_required(VERSION 3.0) + +project(memgraph_tests) + +# setup dependencies + +# Catch (C++ Automated Test Cases in Headers) dependency +ExternalProject_Add( + Catch + GIT_REPOSITORY "https://github.com/philsquared/Catch.git" + GIT_TAG "master" + SOURCE_DIR "${CMAKE_SOURCE_DIR}/libs/Catch" + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + TEST_COMMAND "" +) +ExternalProject_Get_Property(Catch source_dir) +set(catch_source_dir ${source_dir}) +include_directories(${catch_source_dir}/include) + +# find tests +file(GLOB_RECURSE test_files ${CMAKE_HOME_DIRECTORY}/tests/*.cpp) +set(tests "") +foreach(test_file ${test_files}) + get_filename_component(test_name ${test_file} NAME_WE) + list(APPEND tests ${test_name}) +endforeach() +MESSAGE(STATUS "Available tests are: ${tests}") + +# build tests +foreach(test ${tests}) + add_executable(${test} ${test}.cpp) + add_test(NAME ${test} COMMAND ${test}) + set_property(TARGET ${test} PROPERTY CXX_STANDARD 14) +endforeach() diff --git a/tests/cypher_traversal.cpp b/tests/cypher_traversal.cpp new file mode 100644 index 000000000..b5e798477 --- /dev/null +++ b/tests/cypher_traversal.cpp @@ -0,0 +1,30 @@ +#include +#include + +#include "cypher/compiler.hpp" +#include "cypher/debug/tree_print.hpp" + +using std::cout; +using std::endl; + +int calc(int i) +{ + return i + 1; +} + +int main() +{ + // TODO + // auto print_visitor = new PrintVisitor(cout); + + // // create AST + // cypher::Compiler compiler; + // auto tree = compiler.syntax_tree("MATCH (n) DELETE n"); + + // // traverser the tree + // tree.root->accept(*print_visitor); + // + assert(calc(0) == 1); + + return 0; +} diff --git a/tests/dynamic_bitset.cpp b/tests/dynamic_bitset.cpp new file mode 100644 index 000000000..8294f3c34 --- /dev/null +++ b/tests/dynamic_bitset.cpp @@ -0,0 +1,20 @@ +#define CATCH_CONFIG_MAIN +#include "catch.hpp" + +#include "data_structures/bitset/dynamic_bitset.hpp" + +TEST_CASE("Dynamic bitset basic functionality") +{ + DynamicBitset<> db; + db.set(222555, 1); + bool value = db.at(222555, 1); + REQUIRE(value == true); + + db.set(32, 1); + value = db.at(32, 1); + REQUIRE(value == true); + + db.clear(32, 1); + value = db.at(32, 1); + REQUIRE(value == false); +}