1ea1551fd51d297bd8d23ef0a2ed112198349283
[alexxy/gromacs.git] / src / gromacs / analysisdata / tests / lifetime.cpp
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
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.
8  *
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.
13  *
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.
18  *
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.
23  *
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.
31  *
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.
34  */
35 /*! \internal \file
36  * \brief
37  * Tests for functionality of analysis data lifetime module.
38  *
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.
44  *
45  * \author Teemu Murtola <teemu.murtola@gmail.com>
46  * \ingroup module_analysisdata
47  */
48 #include <gtest/gtest.h>
49
50 #include "gromacs/analysisdata/analysisdata.h"
51 #include "gromacs/analysisdata/modules/lifetime.h"
52
53 #include "gromacs/analysisdata/tests/datatest.h"
54 #include "testutils/testasserts.h"
55
56 using gmx::test::AnalysisDataTestInput;
57
58 namespace
59 {
60
61 // Simple input data for gmx::AnalysisDataLifetimeModule tests.
62 class SimpleInputData
63 {
64     public:
65         static const AnalysisDataTestInput &get()
66         {
67 #ifndef INTEL_STATIC_ANON_NAMESPACE_BUG
68             static SimpleInputData singleton;
69             return singleton.data_;
70 #else
71             static SimpleInputData singleton_lifetime;
72             return singleton_lifetime.data_;
73 #endif
74         }
75
76         SimpleInputData() : data_(1, false)
77         {
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);
82         }
83
84     private:
85         AnalysisDataTestInput  data_;
86 };
87
88 // Input data with multiple data sets for gmx::AnalysisDataLifetimeModule tests.
89 class MultiDataSetInputData
90 {
91     public:
92         static const AnalysisDataTestInput &get()
93         {
94 #ifndef INTEL_STATIC_ANON_NAMESPACE_BUG
95             static MultiDataSetInputData singleton;
96             return singleton.data_;
97 #else
98             static MultiDataSetInputData singleton_lifetime;
99             return singleton_lifetime.data_;
100 #endif
101         }
102
103         MultiDataSetInputData() : data_(2, false)
104         {
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);
117         }
118
119     private:
120         AnalysisDataTestInput  data_;
121 };
122
123
124 /********************************************************************
125  * Tests for gmx::AnalysisDataLifetimeModule.
126  */
127
128 //! Test fixture for gmx::AnalysisDataLifetimeModule.
129 typedef gmx::test::AnalysisDataTestFixture LifetimeModuleTest;
130
131 TEST_F(LifetimeModuleTest, BasicTest)
132 {
133     const AnalysisDataTestInput &input = SimpleInputData::get();
134     gmx::AnalysisData            data;
135     ASSERT_NO_THROW_GMX(setupDataObject(input, &data));
136
137     gmx::AnalysisDataLifetimeModulePointer module(
138             new gmx::AnalysisDataLifetimeModule);
139     module->setCumulative(false);
140     data.addModule(module);
141
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));
146 }
147
148 TEST_F(LifetimeModuleTest, CumulativeTest)
149 {
150     const AnalysisDataTestInput &input = SimpleInputData::get();
151     gmx::AnalysisData            data;
152     ASSERT_NO_THROW_GMX(setupDataObject(input, &data));
153
154     gmx::AnalysisDataLifetimeModulePointer module(
155             new gmx::AnalysisDataLifetimeModule);
156     module->setCumulative(true);
157     data.addModule(module);
158
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));
163 }
164
165 TEST_F(LifetimeModuleTest, HandlesMultipleDataSets)
166 {
167     const AnalysisDataTestInput &input = MultiDataSetInputData::get();
168     gmx::AnalysisData            data;
169     ASSERT_NO_THROW_GMX(setupDataObject(input, &data));
170
171     gmx::AnalysisDataLifetimeModulePointer module(
172             new gmx::AnalysisDataLifetimeModule);
173     module->setCumulative(false);
174     data.addModule(module);
175
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));
180 }
181
182 } // namespace