OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
SDDSParserTest.cpp
Go to the documentation of this file.
1 //
2 // Test SDDSParserTest
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 "Util/SDDSReader.h"
22 #include "gtest/gtest.h"
23 
24 
25 namespace {
26 
27  // The fixture for testing class Foo.
28  class SDDSParserTest : public ::testing::Test {
29  protected:
30 
31  SDDSParserTest() {
32  // You can do set-up work for each test here.
33  sddsr = new SDDSReader("resources/test.stat");
34  }
35 
36  virtual ~SDDSParserTest() {
37  // You can do clean-up work that doesn't throw exceptions here.
38  delete sddsr;
39  }
40 
41  // If the constructor and destructor are not enough for setting up
42  // and cleaning up each test, you can define the following methods:
43 
44  virtual void SetUp() {
45  // Code here will be called immediately after the constructor (right
46  // before each test).
47  sddsr->parseFile();
48  }
49 
50  virtual void TearDown() {
51  // Code here will be called immediately after each test (right
52  // before the destructor).
53  }
54 
55  // Objects declared here can be used by all tests in the test case
56  SDDSReader *sddsr;
57  };
58 
59  TEST_F(SDDSParserTest, ReadEnergy) {
60 
61  double energy = 0.0;
62  std::string s = "energy";
63  sddsr->getValue(1, s, energy);
64 
65  double expected = 2.220252349855340e-01;
66  ASSERT_DOUBLE_EQ(expected, energy);
67  }
68 
69  TEST_F(SDDSParserTest, ReadLastPosition) {
70 
71  double position = 0.0;
72  std::string s = "s";
73  sddsr->getValue(-1, s, position);
74 
75  double expected = 4.247573354842603e-03;
76  ASSERT_DOUBLE_EQ(expected, position);
77  }
78 
79  TEST_F(SDDSParserTest, InterpolateRms_x) {
80 
81  double spos = 4.0e-03;
82  double rmsx_interp = 0.0;
83 
84  EXPECT_NO_THROW({
85  sddsr->getInterpolatedValue(spos, "rms_x", rmsx_interp);
86  });
87 
88  double spos_before = 3.786226707177705e-03;
89  double spos_after = 4.015012129060398e-03;
90  double rmsx_before = 3.147090549966750e-04;
91  double rmsx_after = 3.166390884805550e-04;
92 
93  double expected = rmsx_before + (spos - spos_before) * (rmsx_after - rmsx_before) / (spos_after - spos_before);
94 
95  ASSERT_DOUBLE_EQ(expected, rmsx_interp);
96  }
97 
98 }
99 
100 int main(int argc, char **argv) {
101  ::testing::InitGoogleTest(&argc, argv);
102  return RUN_ALL_TESTS();
103 }
104 
int main(int argc, char **argv)
void getValue(int t, std::string column_name, T &nval)
Definition: SDDSParser.h:85