2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 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 lifetime module.
39 * These tests check that gmx::AnalysisDataLifetimeModule computes lifetimes
40 * correctly with simple input data.
41 * Checking is done using gmx::test::AnalysisDataTestFixture and reference
42 * data. Also the input data is written to the reference data to catch
43 * out-of-date reference.
45 * \author Teemu Murtola <teemu.murtola@gmail.com>
46 * \ingroup module_analysisdata
48 #include <gtest/gtest.h>
50 #include "gromacs/analysisdata/analysisdata.h"
51 #include "gromacs/analysisdata/modules/lifetime.h"
53 #include "gromacs/analysisdata/tests/datatest.h"
54 #include "testutils/testasserts.h"
56 using gmx::test::AnalysisDataTestInput;
61 // Simple input data for gmx::AnalysisDataLifetimeModule tests.
65 static const AnalysisDataTestInput &get()
67 #ifndef STATIC_ANON_NAMESPACE_BUG
68 static SimpleInputData singleton;
69 return singleton.data_;
71 static SimpleInputData singleton_lifetime;
72 return singleton_lifetime.data_;
76 SimpleInputData() : data_(1, false)
78 data_.setColumnCount(0, 3);
79 data_.addFrameWithValues(1.0, 1.0, 1.0, 1.0);
80 data_.addFrameWithValues(2.0, 1.0, 0.0, 1.0);
81 data_.addFrameWithValues(3.0, 0.0, 1.0, 1.0);
85 AnalysisDataTestInput data_;
88 // Input data with multiple data sets for gmx::AnalysisDataLifetimeModule tests.
89 class MultiDataSetInputData
92 static const AnalysisDataTestInput &get()
94 #ifndef STATIC_ANON_NAMESPACE_BUG
95 static MultiDataSetInputData singleton;
96 return singleton.data_;
98 static MultiDataSetInputData singleton_lifetime;
99 return singleton_lifetime.data_;
103 MultiDataSetInputData() : data_(2, false)
105 using gmx::test::AnalysisDataTestInputFrame;
106 data_.setColumnCount(0, 2);
107 data_.setColumnCount(1, 2);
108 AnalysisDataTestInputFrame &frame1 = data_.addFrame(1.0);
109 frame1.addPointSetWithValues(0, 0, 1.0, 1.0);
110 frame1.addPointSetWithValues(1, 0, 0.0, 0.0);
111 AnalysisDataTestInputFrame &frame2 = data_.addFrame(2.0);
112 frame2.addPointSetWithValues(0, 0, 1.0, 0.0);
113 frame2.addPointSetWithValues(1, 0, 1.0, 0.0);
114 AnalysisDataTestInputFrame &frame3 = data_.addFrame(3.0);
115 frame3.addPointSetWithValues(0, 0, 1.0, 0.0);
116 frame3.addPointSetWithValues(1, 0, 1.0, 1.0);
120 AnalysisDataTestInput data_;
124 /********************************************************************
125 * Tests for gmx::AnalysisDataLifetimeModule.
128 //! Test fixture for gmx::AnalysisDataLifetimeModule.
129 typedef gmx::test::AnalysisDataTestFixture LifetimeModuleTest;
131 TEST_F(LifetimeModuleTest, BasicTest)
133 const AnalysisDataTestInput &input = SimpleInputData::get();
134 gmx::AnalysisData data;
135 ASSERT_NO_THROW_GMX(setupDataObject(input, &data));
137 gmx::AnalysisDataLifetimeModulePointer module(
138 new gmx::AnalysisDataLifetimeModule);
139 module->setCumulative(false);
140 data.addModule(module);
142 ASSERT_NO_THROW_GMX(addStaticCheckerModule(input, &data));
143 ASSERT_NO_THROW_GMX(addReferenceCheckerModule("InputData", &data));
144 ASSERT_NO_THROW_GMX(addReferenceCheckerModule("Lifetime", module.get()));
145 ASSERT_NO_THROW_GMX(presentAllData(input, &data));
148 TEST_F(LifetimeModuleTest, CumulativeTest)
150 const AnalysisDataTestInput &input = SimpleInputData::get();
151 gmx::AnalysisData data;
152 ASSERT_NO_THROW_GMX(setupDataObject(input, &data));
154 gmx::AnalysisDataLifetimeModulePointer module(
155 new gmx::AnalysisDataLifetimeModule);
156 module->setCumulative(true);
157 data.addModule(module);
159 ASSERT_NO_THROW_GMX(addStaticCheckerModule(input, &data));
160 ASSERT_NO_THROW_GMX(addReferenceCheckerModule("InputData", &data));
161 ASSERT_NO_THROW_GMX(addReferenceCheckerModule("Lifetime", module.get()));
162 ASSERT_NO_THROW_GMX(presentAllData(input, &data));
165 TEST_F(LifetimeModuleTest, HandlesMultipleDataSets)
167 const AnalysisDataTestInput &input = MultiDataSetInputData::get();
168 gmx::AnalysisData data;
169 ASSERT_NO_THROW_GMX(setupDataObject(input, &data));
171 gmx::AnalysisDataLifetimeModulePointer module(
172 new gmx::AnalysisDataLifetimeModule);
173 module->setCumulative(false);
174 data.addModule(module);
176 ASSERT_NO_THROW_GMX(addStaticCheckerModule(input, &data));
177 ASSERT_NO_THROW_GMX(addReferenceCheckerModule("InputData", &data));
178 ASSERT_NO_THROW_GMX(addReferenceCheckerModule("Lifetime", module.get()));
179 ASSERT_NO_THROW_GMX(presentAllData(input, &data));