TestMain.cpp 2.71 KB
Newer Older
1
2
3
4
#include "TestMain.hpp"
#include "Main.hpp"

#include "TestEnvironment.hpp"
niklas.baumgarten's avatar
niklas.baumgarten committed
5
#include <filesystem>
6
7


niklas.baumgarten's avatar
niklas.baumgarten committed
8
class TestMainProgram : public TestWithParam<ConfigMap> {
9
protected:
niklas.baumgarten's avatar
niklas.baumgarten committed
10
  MainProgram *mainProgram;
niklas.baumgarten's avatar
niklas.baumgarten committed
11

niklas.baumgarten's avatar
niklas.baumgarten committed
12
13
14
  TestMainProgram(ConfigMap defaultMap) {
    std::filesystem::remove_all("data/vtu/");
    std::filesystem::create_directory("data/vtu/");
niklas.baumgarten's avatar
niklas.baumgarten committed
15

niklas.baumgarten's avatar
niklas.baumgarten committed
16
17
    ConfigMap finalMap = defaultMap;
    ConfigMap additionalMap = GetParam();
18

niklas.baumgarten's avatar
niklas.baumgarten committed
19
20
    for (auto &pair: additionalMap)
      finalMap[pair.first] = pair.second;
21

niklas.baumgarten's avatar
niklas.baumgarten committed
22
    Config::initialize(finalMap);
23

niklas.baumgarten's avatar
niklas.baumgarten committed
24
25
    mainProgram = new MainProgram();
  }
26

niklas.baumgarten's avatar
niklas.baumgarten committed
27
28
29
30
31
  void TearDown() override {
    delete mainProgram;
    Plotting::InstanceM().Clear();
    Config::close();
  }
32
33
};

niklas.baumgarten's avatar
niklas.baumgarten committed
34
35
class TestMainProgramElliptic : public TestMainProgram {
public:
niklas.baumgarten's avatar
niklas.baumgarten committed
36
  TestMainProgramElliptic() : TestMainProgram(DefaultEllipticConfigMap) {}
niklas.baumgarten's avatar
niklas.baumgarten committed
37
};
38

niklas.baumgarten's avatar
niklas.baumgarten committed
39
INSTANTIATE_TEST_SUITE_P(TestMainProgram, TestMainProgramElliptic, Values(
40
41
//  ConfigMap{{"Problem", "StochasticLaplace1D"}, {"epsilon", "0.01"}},
//  ConfigMap{{"Problem", "StochasticLaplace1D"}, {"epsilon", "0.003"}},
niklas.baumgarten's avatar
niklas.baumgarten committed
42
43
//  ConfigMap{{"Problem", "StochasticLaplace2D"}, {"epsilon", "0.0"},
//            {"initLevels", "[3, 4, 5, 6]"}, {"initSampleAmount", "[100, 100, 100, 100]"}},
niklas.baumgarten's avatar
niklas.baumgarten committed
44
  ConfigMap{{"Problem", "StochasticLaplace2D"}, {"epsilon", "0.01"}},
niklas.baumgarten's avatar
niklas.baumgarten committed
45
46
47
  ConfigMap{{"Problem", "StochasticLaplace2D"}, {"epsilon", "0.003"}},
  ConfigMap{{"Problem", "StochasticLaplace2DTest"}, {"epsilon", "0.01"}},
  ConfigMap{{"Problem", "StochasticLaplace2DTest"}, {"epsilon", "0.003"}}
48
49
));

niklas.baumgarten's avatar
niklas.baumgarten committed
50
TEST_P(TestMainProgramElliptic, TestRun) {
niklas.baumgarten's avatar
niklas.baumgarten committed
51
52
53
54
55
  EXPECT_EQ(mainProgram->Run(), 0);
  EXPECT_TRUE(mainProgram->mlmc.errors.total < mainProgram->mlmc.epsilon);
  EXPECT_TRUE(mainProgram->mlmc.exponents.alpha > 0);
  EXPECT_TRUE(mainProgram->mlmc.exponents.beta > 0);
  EXPECT_TRUE(mainProgram->mlmc.exponents.gamma > 0);
56
57
}

niklas.baumgarten's avatar
niklas.baumgarten committed
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//class TestMainProgramTransport : public TestMainProgram {
//public:
//    TestMainProgramTransport() : TestMainProgram(DefaultTransportConfigMap) {}
//};
//
//INSTANTIATE_TEST_CASE_P(TestMainProgram, TestMainProgramTransport, Values(
//    ConfigMap{{"epsilon", "0.01"}},
//    ConfigMap{{"epsilon", "0.003"}},
//    ConfigMap{{"epsilon", "0.001"}},
//    ConfigMap{{"epsilon", "0.0003"}}
//));
//
//TEST_P(TestMainProgramTransport, TestRunMLMCExperiment) {
//    EXPECT_EQ(mainProgram->Run(), 0);
//    EXPECT_TRUE(mainProgram->mlmc.errors.total < mainProgram->mlmc.epsilon);
//    EXPECT_TRUE(mainProgram->mlmc.exponents.alpha > 0);
//    EXPECT_TRUE(mainProgram->mlmc.exponents.beta > 0);
//    EXPECT_TRUE(mainProgram->mlmc.exponents.gamma > 0);
//}
77
78

int main(int argc, char **argv) {
niklas.baumgarten's avatar
niklas.baumgarten committed
79
80
81
82
83
84
  return MppTest(
    MppTestBuilder(argc, argv).
      WithoutDefaultConfig().
      WithScreenLogging().
      WithPPM()
  ).RUN_ALL_MPP_TESTS();
85
}