From 112ea8c74877bad810c70fb18d55750f675229fd Mon Sep 17 00:00:00 2001 From: DanielWit Date: Mon, 13 Nov 2023 11:35:19 +0000 Subject: [PATCH] finally all tests works extracted main outside so google test does not complain about two mains --- .gitignore | 2 ++ CMakeLists.txt | 2 -- src/gs/gs.cpp | 32 -------------------------------- src/main.cpp | 36 ++++++++++++++++++++++++++++++++++++ tests/CMakeLists.txt | 6 ++++-- tests/gs_test.cpp | 5 +---- 6 files changed, 43 insertions(+), 40 deletions(-) create mode 100644 .gitignore create mode 100644 src/main.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..01f9cb9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +build/ +.vscode/ \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 371f0f6..b974a83 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,5 @@ project(MiscadaProjectGp12Tests) set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) -enable_testing() - add_subdirectory(src) add_subdirectory(tests) \ No newline at end of file diff --git a/src/gs/gs.cpp b/src/gs/gs.cpp index 8cc54ed..4a8c233 100644 --- a/src/gs/gs.cpp +++ b/src/gs/gs.cpp @@ -109,36 +109,4 @@ double countElementsAboveThreshold(double threshold) { return (double)(count)/(width*height); } -#ifndef TESTS -int main(int argc, char* argv[]) { - if (argc != 5){ - std::cout << "Usage: " << argv[0] << " " << std::endl; - } - else{ - Du = std::stod(argv[1]); - Dv = std::stod(argv[2]); - F = std::stod(argv[3]); - k = std::stod(argv[4]); - threshold = std::stod(argv[5]); - } - - init(); - std::cout << "Simulation initiated." << std::endl; - // Main simulation loop - for (int iteration = 0; iteration < numIterations; ++iteration) { - simulateStep(); - - // Periodically write to VTK file - if (iteration % outputInterval == 0) { - writeVTKFile(iteration); - } - } - - // count the amount of pixels above threshold at end. - double n = countElementsAboveThreshold(threshold); - std::cout << "Simulation completed: P(v > threshold) = " << n << std::endl; - - return 0; -} -#endif diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..0f7877f --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,36 @@ + +#include "gs/gs.h" +#include +#include + +int main(int argc, char* argv[]) { + if (argc != 5){ + std::cout << "Usage: " << argv[0] << " " << std::endl; + } + else{ + Du = std::stod(argv[1]); + Dv = std::stod(argv[2]); + F = std::stod(argv[3]); + k = std::stod(argv[4]); + threshold = std::stod(argv[5]); + } + + init(); + std::cout << "Simulation initiated." << std::endl; + + // Main simulation loop + for (int iteration = 0; iteration < numIterations; ++iteration) { + simulateStep(); + + // Periodically write to VTK file + if (iteration % outputInterval == 0) { + writeVTKFile(iteration); + } + } + + // count the amount of pixels above threshold at end. + double n = countElementsAboveThreshold(threshold); + std::cout << "Simulation completed: P(v > threshold) = " << n << std::endl; + + return 0; +} diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index fe51341..42fb422 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -10,6 +10,8 @@ FetchContent_MakeAvailable(googletest) add_library(GTest::GTest INTERFACE IMPORTED) target_link_libraries(GTest::GTest INTERFACE gtest_main) +enable_testing() + add_executable( gs_test gs_test.cpp @@ -21,5 +23,5 @@ target_link_libraries( GTest::GTest gs ) - -add_test(gs_gtests gs_test) +include(GoogleTest) +gtest_discover_tests(gs_test) \ No newline at end of file diff --git a/tests/gs_test.cpp b/tests/gs_test.cpp index 0cd4744..7b6fcc1 100644 --- a/tests/gs_test.cpp +++ b/tests/gs_test.cpp @@ -1,8 +1,7 @@ #include "gs/gs.h" #include -#define TESTS -namespace { +#define TESTS TEST(GSTests, CountElementsAboveThreshold) { double threshold = 0.5; @@ -33,5 +32,3 @@ TEST(GSTests, GridInitializationTest) { } } - -} //namespace