libjmmcg  release_579_6_g8cffd
A C++ library containing an eclectic mix of useful, advanced components.
integer_power.cpp
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright © 2002 by J.M.McGuiness, coder@hussar.me.uk
3 **
4 ** This library is free software; you can redistribute it and/or
5 ** modify it under the terms of the GNU Lesser General Public
6 ** License as published by the Free Software Foundation; either
7 ** version 2.1 of the License, or (at your option) any later version.
8 **
9 ** This library is distributed in the hope that it will be useful,
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 ** Lesser General Public License for more details.
13 **
14 ** You should have received a copy of the GNU Lesser General Public
15 ** License along with this library; if not, write to the Free Software
16 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18 
19 #include "stdafx.h"
20 
21 #define BOOST_TEST_MODULE libjmmcg_tests
22 #include <boost/test/included/unit_test.hpp>
23 
24 #include "core/integer_power.hpp"
25 
26 using namespace libjmmcg;
27 
28 BOOST_AUTO_TEST_SUITE(dynamic_integer_powers)
29 
30 BOOST_AUTO_TEST_CASE(two_pow_zero)
31 {
32  BOOST_CHECK_EQUAL(pow<0>(2), 1);
33 }
34 
35 BOOST_AUTO_TEST_CASE(two_pow_one)
36 {
37  BOOST_CHECK_EQUAL(pow<1>(2), 2);
38 }
39 
40 BOOST_AUTO_TEST_CASE(two_pow_two)
41 {
42  BOOST_CHECK_EQUAL(pow<2>(2), 4);
43 }
44 
45 BOOST_AUTO_TEST_CASE(two_pow_eight)
46 {
47  BOOST_CHECK_EQUAL(pow<8>(2), 256);
48 }
49 
50 BOOST_AUTO_TEST_CASE(two_pow_minus_one)
51 {
52  BOOST_CHECK_EQUAL(pow<-1>(2.0), 0.5);
53 }
54 
55 BOOST_AUTO_TEST_CASE(two_pow_minus_two)
56 {
57  BOOST_CHECK_EQUAL(pow<-2>(2.0), 0.25);
58 }
59 
60 BOOST_AUTO_TEST_SUITE_END()
61 
62 BOOST_AUTO_TEST_SUITE(static_integer_powers)
63 
64 BOOST_AUTO_TEST_CASE(two_pow_zero)
65 {
66  typedef binary_right_to_left::mpl::pow<2, 0> pow_2_0_t;
67  const double res=pow_2_0_t::result;
68  BOOST_CHECK_EQUAL(pow<0>(2), res);
69 }
70 
71 BOOST_AUTO_TEST_CASE(two_pow_one)
72 {
73  typedef binary_right_to_left::mpl::pow<2, 1> pow_2_1_t;
74  const double res=pow_2_1_t::result;
75  BOOST_CHECK_EQUAL(pow<1>(2), res);
76 }
77 
78 BOOST_AUTO_TEST_CASE(two_pow_two)
79 {
80  typedef binary_right_to_left::mpl::pow<2, 2> pow_2_2_t;
81  const double res=pow_2_2_t::result;
82  BOOST_CHECK_EQUAL(pow<2>(2), res);
83 }
84 
85 BOOST_AUTO_TEST_CASE(two_pow_eight)
86 {
87  typedef binary_right_to_left::mpl::pow<2, 8> pow_2_8_t;
88  const double res=pow_2_8_t::result;
89  BOOST_CHECK_EQUAL(pow<8>(2), res);
90 }
91 
92 BOOST_AUTO_TEST_CASE(two_pow_minus_one)
93 {
94  typedef binary_right_to_left::mpl::pow<2, -1> pow_2_n1_t;
95  const double res=pow_2_n1_t::result;
96  BOOST_CHECK_EQUAL(0, res);
97 }
98 
99 BOOST_AUTO_TEST_CASE(two_pow_minus_two)
100 {
101  typedef binary_right_to_left::mpl::pow<2, -2> pow_2_n2_t;
102  const double res=pow_2_n2_t::result;
103  BOOST_CHECK_EQUAL(0, res);
104 }
105 
106 BOOST_AUTO_TEST_SUITE_END()