TestMainProgramElliptic.cpp 1.61 KB
Newer Older
1
#include "main/MainProgram.hpp"
niklas.baumgarten's avatar
niklas.baumgarten committed
2
#include "TestMainProgramElliptic.hpp"
niklas.baumgarten's avatar
niklas.baumgarten committed
3
4
5

#include "TestEnvironment.hpp"

niklas.baumgarten's avatar
niklas.baumgarten committed
6

niklas.baumgarten's avatar
niklas.baumgarten committed
7
typedef std::map<std::string, std::string> ConfigMap;
niklas.baumgarten's avatar
niklas.baumgarten committed
8
9
10
11
12

struct ConfigMapsForTest {
    ConfigMap defaultMap;
    ConfigMap additionalConfigMap;
};
13

14
class TestMainProgram : public TestWithParam<ConfigMapsForTest> {
niklas.baumgarten's avatar
niklas.baumgarten committed
15
16
17
18
protected:
    std::unique_ptr<MainProgram> mainProgram;

    void SetUp() override {
niklas.baumgarten's avatar
niklas.baumgarten committed
19
20
        ConfigMap finalMap = GetParam().defaultMap;
        ConfigMap additionalMap = GetParam().additionalConfigMap;
niklas.baumgarten's avatar
niklas.baumgarten committed
21

22
23
24
        for (auto &pair: additionalMap)
            finalMap[pair.first] = pair.second;

niklas.baumgarten's avatar
niklas.baumgarten committed
25
        Config::initialize(finalMap);
niklas.baumgarten's avatar
niklas.baumgarten committed
26

niklas.baumgarten's avatar
niklas.baumgarten committed
27
28
29
        mainProgram = std::make_unique<MainProgram>();
        mainProgram->Initialize();
    }
niklas.baumgarten's avatar
niklas.baumgarten committed
30

niklas.baumgarten's avatar
niklas.baumgarten committed
31
    void TearDown() override {
niklas.baumgarten's avatar
niklas.baumgarten committed
32
        Config::close();
niklas.baumgarten's avatar
niklas.baumgarten committed
33
    }
niklas.baumgarten's avatar
niklas.baumgarten committed
34
};
niklas.baumgarten's avatar
niklas.baumgarten committed
35

niklas.baumgarten's avatar
niklas.baumgarten committed
36
INSTANTIATE_TEST_CASE_P(TestMainProgram, TestMainProgram, Values(
37
38
    // Tests with default elliptic config
    ConfigMapsForTest{defaultEllipticConfigMap,
niklas.baumgarten's avatar
niklas.baumgarten committed
39
                      ConfigMap{}},
niklas.baumgarten's avatar
niklas.baumgarten committed
40
41

    ConfigMapsForTest{defaultEllipticConfigMap,
42
                      ConfigMap{{"Problem", "StochasticLaplace2D"}}}
niklas.baumgarten's avatar
niklas.baumgarten committed
43
));
niklas.baumgarten's avatar
niklas.baumgarten committed
44

niklas.baumgarten's avatar
niklas.baumgarten committed
45
46
47
TEST_P(TestMainProgram, TestRunMLMCExperiment) {
    ASSERT_EQ(mainProgram->Run(), 0);
    ASSERT_TRUE(mainProgram->mlmc->totalErr < mainProgram->epsilon);
niklas.baumgarten's avatar
niklas.baumgarten committed
48
49
50
    ASSERT_TRUE(mainProgram->mlmc->alpha > 0);
    ASSERT_TRUE(mainProgram->mlmc->beta > 0);
    ASSERT_TRUE(mainProgram->mlmc->gamma > 0);
niklas.baumgarten's avatar
niklas.baumgarten committed
51
}
niklas.baumgarten's avatar
niklas.baumgarten committed
52

niklas.baumgarten's avatar
niklas.baumgarten committed
53
int main(int argc, char **argv) {
54
55
56
    MppTest mppTest = MppTestBuilder(argc, argv).WithPPM().WithoutDefaultConfig().
        WithScreenLogging().WithSearchPath("../../mlmc/");
    return mppTest.RUN_ALL_MPP_TESTS();
niklas.baumgarten's avatar
niklas.baumgarten committed
57
}