pow_test.cc
Go to the documentation of this file.
1 #define BOOST_TEST_MODULE (pow test)
2 #include "boost/test/unit_test.hpp"
3 
4 #include "cetlib/pow.h"
5 
6 using cet::cube;
8 using cet::fourth;
9 using cet::pow;
10 using cet::square;
12 
13 BOOST_AUTO_TEST_SUITE(pow_test)
14 
16 {
17  BOOST_TEST(pow<1>(0) == 0);
18  BOOST_TEST(pow<2>(0u) == 0u);
19  BOOST_TEST(square(0.0) == 0.0);
20  BOOST_TEST(pow<3>(0.0F) == 0.0F);
21  BOOST_TEST(cube(0.0L) == 0.0L);
22  BOOST_TEST(pow<4>(0UL) == 0UL);
23  BOOST_TEST(fourth(0UL) == 0UL);
24  BOOST_TEST(pow<5>(0L) == 0L);
25  BOOST_TEST(pow<9>(0.0) == 0.0);
26 }
27 
29 {
30  BOOST_TEST(pow<0>(1) == 1);
31  BOOST_TEST(pow<1>(1) == 1);
32  BOOST_TEST(pow<2>(1u) == 1u);
33  BOOST_TEST(square(1.0) == 1.0);
34  BOOST_TEST(pow<3>(1.0F) == 1.0F);
35  BOOST_TEST(cube(1.0L) == 1.0L);
36  BOOST_TEST(pow<4>(1UL) == 1UL);
37  BOOST_TEST(fourth(1UL) == 1UL);
38  BOOST_TEST(pow<5>(1L) == 1L);
39  BOOST_TEST(pow<9>(1.0) == 1.0);
40 }
41 
43 {
44  BOOST_TEST(pow<0>(2) == 1);
45  BOOST_TEST(pow<1>(2) == 2);
46  BOOST_TEST(pow<2>(2u) == 4u);
47  BOOST_TEST(square(2.0) == 4.0);
48  BOOST_TEST(pow<3>(2.0F) == 8.0F);
49  BOOST_TEST(cube(2.0L) == 8.0L);
50  BOOST_TEST(pow<4>(2UL) == 16UL);
51  BOOST_TEST(fourth(2UL) == 16UL);
52  BOOST_TEST(pow<5>(2L) == 32L);
53  BOOST_TEST(pow<9>(2.0) == 512.0);
54 }
55 
57 {
58  BOOST_TEST(diff_of_squares(13, 12) == 25);
59  BOOST_TEST(diff_of_squares(13u, 12u) == 25u);
60  BOOST_TEST(diff_of_squares(13L, 12L) == 25L);
61  BOOST_TEST(diff_of_squares(13.0, 12.0) == 25.0);
62  BOOST_TEST(diff_of_squares(13.0F, 12.0F) == 25.0F);
63  BOOST_TEST(diff_of_squares(13.0L, 12.0L) == 25.0L);
64 }
65 
67 {
68  BOOST_TEST(sum_of_squares(1, 2) == 5);
69  BOOST_TEST(sum_of_squares(1u, 2u) == 5u);
70  BOOST_TEST(sum_of_squares(1L, 2L) == 5L);
71  BOOST_TEST(sum_of_squares(1.0, 2.0) == 5.0);
72  BOOST_TEST(sum_of_squares(1.0F, 2.0F) == 5.0F);
73  BOOST_TEST(sum_of_squares(1.0L, 2.0L) == 5.0L);
74 }
75 
77 {
78  BOOST_TEST(sum_of_squares(1, 2, 3) == 14);
79  BOOST_TEST(sum_of_squares(1u, 2u, 3u) == 14u);
80  BOOST_TEST(sum_of_squares(1L, 2L, 3L) == 14L);
81  BOOST_TEST(sum_of_squares(1.0, 2.0, 3.0) == 14.0);
82  BOOST_TEST(sum_of_squares(1.0F, 2.0F, 3.0F) == 14.0F);
83  BOOST_TEST(sum_of_squares(1.0L, 2.0L, 3.0L) == 14.0L);
84 }
85 
86 BOOST_AUTO_TEST_SUITE_END()
constexpr T fourth(T x)
Definition: pow.h:33
BOOST_AUTO_TEST_CASE(zero)
Definition: pow_test.cc:15
constexpr T diff_of_squares(T x, T y)
Definition: pow.h:132
constexpr T sum_of_squares(T x, T y)
Definition: pow.h:139
constexpr T pow(T x)
Definition: pow.h:72
constexpr T square(T x)
Definition: pow.h:21
constexpr T cube(T x)
Definition: pow.h:27
T cube(T side)