OPAL (Object Oriented Parallel Accelerator Library) 2022.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"
28#include "Expression/SumErrSq.h"
29
30#include "gtest/gtest.h"
31
32#include "boost/smart_ptr.hpp"
33#include "boost/tuple/tuple.hpp"
34#include "boost/type_traits/remove_cv.hpp"
35#include "boost/variant/get.hpp"
36#include "boost/variant/variant.hpp"
37
38
39namespace {
40
41 // The fixture for testing class Foo.
42 class SumErrSqExpressionTest : public ::testing::Test {
43 protected:
44
45 SumErrSqExpressionTest() {
46 // You can do set-up work for each test here.
47 }
48
49 virtual ~SumErrSqExpressionTest() {
50 // You can do clean-up work that doesn't throw exceptions here.
51 }
52
53 // If the constructor and destructor are not enough for setting up
54 // and cleaning up each test, you can define the following methods:
55
56 virtual void SetUp() {
57 // Code here will be called immediately after the constructor (right
58 // before each test).
59 }
60
61 virtual void TearDown() {
62 // Code here will be called immediately after each test (right
63 // before the destructor).
64 }
65 };
66
67
68 TEST_F(SumErrSqExpressionTest, EvaluateSumErrSqExpression) {
69
71 double expected = (3.087242557177229e-04*3.087242557177229e-04 +
72 3.127445619624299e-04*3.127445619624299e-04 +
73 3.185324887508158e-04*3.185324887508158e-04) / 3.0;
74 expected = sqrt(expected);
75
78 errsumsq = SumErrSq();
79 funcs.insert(std::pair<std::string, client::function::type>
80 ("sumErrSq", errsumsq));
81
82 std::string testexpr = "sumErrSq(\"resources/measurement_test.dat\", \"rms_x\", \"resources/test.stat\")";
83 boost::scoped_ptr<Expression> e(new Expression(testexpr, funcs));
85 EXPECT_NO_THROW({
86 result = e->evaluate(vars);
87 });
88
89
90 //XXX: expected uses the nearest (and NOT interpolated) rms_x values
91 ASSERT_NEAR(expected, boost::get<0>(result), 1e-6);
92 ASSERT_TRUE(boost::get<1>(result));
93 }
94
95}
96
97int main(int argc, char **argv) {
98 ::testing::InitGoogleTest(&argc, argv);
99 return RUN_ALL_TESTS();
100}
Tps< T > sqrt(const Tps< T > &x)
Square root.
Definition: TpsMath.h:91
int main(int argc, char **argv)
std::map< std::string, client::function::type > functionDictionary_t
Definition: Expression.h:56
std::map< std::string, double > variableDictionary_t
Definition: Expression.h:55
boost::tuple< double, bool > Result_t
Definition: Expression.h:66
constexpr double e
The value of.
Definition: Physics.h:39
boost::function< boost::tuple< double, bool >(arguments_t)> type
Definition: function.hpp:21