2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2014, 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>
43 #include <gtest/gtest.h>
45 #include "gromacs/mdlib/bitmask.h"
47 //! Implemenation of BITMASK_CLASSNAME
48 #define BITMASK_CLASSNAME_(S) BitmaskTest ## S
49 //! Returns name of Bitmask test fixture class
50 #define BITMASK_CLASSNAME(S) BITMASK_CLASSNAME_(S)
51 //! Implementation of BITMASK_TEST_P
52 #define BITMASK_TEST_P_(C, T) TEST_P(C, T)
53 //! Defines a parameterized bitmask test
54 #define BITMASK_TEST_P(T) BITMASK_TEST_P_(BITMASK_CLASSNAME(BITMASK_SIZE), T)
56 class BITMASK_CLASSNAME(BITMASK_SIZE) : public ::testing::TestWithParam<int>
60 BITMASK_TEST_P(SetAndClear)
65 EXPECT_TRUE(bitmask_is_zero(m));
66 EXPECT_FALSE(bitmask_is_set(m, i));
67 bitmask_set_bit(&m, i);
68 for (int j = 0; j < BITMASK_SIZE; j++)
70 EXPECT_EQ(bitmask_is_set(m, j), j == i);
73 EXPECT_TRUE(bitmask_is_zero(m));
76 BITMASK_TEST_P(InitBit)
80 bitmask_init_bit(&m1, i);
82 EXPECT_FALSE(bitmask_is_equal(m1, m2));
83 bitmask_set_bit(&m2, i);
84 EXPECT_TRUE(bitmask_is_equal(m1, m2));
87 BITMASK_TEST_P(InitLowBits)
91 bitmask_init_low_bits(&m, i);
92 for (int j = 0; j < BITMASK_SIZE; j++)
94 EXPECT_EQ(bitmask_is_set(m, j), j < i);
98 BITMASK_TEST_P(Disjoint)
100 gmx_bitmask_t m1, m2;
102 bitmask_init_bit(&m1, i);
103 bitmask_init_bit(&m2, i);
104 EXPECT_FALSE(bitmask_is_disjoint(m1, m2));
105 bitmask_init_low_bits(&m2, i);
106 EXPECT_TRUE(bitmask_is_disjoint(m1, m2));
109 BITMASK_TEST_P(Union)
111 gmx_bitmask_t m1, m2;
113 int j = (i + BITMASK_SIZE/2)%BITMASK_SIZE;
114 bitmask_init_bit(&m1, i);
115 bitmask_init_bit(&m2, j);
116 bitmask_union(&m1, m2);
117 for (int k = 0; k < BITMASK_SIZE; k++)
119 EXPECT_EQ(bitmask_is_set(m1, k), k == i || k == j);
122 bitmask_init_bit(&m1, i);
124 bitmask_union(&m1, m2);
125 bitmask_init_bit(&m2, i);
126 EXPECT_TRUE(bitmask_is_equal(m1, m2));
129 bitmask_init_bit(&m2, i);
130 bitmask_union(&m1, m2);
131 EXPECT_TRUE(bitmask_is_equal(m1, m2));