OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
SumErrSqExpressionTest.cpp
Go to the documentation of this file.
1 #include <set>
2 #include <string>
3 
4 #include "Util/Types.h"
8 #include "Expression/SumErrSq.h"
9 
10 #include "gtest/gtest.h"
11 
12 #include "boost/smart_ptr.hpp"
13 #include "boost/tuple/tuple.hpp"
14 #include "boost/type_traits/remove_cv.hpp"
15 #include "boost/variant/get.hpp"
16 #include "boost/variant/variant.hpp"
17 
18 
19 namespace {
20 
21  // The fixture for testing class Foo.
22  class SumErrSqExpressionTest : public ::testing::Test {
23  protected:
24 
25  SumErrSqExpressionTest() {
26  // You can do set-up work for each test here.
27  }
28 
29  virtual ~SumErrSqExpressionTest() {
30  // You can do clean-up work that doesn't throw exceptions here.
31  }
32 
33  // If the constructor and destructor are not enough for setting up
34  // and cleaning up each test, you can define the following methods:
35 
36  virtual void SetUp() {
37  // Code here will be called immediately after the constructor (right
38  // before each test).
39  }
40 
41  virtual void TearDown() {
42  // Code here will be called immediately after each test (right
43  // before the destructor).
44  }
45  };
46 
47 
48  TEST_F(SumErrSqExpressionTest, EvaluateSumErrSqExpression) {
49 
51  double expected = (3.087242557177229e-04*3.087242557177229e-04 +
52  3.127445619624299e-04*3.127445619624299e-04 +
53  3.185324887508158e-04*3.185324887508158e-04) / 3.0;
54  expected = sqrt(expected);
55 
57  client::function::type errsumsq;
58  errsumsq = SumErrSq();
59  funcs.insert(std::pair<std::string, client::function::type>
60  ("sumErrSq", errsumsq));
61 
62  std::string testexpr = "sumErrSq(\"resources/measurement_test.dat\", \"rms_x\", \"resources/test.stat\")";
63  boost::scoped_ptr<Expression> e(new Expression(testexpr, funcs));
64  Expressions::Result_t result;
65  EXPECT_NO_THROW({
66  result = e->evaluate(vars);
67  });
68 
69 
70  //XXX: expected uses the nearest (and NOT interpolated) rms_x values
71  ASSERT_NEAR(expected, boost::get<0>(result), 1e-6);
72  ASSERT_TRUE(boost::get<1>(result));
73  }
74 
75 }
76 
77 int main(int argc, char **argv) {
78  ::testing::InitGoogleTest(&argc, argv);
79  return RUN_ALL_TESTS();
80 }
constexpr double e
The value of .
Definition: Physics.h:40
Expression to be evaluated in the framework.
Definition: Expression.h:75
boost::tuple< double, bool > Result_t
Definition: Expression.h:37
Tps< T > sqrt(const Tps< T > &x)
Square root.
Definition: TpsMath.h:91
int main(int argc, char *argv[])
Definition: Main.cpp:107
boost::function< boost::tuple< double, bool >arguments_t)> type
Definition: function.hpp:21
std::map< std::string, double > variableDictionary_t
Definition: Expression.h:26
std::map< std::string, client::function::type > functionDictionary_t
Definition: Expression.h:27