OPAL (Object Oriented Parallel Accelerator Library)  2024.1
OPAL
SumErrSqExpressionTest.cpp
Go to the documentation of this file.
1 //
2 // Test SumErrSqExpressionTest
3 //
4 // Copyright (c) 2010 - 2013, Yves Ineichen, ETH Zürich
5 // All rights reserved
6 //
7 // Implemented as part of the PhD thesis
8 // "Toward massively parallel multi-objective optimization with application to
9 // particle accelerators" (https://doi.org/10.3929/ethz-a-009792359)
10 //
11 // This file is part of OPAL.
12 //
13 // OPAL is free software: you can redistribute it and/or modify
14 // it under the terms of the GNU General Public License as published by
15 // the Free Software Foundation, either version 3 of the License, or
16 // (at your option) any later version.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with OPAL. If not, see <https://www.gnu.org/licenses/>.
20 //
21 #include <set>
22 #include <string>
23 
24 #include "Util/Types.h"
25 #include "Util/OptPilotException.h"
26 #include "Expression/Expression.h"
28 #include "Expression/SumErrSq.h"
29 
30 #include "gtest/gtest.h"
31 
32 #include "boost/tuple/tuple.hpp"
33 #include "boost/type_traits/remove_cv.hpp"
34 #include "boost/variant/get.hpp"
35 #include "boost/variant/variant.hpp"
36 
37 
38 namespace {
39 
40  // The fixture for testing class Foo.
41  class SumErrSqExpressionTest : public ::testing::Test {
42  protected:
43 
44  SumErrSqExpressionTest() {
45  // You can do set-up work for each test here.
46  }
47 
48  virtual ~SumErrSqExpressionTest() {
49  // You can do clean-up work that doesn't throw exceptions here.
50  }
51 
52  // If the constructor and destructor are not enough for setting up
53  // and cleaning up each test, you can define the following methods:
54 
55  virtual void SetUp() {
56  // Code here will be called immediately after the constructor (right
57  // before each test).
58  }
59 
60  virtual void TearDown() {
61  // Code here will be called immediately after each test (right
62  // before the destructor).
63  }
64  };
65 
66 
67  TEST_F(SumErrSqExpressionTest, EvaluateSumErrSqExpression) {
68 
70  double expected = (3.087242557177229e-04*3.087242557177229e-04 +
71  3.127445619624299e-04*3.127445619624299e-04 +
72  3.185324887508158e-04*3.185324887508158e-04) / 3.0;
73  expected = sqrt(expected);
74 
76  client::function::type errsumsq;
77  errsumsq = SumErrSq();
78  funcs.insert(std::pair<std::string, client::function::type>
79  ("sumErrSq", errsumsq));
80 
81  std::string testexpr = "sumErrSq(\"resources/measurement_test.dat\", \"rms_x\", \"resources/test.stat\")";
82  const std::unique_ptr<Expression> e(new Expression(testexpr, funcs));
84  EXPECT_NO_THROW({
85  result = e->evaluate(vars);
86  });
87 
88 
89  //XXX: expected uses the nearest (and NOT interpolated) rms_x values
90  ASSERT_NEAR(expected, boost::get<0>(result), 1e-6);
91  ASSERT_TRUE(boost::get<1>(result));
92  }
93 
94 }
95 
96 int main(int argc, char **argv) {
97  ::testing::InitGoogleTest(&argc, argv);
98  return RUN_ALL_TESTS();
99 }
Tps< T > sqrt(const Tps< T > &x)
Square root.
Definition: TpsMath.h:91
int main(int argc, char *argv[])
Definition: Main.cpp:139
boost::function< boost::tuple< double, bool >arguments_t)> type
Definition: function.hpp:21
std::map< std::string, double > variableDictionary_t
Definition: Expression.h:55
std::map< std::string, client::function::type > functionDictionary_t
Definition: Expression.h:56
float result
Definition: test.py:2
constexpr double e
The value of .
Definition: Physics.h:39
boost::tuple< double, bool > Result_t
Definition: Expression.h:66