Commit a87d0a02 authored by niklas.baumgarten's avatar niklas.baumgarten
Browse files

test refactoring

parent 0506ff0a
#include "TestMonteCarlo.hpp"
MONTECARLO_INTERVAL_TESTS(TestMonteCarloInterval)
//MONTECARLO_INTERVAL_TESTS(TestMonteCarloIntervalWithSplit)
class TestMonteCarlo : public TestWithParam<std::string> {
protected:
int pLevel = 2;
//MONTECARLO_INTERVAL_TESTS(TestMonteCarloIntervalWithDoubleSplit)
int level = 3;
//MONTECARLO_INTERVAL_TESTS(TestMonteCarloIntervalWithFullSplit)
int dM = 1e6;
MeshesCreator meshesCreator;
PDESolverCreator pdeSolverCreator;
MonteCarlo mc;
TestMonteCarlo(const std::string &meshName, int commSplit = 0) :
meshesCreator(MeshesCreator("Interval").
WithCommSplit(commSplit).
WithDistribute("RCB").
WithoutOverlap().
WithPLevel(pLevel).
WithLevel(level)),
pdeSolverCreator(PDESolverCreator().
WithProblem(GetParam()).
WithQuantity("GeneratorValue").
WithModel("DummyPDESolver")),
mc(MonteCarlo(Level(level), dM, true, meshesCreator, pdeSolverCreator)) {
mc.Method();
}
void TearDown() {
PPM->Barrier(0);
PPM->ClearCommunicators(false);
}
};
class TestMonteCarloInterval : public TestMonteCarlo {
protected:
TestMonteCarloInterval(int commSplit = 0) :
TestMonteCarlo("Interval", commSplit) {}
};
INSTANTIATE_TEST_SUITE_P(TestMonteCarlo, TestMonteCarloInterval, Values(
"StochasticDummyScalarGeneratorProblem"
));
TEST_P(TestMonteCarloInterval, TestMethodOnlyFine) {
EXPECT_NEAR(mc.avgs.Q, 0.0, sqrt(1.0 / dM));
EXPECT_NEAR(mc.avgs.Y, 0.0, sqrt(1.0 / dM));
EXPECT_NEAR(mc.vars.Q, 1.0, sqrt(10.0 / dM));
EXPECT_NEAR(mc.vars.Y, 1.0, sqrt(10.0 / dM));
}
int main(int argc, char **argv) {
return MppTest(
......
......@@ -9,80 +9,6 @@
#include "TestEnvironment.hpp"
constexpr double MONTECARLO_TEST_TOLERANCE = 1e-1;
class TestMonteCarlo : public TestWithParam<std::string> {
protected:
int commSplit;
int pLevel = 2;
int level = 3;
int dM = 1e5;
MeshesCreator meshesCreator;
PDESolverCreator pdeSolverCreator;
MonteCarlo mc;
TestMonteCarlo(const std::string &meshName, int commSplit = 0) :
meshesCreator(MeshesCreator("Interval").
WithCommSplit(commSplit).
WithDistribute("RCB").
WithoutOverlap().
WithPLevel(pLevel).
WithLevel(level)),
pdeSolverCreator(PDESolverCreator().
WithProblem(GetParam()).
WithQuantity("GeneratorValue").
WithModel("DummyPDESolver")),
mc(MonteCarlo(Level(level), dM, true, meshesCreator, pdeSolverCreator)) {
mc.Method();
}
void TearDown() {
PPM->Barrier(0);
PPM->ClearCommunicators(false);
}
};
class TestMonteCarloInterval : public TestMonteCarlo {
protected:
TestMonteCarloInterval(int commSplit = 0) :
TestMonteCarlo("Interval", commSplit) {}
};
class TestMonteCarloIntervalWithSplit : public TestMonteCarloInterval {
protected:
TestMonteCarloIntervalWithSplit() :
TestMonteCarloInterval(1) {}
};
class TestMonteCarloIntervalWithDoubleSplit : public TestMonteCarloInterval {
protected:
TestMonteCarloIntervalWithDoubleSplit() :
TestMonteCarloInterval(2) {}
};
class TestMonteCarloIntervalWithFullSplit : public TestMonteCarloInterval {
protected:
TestMonteCarloIntervalWithFullSplit() :
TestMonteCarloInterval(-1) {}
};
#define MONTECARLO_INTERVAL_TESTS(MonteCarloIntervalTestClass)\
\
INSTANTIATE_TEST_SUITE_P(TestMonteCarlo, MonteCarloIntervalTestClass, Values(\
"StochasticDummyScalarGeneratorProblem"\
));\
\
TEST_P(MonteCarloIntervalTestClass, TestMethodOnlyFine) {\
EXPECT_NEAR(mc.avgs.Q, 0.0, MONTECARLO_TEST_TOLERANCE);\
EXPECT_NEAR(mc.avgs.Y, 0.0, MONTECARLO_TEST_TOLERANCE);\
EXPECT_NEAR(mc.vars.Q, 1.0, MONTECARLO_TEST_TOLERANCE);\
EXPECT_NEAR(mc.vars.Y, 1.0, MONTECARLO_TEST_TOLERANCE);\
}\
#endif //TESTMONTECARLO_HPP
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment