/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2015,2016,2017,2018,2019, by the GROMACS development team, led by
+ * Copyright (c) 2015,2016,2017,2018,2019 by the GROMACS development team.
+ * Copyright (c) 2021, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
}
}
+template<typename T>
+class FunctionTestIntegerTypes : public ::testing::Test
+{
+};
+
+typedef ::testing::Types<char, unsigned char, int, unsigned int, long, unsigned long> IntegerTypes;
+TYPED_TEST_CASE(FunctionTestIntegerTypes, IntegerTypes);
+
+TYPED_TEST(FunctionTestIntegerTypes, IsPowerOfTwo)
+{
+ if (std::is_signed_v<TypeParam>)
+ {
+ EXPECT_EQ(false, gmx::isPowerOfTwo<TypeParam>(std::numeric_limits<TypeParam>::min()));
+ EXPECT_EQ(false, gmx::isPowerOfTwo<TypeParam>(-16));
+ EXPECT_EQ(false, gmx::isPowerOfTwo<TypeParam>(-3));
+ EXPECT_EQ(false, gmx::isPowerOfTwo<TypeParam>(-2));
+ EXPECT_EQ(false, gmx::isPowerOfTwo<TypeParam>(-1));
+ }
+ EXPECT_EQ(false, gmx::isPowerOfTwo<TypeParam>(0));
+ EXPECT_EQ(true, gmx::isPowerOfTwo<TypeParam>(1));
+ EXPECT_EQ(true, gmx::isPowerOfTwo<TypeParam>(2));
+ EXPECT_EQ(false, gmx::isPowerOfTwo<TypeParam>(3));
+ EXPECT_EQ(true, gmx::isPowerOfTwo<TypeParam>(4));
+ EXPECT_EQ(false, gmx::isPowerOfTwo<TypeParam>(5));
+ EXPECT_EQ(false, gmx::isPowerOfTwo<TypeParam>(6));
+ EXPECT_EQ(false, gmx::isPowerOfTwo<TypeParam>(24));
+ EXPECT_EQ(false, gmx::isPowerOfTwo<TypeParam>(63));
+ EXPECT_EQ(true, gmx::isPowerOfTwo<TypeParam>(64));
+ EXPECT_EQ(false, gmx::isPowerOfTwo<TypeParam>(66));
+ // Max for any type is always 2^x - 1
+ EXPECT_EQ(false, gmx::isPowerOfTwo<TypeParam>(std::numeric_limits<TypeParam>::max()));
+}
+
} // namespace