SYCL: Avoid using no_init read accessor in rocFFT
[alexxy/gromacs.git] / src / gromacs / utility / tests / fixedcapacityvector.cpp
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2019, 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 Tests for gmx::FixedCapacityVector
37  *
38  * \author Berk Hess <hess@kth.se>
39  * \ingroup module_utility
40  */
41 #include "gmxpre.h"
42
43 #include "gromacs/utility/fixedcapacityvector.h"
44
45 #include <gtest/gtest.h>
46
47 #include "gromacs/utility/basedefinitions.h"
48
49 namespace gmx
50 {
51
52 namespace
53 {
54
55 TEST(FixedCapacityVectorTest, IsEmpty)
56 {
57     FixedCapacityVector<int, 2> empty;
58
59     EXPECT_EQ(0U, empty.size());
60     EXPECT_TRUE(empty.empty());
61 }
62
63 TEST(FixedCapacityVectorTest, PushWorks)
64 {
65     FixedCapacityVector<int, 2> v;
66
67     v.push_back(8);
68     EXPECT_EQ(1U, v.size());
69     EXPECT_EQ(8, v[0]);
70
71     v.push_back(5);
72     EXPECT_EQ(2U, v.size());
73     EXPECT_EQ(8, v[0]);
74     EXPECT_EQ(5, v[1]);
75 }
76
77 TEST(FixedCapacityVectorTest, PopWorks)
78 {
79     FixedCapacityVector<int, 3> v;
80
81     v.push_back(8);
82     EXPECT_EQ(1U, v.size());
83
84     v.pop_back();
85     EXPECT_EQ(0U, v.size());
86     EXPECT_TRUE(v.empty());
87 }
88
89 TEST(FixedCapacityVectorTest, ClearWorks)
90 {
91     FixedCapacityVector<int, 3> v;
92
93     v.push_back(8);
94     EXPECT_EQ(1U, v.size());
95
96     v.clear();
97     EXPECT_EQ(0U, v.size());
98     EXPECT_TRUE(v.empty());
99 }
100
101 TEST(FixedCapacityVectorTest, EmplaceBackWorks)
102 {
103     FixedCapacityVector<std::vector<int>, 2> v;
104
105     const auto& elem = v.emplace_back(5);
106     EXPECT_EQ(1U, v.size());
107     EXPECT_EQ(5U, elem.size());
108 }
109
110 TEST(FixedCapacityVectorTest, AtThrows)
111 {
112     FixedCapacityVector<int, 3> v;
113
114     v.push_back(8);
115     EXPECT_EQ(8, v.at(0));
116
117     EXPECT_THROW(v.at(1), std::out_of_range);
118 }
119
120 TEST(FixedCapacityVectorTest, IteratorWorks)
121 {
122     FixedCapacityVector<int, 4> v;
123
124     std::vector<int> ref = { 7, 4, 5 };
125
126     for (auto elem : ref)
127     {
128         v.push_back(elem);
129     }
130     EXPECT_EQ(3U, v.size());
131
132     std::vector<int> loopResult;
133     for (auto elem : v)
134     {
135         loopResult.push_back(elem);
136     }
137     EXPECT_EQ(3U, loopResult.size());
138     EXPECT_EQ(ref[0], loopResult[0]);
139     EXPECT_EQ(ref[1], loopResult[1]);
140     EXPECT_EQ(ref[2], loopResult[2]);
141 }
142
143 TEST(FixedCapacityVectorTest, ReverseIteratorWorks)
144 {
145     FixedCapacityVector<int, 4> v;
146
147     std::vector<int> ref = { 7, 4, 5 };
148
149     for (auto elem : ref)
150     {
151         v.push_back(elem);
152     }
153     EXPECT_EQ(3U, v.size());
154
155     std::vector<int> loopResult;
156     for (auto it = v.rbegin(); it != v.rend(); ++it)
157     {
158         loopResult.push_back(*it);
159     }
160     EXPECT_EQ(3U, loopResult.size());
161     EXPECT_EQ(ref[0], loopResult[2]);
162     EXPECT_EQ(ref[1], loopResult[1]);
163     EXPECT_EQ(ref[2], loopResult[0]);
164 }
165
166 TEST(FixedCapacityVectorTest, ZeroCapacityWorks)
167 {
168     FixedCapacityVector<int, 0> v;
169
170     EXPECT_EQ(0U, v.size());
171     EXPECT_TRUE(v.empty());
172 }
173
174 } // namespace
175
176 } // namespace gmx