Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Mpp
MLUQ
Commits
a87d0a02
Commit
a87d0a02
authored
Mar 25, 2021
by
niklas.baumgarten
Browse files
test refactoring
parent
0506ff0a
Changes
2
Hide whitespace changes
Inline
Side-by-side
mlmc/tests/montecarlo/TestMonteCarlo.cpp
View file @
a87d0a02
#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
(
...
...
mlmc/tests/montecarlo/TestMonteCarlo.hpp
View file @
a87d0a02
...
...
@@ -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
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment