Update instructions in containers.rst
[gromacs.git] / src / gromacs / topology / tests / idef.cpp
blob77f0dbd11b20899203e403d4b80ca20cb32eae09
1 /*
2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2020, 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.
35 /*! \internal \file
36 * \brief
37 * Implements test of InteractionList routines
39 * \author Paul Bauer <paul.bauer.q@gmail.com>
40 * \ingroup module_topology
42 #include "gmxpre.h"
44 #include "gromacs/topology/idef.h"
46 #include <array>
48 #include <gtest/gtest.h>
50 namespace gmx
52 namespace
55 TEST(InteractionListTest, EmptyWorks)
57 InteractionList ilist;
58 EXPECT_TRUE(ilist.empty());
59 EXPECT_EQ(ilist.size(), 0);
62 TEST(InteractionListTest, CanAddInteractionArray)
64 InteractionList ilist;
65 int parameterType = 0;
66 std::array<int, 1> singleAtomList = { 1 };
67 ilist.push_back(parameterType, singleAtomList);
68 EXPECT_FALSE(ilist.empty());
69 EXPECT_EQ(ilist.size(), 2);
70 EXPECT_EQ(ilist.iatoms[0], parameterType);
71 EXPECT_EQ(ilist.iatoms[1], 1);
74 TEST(InteractionListTest, CanAddInteractionArrayMultipleAtoms)
76 InteractionList ilist;
77 int parameterType = 0;
78 std::array<int, 3> atomList = { 1, 2, 3 };
79 ilist.push_back(parameterType, atomList);
80 EXPECT_FALSE(ilist.empty());
81 EXPECT_EQ(ilist.size(), 4);
82 EXPECT_EQ(ilist.iatoms[0], parameterType);
83 EXPECT_EQ(ilist.iatoms[1], 1);
84 EXPECT_EQ(ilist.iatoms[2], 2);
85 EXPECT_EQ(ilist.iatoms[3], 3);
88 TEST(InteractionListTest, CanAddInteractionPointer)
90 InteractionList ilist;
91 int parameterType = 0;
92 std::array<int, 1> singleAtomList = { 1 };
93 ilist.push_back(parameterType, singleAtomList.size(), singleAtomList.data());
94 EXPECT_FALSE(ilist.empty());
95 EXPECT_EQ(ilist.size(), 2);
96 EXPECT_EQ(ilist.iatoms[0], parameterType);
97 EXPECT_EQ(ilist.iatoms[1], 1);
100 TEST(InteractionListTest, CanAddListToOtherList)
102 InteractionList firstList;
103 int firstParameterType = 0;
105 std::array<int, 1> singleAtomList = { 1 };
106 firstList.push_back(firstParameterType, singleAtomList);
107 EXPECT_FALSE(firstList.empty());
108 EXPECT_EQ(firstList.size(), 2);
109 EXPECT_EQ(firstList.iatoms[0], firstParameterType);
110 EXPECT_EQ(firstList.iatoms[1], 1);
112 InteractionList secondList;
113 int secondParameterType = 1;
115 std::array<int, 3> atomList = { 1, 2, 3 };
116 secondList.push_back(secondParameterType, atomList);
117 EXPECT_FALSE(secondList.empty());
118 EXPECT_EQ(secondList.size(), 4);
119 EXPECT_EQ(secondList.iatoms[0], secondParameterType);
120 EXPECT_EQ(secondList.iatoms[1], 1);
121 EXPECT_EQ(secondList.iatoms[2], 2);
122 EXPECT_EQ(secondList.iatoms[3], 3);
124 firstList.append(secondList);
125 EXPECT_EQ(firstList.size(), 6);
126 EXPECT_EQ(firstList.iatoms[2], secondParameterType);
127 EXPECT_EQ(firstList.iatoms[3], 1);
128 EXPECT_EQ(firstList.iatoms[4], 2);
129 EXPECT_EQ(firstList.iatoms[5], 3);
132 TEST(InteractionListTest, ClearingWorks)
134 InteractionList ilist;
135 int parameterType = 0;
136 std::array<int, 1> singleAtomList = { 1 };
137 ilist.push_back(parameterType, singleAtomList);
138 EXPECT_FALSE(ilist.empty());
139 EXPECT_EQ(ilist.size(), 2);
140 EXPECT_EQ(ilist.iatoms[0], parameterType);
141 EXPECT_EQ(ilist.iatoms[1], 1);
142 ilist.clear();
143 EXPECT_TRUE(ilist.empty());
144 EXPECT_EQ(ilist.size(), 0);
147 } // namespace
149 } // namespace gmx