2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 * and including many others, as listed in the AUTHORS file in the
7 * top-level source directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
37 * Tests for functionality of analysis data averaging modules.
39 * These tests check that gmx::AnalysisDataAverageModule and
40 * gmx::AnalysisDataFrameAverageModule compute averages correctly with simple
42 * Checking is done using gmx::test::AnalysisDataTestFixture and reference
43 * data. Also the input data is written to the reference data to catch
44 * out-of-date reference.
46 * \author Teemu Murtola <teemu.murtola@gmail.com>
47 * \ingroup module_analysisdata
51 #include "gromacs/analysisdata/modules/average.h"
53 #include <gtest/gtest.h>
55 #include "gromacs/analysisdata/analysisdata.h"
57 #include "gromacs/analysisdata/tests/datatest.h"
58 #include "testutils/testasserts.h"
60 using gmx::test::AnalysisDataTestInput
;
65 // Simple input data for gmx::AnalysisDataAverageModule tests.
69 static const AnalysisDataTestInput
&get()
71 #ifndef STATIC_ANON_NAMESPACE_BUG
72 static SimpleInputData singleton
;
73 return singleton
.data_
;
75 static SimpleInputData singleton_average
;
76 return singleton_average
.data_
;
80 SimpleInputData() : data_(1, false)
82 data_
.setColumnCount(0, 3);
83 data_
.addFrameWithValues(1.0, 0.0, 1.0, 2.0);
84 data_
.addFrameWithValues(2.0, 1.0, 1.0, 1.0);
85 data_
.addFrameWithValues(3.0, 2.0, 0.0, 0.0);
89 AnalysisDataTestInput data_
;
92 // Multipoint input data for gmx::AnalysisDataAverageModule tests.
93 class MultipointInputData
96 static const AnalysisDataTestInput
&get()
98 #ifndef STATIC_ANON_NAMESPACE_BUG
99 static MultipointInputData singleton
;
100 return singleton
.data_
;
102 static MultipointInputData singleton_average
;
103 return singleton_average
.data_
;
107 MultipointInputData() : data_(1, true)
109 using gmx::test::AnalysisDataTestInputFrame
;
110 data_
.setColumnCount(0, 3);
111 AnalysisDataTestInputFrame
&frame1
= data_
.addFrame(1.0);
112 frame1
.addPointSetWithValues(0, 0, 0.0, 1.0, 2.0);
113 frame1
.addPointSetWithValues(0, 0, 1.0, 0.0);
114 frame1
.addPointSetWithValues(0, 0, 2.0);
115 AnalysisDataTestInputFrame
&frame2
= data_
.addFrame(2.0);
116 frame2
.addPointSetWithValues(0, 0, 1.0, 1.0);
117 frame2
.addPointSetWithValues(0, 0, 2.0);
118 AnalysisDataTestInputFrame
&frame3
= data_
.addFrame(3.0);
119 frame3
.addPointSetWithValues(0, 0, 2.0, 0.0, 0.0);
123 AnalysisDataTestInput data_
;
126 // Input data with multiple data sets for gmx::AnalysisDataAverageModule tests.
127 class MultiDataSetInputData
130 static const AnalysisDataTestInput
&get()
132 #ifndef STATIC_ANON_NAMESPACE_BUG
133 static MultiDataSetInputData singleton
;
134 return singleton
.data_
;
136 static MultiDataSetInputData singleton_average
;
137 return singleton_average
.data_
;
141 MultiDataSetInputData() : data_(2, true)
143 using gmx::test::AnalysisDataTestInputFrame
;
144 data_
.setColumnCount(0, 3);
145 data_
.setColumnCount(1, 2);
146 AnalysisDataTestInputFrame
&frame1
= data_
.addFrame(1.0);
147 frame1
.addPointSetWithValues(0, 0, 0.0, 1.0, 2.0);
148 frame1
.addPointSetWithValues(0, 0, 1.0, 0.0);
149 frame1
.addPointSetWithValues(1, 0, 2.0, 1.0);
150 frame1
.addPointSetWithValues(1, 1, 2.0);
151 AnalysisDataTestInputFrame
&frame2
= data_
.addFrame(2.0);
152 frame2
.addPointSetWithValues(0, 0, 1.0, 1.0);
153 frame2
.addPointSetWithValues(0, 2, 2.0);
154 frame2
.addPointSetWithValues(1, 0, 1.0, 0.0);
155 AnalysisDataTestInputFrame
&frame3
= data_
.addFrame(3.0);
156 frame3
.addPointSetWithValues(0, 0, 2.0, 0.0, 0.0);
157 frame3
.addPointSetWithValues(1, 0, 0.0, 2.0);
161 AnalysisDataTestInput data_
;
165 /********************************************************************
166 * Tests for gmx::AnalysisDataAverageModule.
169 //! Test fixture for gmx::AnalysisDataAverageModule.
170 typedef gmx::test::AnalysisDataTestFixture AverageModuleTest
;
172 TEST_F(AverageModuleTest
, BasicTest
)
174 const AnalysisDataTestInput
&input
= SimpleInputData::get();
175 gmx::AnalysisData data
;
176 ASSERT_NO_THROW_GMX(setupDataObject(input
, &data
));
178 gmx::AnalysisDataAverageModulePointer
module(
179 new gmx::AnalysisDataAverageModule
);
180 data
.addModule(module
);
182 ASSERT_NO_THROW_GMX(addStaticCheckerModule(input
, &data
));
183 ASSERT_NO_THROW_GMX(addReferenceCheckerModule("InputData", &data
));
184 ASSERT_NO_THROW_GMX(addReferenceCheckerModule("Average", module
.get()));
185 ASSERT_NO_THROW_GMX(presentAllData(input
, &data
));
188 TEST_F(AverageModuleTest
, HandlesMultipointData
)
190 const AnalysisDataTestInput
&input
= MultipointInputData::get();
191 gmx::AnalysisData data
;
192 ASSERT_NO_THROW_GMX(setupDataObject(input
, &data
));
194 gmx::AnalysisDataAverageModulePointer
module(
195 new gmx::AnalysisDataAverageModule
);
196 data
.addModule(module
);
198 ASSERT_NO_THROW_GMX(addStaticCheckerModule(input
, &data
));
199 ASSERT_NO_THROW_GMX(addReferenceCheckerModule("InputData", &data
));
200 ASSERT_NO_THROW_GMX(addReferenceCheckerModule("Average", module
.get()));
201 ASSERT_NO_THROW_GMX(presentAllData(input
, &data
));
204 TEST_F(AverageModuleTest
, HandlesMultipleDataSets
)
206 const AnalysisDataTestInput
&input
= MultiDataSetInputData::get();
207 gmx::AnalysisData data
;
208 ASSERT_NO_THROW_GMX(setupDataObject(input
, &data
));
210 gmx::AnalysisDataAverageModulePointer
module(
211 new gmx::AnalysisDataAverageModule
);
212 data
.addModule(module
);
214 ASSERT_NO_THROW_GMX(addStaticCheckerModule(input
, &data
));
215 ASSERT_NO_THROW_GMX(addReferenceCheckerModule("InputData", &data
));
216 ASSERT_NO_THROW_GMX(addReferenceCheckerModule("Average", module
.get()));
217 ASSERT_NO_THROW_GMX(presentAllData(input
, &data
));
220 TEST_F(AverageModuleTest
, HandlesDataSetAveraging
)
222 const AnalysisDataTestInput
&input
= MultiDataSetInputData::get();
223 gmx::AnalysisData data
;
224 ASSERT_NO_THROW_GMX(setupDataObject(input
, &data
));
226 gmx::AnalysisDataAverageModulePointer
module(
227 new gmx::AnalysisDataAverageModule
);
228 module
->setAverageDataSets(true);
229 data
.addModule(module
);
231 ASSERT_NO_THROW_GMX(addStaticCheckerModule(input
, &data
));
232 ASSERT_NO_THROW_GMX(addReferenceCheckerModule("InputData", &data
));
233 ASSERT_NO_THROW_GMX(addReferenceCheckerModule("Average", module
.get()));
234 ASSERT_NO_THROW_GMX(presentAllData(input
, &data
));
237 TEST_F(AverageModuleTest
, CanCustomizeXAxis
)
239 const AnalysisDataTestInput
&input
= SimpleInputData::get();
240 gmx::AnalysisData data
;
241 ASSERT_NO_THROW_GMX(setupDataObject(input
, &data
));
243 gmx::AnalysisDataAverageModulePointer
module(new gmx::AnalysisDataAverageModule());
244 data
.addModule(module
);
245 module
->setXAxis(0.5, 0.5);
247 ASSERT_NO_THROW_GMX(addStaticCheckerModule(input
, &data
));
248 ASSERT_NO_THROW_GMX(addReferenceCheckerModule("InputData", &data
));
249 ASSERT_NO_THROW_GMX(addReferenceCheckerModule("Average", module
.get()));
250 ASSERT_NO_THROW_GMX(presentAllData(input
, &data
));
253 TEST_F(AverageModuleTest
, CanCustomizeNonUniformXAxis
)
255 const AnalysisDataTestInput
&input
= SimpleInputData::get();
256 gmx::AnalysisData data
;
257 ASSERT_NO_THROW_GMX(setupDataObject(input
, &data
));
259 gmx::AnalysisDataAverageModulePointer
module(new gmx::AnalysisDataAverageModule());
260 data
.addModule(module
);
261 module
->setXAxisValue(0, 2.0);
262 module
->setXAxisValue(1, 3.0);
263 module
->setXAxisValue(2, 5.0);
265 ASSERT_NO_THROW_GMX(addStaticCheckerModule(input
, &data
));
266 ASSERT_NO_THROW_GMX(addReferenceCheckerModule("InputData", &data
));
267 ASSERT_NO_THROW_GMX(addReferenceCheckerModule("Average", module
.get()));
268 ASSERT_NO_THROW_GMX(presentAllData(input
, &data
));
271 /********************************************************************
272 * Tests for gmx::AnalysisDataFrameAverageModule.
275 //! Test fixture for gmx::AnalysisDataFrameAverageModule.
276 typedef gmx::test::AnalysisDataTestFixture FrameAverageModuleTest
;
278 TEST_F(FrameAverageModuleTest
, BasicTest
)
280 const AnalysisDataTestInput
&input
= SimpleInputData::get();
281 gmx::AnalysisData data
;
282 ASSERT_NO_THROW_GMX(setupDataObject(input
, &data
));
284 gmx::AnalysisDataFrameAverageModulePointer
module(
285 new gmx::AnalysisDataFrameAverageModule
);
286 data
.addModule(module
);
288 ASSERT_NO_THROW_GMX(addStaticCheckerModule(input
, &data
));
289 ASSERT_NO_THROW_GMX(addReferenceCheckerModule("InputData", &data
));
290 ASSERT_NO_THROW_GMX(addReferenceCheckerModule("FrameAverage", module
.get()));
291 ASSERT_NO_THROW_GMX(presentAllData(input
, &data
));
294 TEST_F(FrameAverageModuleTest
, HandlesMultipleDataSets
)
296 const AnalysisDataTestInput
&input
= MultiDataSetInputData::get();
297 gmx::AnalysisData data
;
298 ASSERT_NO_THROW_GMX(setupDataObject(input
, &data
));
300 gmx::AnalysisDataFrameAverageModulePointer
module(
301 new gmx::AnalysisDataFrameAverageModule
);
302 data
.addModule(module
);
304 ASSERT_NO_THROW_GMX(addStaticCheckerModule(input
, &data
));
305 ASSERT_NO_THROW_GMX(addReferenceCheckerModule("InputData", &data
));
306 ASSERT_NO_THROW_GMX(addReferenceCheckerModule("FrameAverage", module
.get()));
307 ASSERT_NO_THROW_GMX(presentAllData(input
, &data
));