clang-tidy: google tests applicable
[alexxy/gromacs.git] / src / gromacs / trajectoryanalysis / tests / clustsize.cpp
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2017,2018, 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 gmx clustsize
38  *
39  * \todo These will be superseded by tests of the new style analysis
40  * modules.
41  *
42  * \author David van der Spoel <david.vanderspoel@icm.uu.se>
43  * \ingroup module_trajectoryanalysis
44  */
45
46 #include "gmxpre.h"
47
48 #include <cstring>
49
50 #include <string>
51
52 #include "gromacs/gmxana/gmx_ana.h"
53
54 #include "testutils/cmdlinetest.h"
55 #include "testutils/refdata.h"
56 #include "testutils/testasserts.h"
57 #include "testutils/textblockmatchers.h"
58 #include "testutils/xvgtest.h"
59
60 namespace gmx
61 {
62
63 namespace test
64 {
65
66 namespace
67 {
68
69 class ClustsizeTest : public CommandLineTestBase
70 {
71     public:
72         ClustsizeTest()
73         {
74             double            tolerance = 1e-4;
75             test::XvgMatch    xvg;
76             test::XvgMatch   &toler     = xvg.tolerance(gmx::test::relativeToleranceAsFloatingPoint(1, tolerance));
77
78             setOutputFile("-mc", ".xvg", toler);
79             setOutputFile("-nc", ".xvg", toler);
80             setOutputFile("-ac", ".xvg", toler);
81             setOutputFile("-hc", ".xvg", toler);
82             setInputFile("-f", "clustsize.pdb");
83         }
84
85         void runTest(const CommandLine &args)
86         {
87             CommandLine &cmdline = commandLine();
88             cmdline.merge(args);
89
90             gmx::test::TestReferenceChecker rootChecker(this->rootChecker());
91             rootChecker.checkString(args.toString(), "CommandLine");
92
93             ASSERT_EQ(0, gmx_clustsize(cmdline.argc(), cmdline.argv()));
94
95             checkOutputFiles();
96         }
97 };
98
99 TEST_F(ClustsizeTest, NoMolDefaultCutoff)
100 {
101     const char *const command[] = { "clustsize" };
102     CommandLine       args      = CommandLine(command);
103
104     setInputFile("-n", "clustsize.ndx");
105
106     runTest(args);
107 }
108
109 TEST_F(ClustsizeTest, NoMolShortCutoff)
110 {
111     const char *const command[] = { "clustsize", "-cut", "0.3" };
112     CommandLine       args      = CommandLine(command);
113
114     setInputFile("-n", "clustsize.ndx");
115
116     runTest(args);
117 }
118
119 TEST_F(ClustsizeTest, MolDefaultCutoff)
120 {
121     const char *const command[] = { "clustsize", "-mol" };
122     CommandLine       args      = CommandLine(command);
123
124     setInputFile("-s", "clustsize.tpr");
125
126     runTest(args);
127 }
128
129 TEST_F(ClustsizeTest, MolShortCutoff)
130 {
131     const char *const command[] = { "clustsize", "-mol", "-cut", "0.3" };
132     CommandLine       args      = CommandLine(command);
133
134     setInputFile("-s", "clustsize.tpr");
135
136     runTest(args);
137 }
138
139 TEST_F(ClustsizeTest, MolCSize)
140 {
141     const char *const command[] = { "clustsize", "-mol", "-nlevels", "6" };
142     CommandLine       args      = CommandLine(command);
143
144     setOutputFile("-o", ".xpm", ExactTextMatch());
145     setOutputFile("-ow", ".xpm", ExactTextMatch());
146
147     setInputFile("-s", "clustsize.tpr");
148
149     runTest(args);
150 }
151
152 } // namespace
153
154 } // namespace test
155
156 } // namespace gmx