Adding Catch2 as submodule, and abandoning main.cpp

master
denes 5 years ago
parent 066627f5e2
commit 9044a9948d
Signed by: denes
GPG Key ID: A7D50EAD42F9FC9F

3
.gitmodules vendored

@ -0,0 +1,3 @@
[submodule "Catch2"]
path = Catch2
url = https://github.com/catchorg/Catch2.git

@ -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)

@ -0,0 +1 @@
Subproject commit 815f99541dc352c4adbb2f8474f7f67108a830d2

@ -0,0 +1,22 @@
// Let Catch provide main():
#define CATCH_CONFIG_MAIN
#include <catch2/catch.hpp>
#include <dummy_lib.hpp>
std::vector<int> generate_random_numbers(int n, int min, int max)
{
std::srand(std::time(nullptr));
std::vector<int> 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<int> v = { 1, 2, 3, 1};
int r = performance_measuring::compute(v);
REQUIRE( r == 2 );
}

@ -1,30 +0,0 @@
#include <cstdlib>
#include <ctime>
#include <vector>
#include "dummy_lib.hpp"
std::vector<int> generate_random_numbers(int n, int min, int max)
{
std::srand(std::time(nullptr));
std::vector<int> 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<int> 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;
}
Loading…
Cancel
Save