Merge remote-tracking branch 'gerrit/release-4-6'
[alexxy/gromacs.git] / src / gromacs / trajectoryanalysis / tests / select.cpp
1 /*
2  *
3  *                This source code is part of
4  *
5  *                 G   R   O   M   A   C   S
6  *
7  *          GROningen MAchine for Chemical Simulations
8  *
9  * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
10  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
11  * Copyright (c) 2001-2009, The GROMACS development team,
12  * check out http://www.gromacs.org for more information.
13
14  * This program is free software; you can redistribute it and/or
15  * modify it under the terms of the GNU General Public License
16  * as published by the Free Software Foundation; either version 2
17  * of the License, or (at your option) any later version.
18  *
19  * If you want to redistribute modifications, please consider that
20  * scientific software is very special. Version control is crucial -
21  * bugs must be traceable. We will be happy to consider code for
22  * inclusion in the official distribution, but derived work must not
23  * be called official GROMACS. Details are found in the README & COPYING
24  * files - if they are missing, get the official version at www.gromacs.org.
25  *
26  * To help us fund GROMACS development, we humbly ask that you cite
27  * the papers on the package - you can find them in the top README file.
28  *
29  * For more info, check our website at http://www.gromacs.org
30  */
31 /*! \internal \file
32  * \brief
33  * Tests for functionality of the "select" trajectory analysis module.
34  *
35  * These tests test most of the functionality of the module, but currently
36  * missing are:
37  *  - Tests related to -oc output.  This would require a more complex input
38  *    structure for reasonable testing (the same structure could also be used
39  *    in selection unit tests for 'insolidangle' keyword).
40  *  - Tests for XVG labels.  This is a limitation of the current testing
41  *    framework.
42  *
43  * \author Teemu Murtola <teemu.murtola@cbr.su.se>
44  * \ingroup module_trajectoryanalysis
45  */
46 #include <gtest/gtest.h>
47
48 #include "gromacs/trajectoryanalysis/modules/select.h"
49
50 #include "testutils/cmdlinetest.h"
51
52 #include "moduletest.h"
53
54 namespace
55 {
56
57 using gmx::test::CommandLine;
58
59 /********************************************************************
60  * Tests for gmx::analysismodules::Select.
61  */
62
63 typedef gmx::test::TrajectoryAnalysisModuleTestFixture<gmx::analysismodules::Select>
64         SelectModuleTest;
65
66 TEST_F(SelectModuleTest, BasicTest)
67 {
68     const char *const cmdline[] = {
69         "select",
70         "-select", "y < 2.5", "resname RA"
71     };
72     setTopology("simple.gro");
73     setOutputFile("-oi", "index.dat");
74     setOutputFile("-on", "index.ndx");
75     excludeDataset("cfrac");
76     runTest(CommandLine::create(cmdline));
77 }
78
79 TEST_F(SelectModuleTest, HandlesDumpOption)
80 {
81     const char *const cmdline[] = {
82         "select",
83         "-select", "y < 2.5",
84         "-dump"
85     };
86     setTopology("simple.gro");
87     setOutputFile("-oi", "index.dat");
88     includeDataset("index");
89     runTest(CommandLine::create(cmdline));
90 }
91
92 TEST_F(SelectModuleTest, NormalizesSizes)
93 {
94     const char *const cmdline[] = {
95         "select",
96         "-select", "y < 2.5", "resname RA and y < 2.5", "resname RA",
97         "-norm"
98     };
99     setTopology("simple.gro");
100     includeDataset("size");
101     runTest(CommandLine::create(cmdline));
102 }
103
104 TEST_F(SelectModuleTest, WritesResidueNumbers)
105 {
106     const char *const cmdline[] = {
107         "select",
108         "-select", "res_com of resname RA RD"
109     };
110     setTopology("simple.gro");
111     includeDataset("index");
112     runTest(CommandLine::create(cmdline));
113 }
114
115 TEST_F(SelectModuleTest, WritesResidueIndices)
116 {
117     const char *const cmdline[] = {
118         "select",
119         "-select", "res_com of resname RA RD",
120         "-resnr", "index"
121     };
122     setTopology("simple.gro");
123     includeDataset("index");
124     runTest(CommandLine::create(cmdline));
125 }
126
127 } // namespace