2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2014,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.
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.
37 * Tests for bitmask functionality.
39 * These tests check the functionality of bitmask.h
41 * \author Roland Schulz <roland@rschulz.eu>
42 * \ingroup module_utility
44 #include <gtest/gtest.h>
46 #include "gromacs/utility/bitmask.h"
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)
57 class BITMASK_CLASSNAME(BITMASK_SIZE) : public ::testing::TestWithParam<int>
61 BITMASK_TEST_P(SetAndClear) //NOLINT(misc-definitions-in-headers)
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++)
71 EXPECT_EQ(bitmask_is_set(m, j), j == i);
74 EXPECT_TRUE(bitmask_is_zero(m));
77 BITMASK_TEST_P(InitBit) //NOLINT(misc-definitions-in-headers)
81 bitmask_init_bit(&m1, i);
83 EXPECT_FALSE(bitmask_is_equal(m1, m2));
84 bitmask_set_bit(&m2, i);
85 EXPECT_TRUE(bitmask_is_equal(m1, m2));
88 BITMASK_TEST_P(InitLowBits) //NOLINT(misc-definitions-in-headers)
92 bitmask_init_low_bits(&m, i);
93 for (int j = 0; j < BITMASK_SIZE; j++)
95 EXPECT_EQ(bitmask_is_set(m, j), j < i);
99 BITMASK_TEST_P(Disjoint) //NOLINT(misc-definitions-in-headers)
101 gmx_bitmask_t m1, m2;
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));
110 BITMASK_TEST_P(Union) //NOLINT(misc-definitions-in-headers)
112 gmx_bitmask_t m1, m2;
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++)
120 EXPECT_EQ(bitmask_is_set(m1, k), k == i || k == j);
123 bitmask_init_bit(&m1, i);
125 bitmask_union(&m1, m2);
126 bitmask_init_bit(&m2, i);
127 EXPECT_TRUE(bitmask_is_equal(m1, m2));
130 bitmask_init_bit(&m2, i);
131 bitmask_union(&m1, m2);
132 EXPECT_TRUE(bitmask_is_equal(m1, m2));