Skip to content

Commit

Permalink
finally all tests works extracted main outside so google test does no…
Browse files Browse the repository at this point in the history
…t complain about two mains
  • Loading branch information
DanielWit committed Nov 13, 2023
1 parent 4826995 commit 112ea8c
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 40 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build/
.vscode/
2 changes: 0 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
32 changes: 0 additions & 32 deletions src/gs/gs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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] << " <Du> <Dv> <F> <k> <threshold>" << 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
36 changes: 36 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

#include "gs/gs.h"
#include <iostream>
#include <sstream>

int main(int argc, char* argv[]) {
if (argc != 5){
std::cout << "Usage: " << argv[0] << " <Du> <Dv> <F> <k> <threshold>" << 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;
}
6 changes: 4 additions & 2 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -21,5 +23,5 @@ target_link_libraries(
GTest::GTest
gs
)

add_test(gs_gtests gs_test)
include(GoogleTest)
gtest_discover_tests(gs_test)
5 changes: 1 addition & 4 deletions tests/gs_test.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#include "gs/gs.h"
#include <gtest/gtest.h>
#define TESTS

namespace {
#define TESTS

TEST(GSTests, CountElementsAboveThreshold) {
double threshold = 0.5;
Expand Down Expand Up @@ -33,5 +32,3 @@ TEST(GSTests, GridInitializationTest) {
}
}


} //namespace

0 comments on commit 112ea8c

Please sign in to comment.