diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..2f24b84 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "Catch2"] + path = Catch2 + url = https://github.com/catchorg/Catch2.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 06b711a..ef04e43 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,7 @@ cmake_minimum_required (VERSION 3.10) project (PerformanceMeasuring) -set(HEADER_FILES dummy_lib.hpp) +set(HEADER_FILES dummy_lib.hpp Catch2/single_include/catch2/catch.hpp) -add_executable(performance_measuring main.cpp ${HEADER_FILES}) +add_executable(performance_measuring catch2_test1.cpp ${HEADER_FILES}) +target_include_directories(performance_measuring PRIVATE . Catch2/single_include) diff --git a/Catch2 b/Catch2 new file mode 160000 index 0000000..815f995 --- /dev/null +++ b/Catch2 @@ -0,0 +1 @@ +Subproject commit 815f99541dc352c4adbb2f8474f7f67108a830d2 diff --git a/catch2_test1.cpp b/catch2_test1.cpp new file mode 100644 index 0000000..8256d06 --- /dev/null +++ b/catch2_test1.cpp @@ -0,0 +1,22 @@ +// Let Catch provide main(): +#define CATCH_CONFIG_MAIN + +#include + +#include + +std::vector generate_random_numbers(int n, int min, int max) +{ + std::srand(std::time(nullptr)); + std::vector v(n); + for (int i = 0; i < n; ++i) + v[i] = min + std::rand() / ((RAND_MAX + 1u)/max); + + return v; +} + +TEST_CASE( "Simple test" ) { + std::vector v = { 1, 2, 3, 1}; + int r = performance_measuring::compute(v); + REQUIRE( r == 2 ); +} diff --git a/main.cpp b/main.cpp deleted file mode 100644 index 8ca3223..0000000 --- a/main.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include -#include - -#include - -#include "dummy_lib.hpp" - - -std::vector generate_random_numbers(int n, int min, int max) -{ - std::srand(std::time(nullptr)); - std::vector v(n); - for (int i = 0; i < n; ++i) - v[i] = min + std::rand() / ((RAND_MAX + 1u)/max); - - return v; -} - -int main(int /*argc*/, char* /*argv*/[]) -{ - std::vector v = generate_random_numbers(10000, 0, 100); - - // How many times does the smallest element occurst in the vector? - - int r = performance_measuring::compute(v); - - (void)r; - - return EXIT_SUCCESS; -}