SYCL: Avoid using no_init read accessor in rocFFT
[alexxy/gromacs.git] / src / gromacs / utility / tests / bitmask.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2014,2018,2019,2021, 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 bitmask functionality.
38  *
39  * These tests check the functionality of bitmask.h
40
41  * \author Roland Schulz <roland@rschulz.eu>
42  * \ingroup module_utility
43  */
44 #include <gtest/gtest.h>
45
46 #include "gromacs/utility/bitmask.h"
47
48 //! Implemenation of BITMASK_CLASSNAME
49 #define BITMASK_CLASSNAME_(S) BitmaskTest##S
50 //! Returns name of Bitmask test fixture class
51 #define BITMASK_CLASSNAME(S) BITMASK_CLASSNAME_(S)
52 //! Implementation of BITMASK_TEST_P
53 #define BITMASK_TEST_P_(C, T) TEST_P(C, T)
54 //! Defines a parameterized bitmask test
55 #define BITMASK_TEST_P(T) BITMASK_TEST_P_(BITMASK_CLASSNAME(BITMASK_SIZE), T)
56
57 class BITMASK_CLASSNAME(BITMASK_SIZE) : public ::testing::TestWithParam<int>
58 {
59 };
60
61 BITMASK_TEST_P(SetAndClear) //NOLINT(misc-definitions-in-headers)
62 {
63     gmx_bitmask_t m; //NOLINT(cppcoreguidelines-init-variables)
64     int           i = GetParam();
65     bitmask_clear(&m);
66     EXPECT_TRUE(bitmask_is_zero(m));
67     EXPECT_FALSE(bitmask_is_set(m, i));
68     bitmask_set_bit(&m, i);
69     for (int j = 0; j < BITMASK_SIZE; j++)
70     {
71         EXPECT_EQ(bitmask_is_set(m, j), j == i);
72     }
73     bitmask_clear(&m);
74     EXPECT_TRUE(bitmask_is_zero(m));
75 }
76
77 BITMASK_TEST_P(InitBit) //NOLINT(misc-definitions-in-headers)
78 {
79     gmx_bitmask_t m1, m2; //NOLINT(cppcoreguidelines-init-variables)
80     int           i = GetParam();
81     bitmask_init_bit(&m1, i);
82     bitmask_clear(&m2);
83     EXPECT_FALSE(bitmask_is_equal(m1, m2));
84     bitmask_set_bit(&m2, i);
85     EXPECT_TRUE(bitmask_is_equal(m1, m2));
86 }
87
88 BITMASK_TEST_P(InitLowBits) //NOLINT(misc-definitions-in-headers)
89 {
90     gmx_bitmask_t m; //NOLINT(cppcoreguidelines-init-variables)
91     int           i = GetParam();
92     bitmask_init_low_bits(&m, i);
93     for (int j = 0; j < BITMASK_SIZE; j++)
94     {
95         EXPECT_EQ(bitmask_is_set(m, j), j < i);
96     }
97 }
98
99 BITMASK_TEST_P(Disjoint) //NOLINT(misc-definitions-in-headers)
100 {
101     gmx_bitmask_t m1, m2; //NOLINT(cppcoreguidelines-init-variables)
102     int           i = GetParam();
103     bitmask_init_bit(&m1, i);
104     bitmask_init_bit(&m2, i);
105     EXPECT_FALSE(bitmask_is_disjoint(m1, m2));
106     bitmask_init_low_bits(&m2, i);
107     EXPECT_TRUE(bitmask_is_disjoint(m1, m2));
108 }
109
110 BITMASK_TEST_P(Union) //NOLINT(misc-definitions-in-headers)
111 {
112     gmx_bitmask_t m1, m2; //NOLINT(cppcoreguidelines-init-variables)
113     int           i = GetParam();
114     int           j = (i + BITMASK_SIZE / 2) % BITMASK_SIZE;
115     bitmask_init_bit(&m1, i);
116     bitmask_init_bit(&m2, j);
117     bitmask_union(&m1, m2);
118     for (int k = 0; k < BITMASK_SIZE; k++)
119     {
120         EXPECT_EQ(bitmask_is_set(m1, k), k == i || k == j);
121     }
122
123     bitmask_init_bit(&m1, i);
124     bitmask_clear(&m2);
125     bitmask_union(&m1, m2);
126     bitmask_init_bit(&m2, i);
127     EXPECT_TRUE(bitmask_is_equal(m1, m2));
128
129     bitmask_clear(&m1);
130     bitmask_init_bit(&m2, i);
131     bitmask_union(&m1, m2);
132     EXPECT_TRUE(bitmask_is_equal(m1, m2));
133 }
134 BITMASK_TEST_P(ToHex) //NOLINT(misc-definitions-in-headers)
135 {
136     gmx_bitmask_t m; //NOLINT(cppcoreguidelines-init-variables)
137     bitmask_clear(&m);
138     bitmask_set_bit(&m, BITMASK_SIZE - 1);
139     EXPECT_EQ(to_hex_string(m), "8" + std::string(BITMASK_SIZE / 4 - 1, '0'));
140 }