Consistently have the namespace closing comment
[folly.git] / folly / test / ConstexprMathTest.cpp
1 /*
2  * Copyright 2017 Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <folly/ConstexprMath.h>
18
19 #include <folly/portability/GTest.h>
20
21 namespace {
22
23 class ConstexprMathTest : public testing::Test {};
24 } // namespace
25
26 TEST_F(ConstexprMathTest, constexpr_min) {
27   constexpr auto x = uint16_t(3);
28   constexpr auto y = uint16_t(7);
29   constexpr auto z = uint16_t(4);
30   constexpr auto a = folly::constexpr_min(x, y, z);
31   EXPECT_EQ(3, a);
32   EXPECT_TRUE((std::is_same<const uint16_t, decltype(a)>::value));
33 }
34
35 TEST_F(ConstexprMathTest, constexpr_max) {
36   constexpr auto x = uint16_t(3);
37   constexpr auto y = uint16_t(7);
38   constexpr auto z = uint16_t(4);
39   constexpr auto a = folly::constexpr_max(x, y, z);
40   EXPECT_EQ(7, a);
41   EXPECT_TRUE((std::is_same<const uint16_t, decltype(a)>::value));
42 }
43
44 TEST_F(ConstexprMathTest, constexpr_abs_unsigned) {
45   constexpr auto v = uint32_t(17);
46   constexpr auto a = folly::constexpr_abs(v);
47   EXPECT_EQ(17, a);
48   EXPECT_TRUE((std::is_same<const uint32_t, decltype(a)>::value));
49 }
50
51 TEST_F(ConstexprMathTest, constexpr_abs_signed_positive) {
52   constexpr auto v = int32_t(17);
53   constexpr auto a = folly::constexpr_abs(v);
54   EXPECT_EQ(17, a);
55   EXPECT_TRUE((std::is_same<const uint32_t, decltype(a)>::value));
56 }
57
58 TEST_F(ConstexprMathTest, constexpr_abs_signed_negative) {
59   constexpr auto v = int32_t(-17);
60   constexpr auto a = folly::constexpr_abs(v);
61   EXPECT_EQ(17, a);
62   EXPECT_TRUE((std::is_same<const uint32_t, decltype(a)>::value));
63 }
64
65 TEST_F(ConstexprMathTest, constexpr_abs_float_positive) {
66   constexpr auto v = 17.5f;
67   constexpr auto a = folly::constexpr_abs(v);
68   EXPECT_EQ(17.5, a);
69   EXPECT_TRUE((std::is_same<const float, decltype(a)>::value));
70 }
71
72 TEST_F(ConstexprMathTest, constexpr_abs_float_negative) {
73   constexpr auto v = -17.5f;
74   constexpr auto a = folly::constexpr_abs(v);
75   EXPECT_EQ(17.5, a);
76   EXPECT_TRUE((std::is_same<const float, decltype(a)>::value));
77 }
78
79 TEST_F(ConstexprMathTest, constexpr_abs_double_positive) {
80   constexpr auto v = 17.5;
81   constexpr auto a = folly::constexpr_abs(v);
82   EXPECT_EQ(17.5, a);
83   EXPECT_TRUE((std::is_same<const double, decltype(a)>::value));
84 }
85
86 TEST_F(ConstexprMathTest, constexpr_abs_double_negative) {
87   constexpr auto v = -17.5;
88   constexpr auto a = folly::constexpr_abs(v);
89   EXPECT_EQ(17.5, a);
90   EXPECT_TRUE((std::is_same<const double, decltype(a)>::value));
91 }
92
93 TEST_F(ConstexprMathTest, constexpr_log2_1) {
94   constexpr auto v = 1ull;
95   constexpr auto a = folly::constexpr_log2(v);
96   EXPECT_EQ(0ull, a);
97   EXPECT_TRUE((std::is_same<decltype(v), decltype(a)>::value));
98 }
99
100 TEST_F(ConstexprMathTest, constexpr_log2_2) {
101   constexpr auto v = 2ull;
102   constexpr auto a = folly::constexpr_log2(v);
103   EXPECT_EQ(1ull, a);
104   EXPECT_TRUE((std::is_same<decltype(v), decltype(a)>::value));
105 }
106
107 TEST_F(ConstexprMathTest, constexpr_log2_64) {
108   constexpr auto v = 64ull;
109   constexpr auto a = folly::constexpr_log2(v);
110   EXPECT_EQ(6ull, a);
111   EXPECT_TRUE((std::is_same<decltype(v), decltype(a)>::value));
112 }