libjmmcg  release_579_6_g8cffd
A C++ library containing an eclectic mix of useful, advanced components.
fibonacci.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 <boost/mpl/list.hpp>
25 
26 #include "core/fibonacci.hpp"
27 
28 using namespace libjmmcg;
29 
30 typedef boost::mpl::list<
31  std::pair<mpl::fibonacci<0>, boost::mpl::int_<1>>,
32  std::pair<mpl::fibonacci<1>, boost::mpl::int_<1>>,
33  std::pair<mpl::fibonacci<2>, boost::mpl::int_<2>>,
34  std::pair<mpl::fibonacci<3>, boost::mpl::int_<3>>,
35  std::pair<mpl::fibonacci<4>, boost::mpl::int_<5>>,
36  std::pair<mpl::fibonacci<5>, boost::mpl::int_<8>>,
37  std::pair<mpl::fibonacci<6>, boost::mpl::int_<13>>,
38  std::pair<mpl::fibonacci<7>, boost::mpl::int_<21>>,
39  std::pair<mpl::fibonacci<8>, boost::mpl::int_<34>>,
40  std::pair<mpl::fibonacci<9>, boost::mpl::int_<55>>,
41  std::pair<mpl::fibonacci<10>, boost::mpl::int_<89>>
43 
44 BOOST_AUTO_TEST_SUITE(fibonacci_tests)
45 
46 BOOST_AUTO_TEST_SUITE(mpl)
47 
48 BOOST_AUTO_TEST_CASE_TEMPLATE(check_value, fibonacci_t, check_mpl_fibonacci_tests) {
49  BOOST_CHECK_EQUAL(fibonacci_t::first_type::value, fibonacci_t::second_type::value);
50 }
51 
52 BOOST_AUTO_TEST_SUITE_END()
53 
54 BOOST_AUTO_TEST_SUITE(dyn)
55 
56 BOOST_AUTO_TEST_CASE(fibonacci_0) {
57  BOOST_CHECK_EQUAL(libjmmcg::dyn::fibonacci::result(0), 1ull);
58 }
59 
60 BOOST_AUTO_TEST_CASE(fibonacci_1) {
61  BOOST_CHECK_EQUAL(libjmmcg::dyn::fibonacci::result(1), 1ull);
62 }
63 
64 BOOST_AUTO_TEST_CASE(fibonacci_2) {
65  BOOST_CHECK_EQUAL(libjmmcg::dyn::fibonacci::result(2), 2ull);
66 }
67 
68 BOOST_AUTO_TEST_CASE(fibonacci_3) {
69  BOOST_CHECK_EQUAL(libjmmcg::dyn::fibonacci::result(3), 3ull);
70 }
71 
72 BOOST_AUTO_TEST_CASE(fibonacci_4) {
73  BOOST_CHECK_EQUAL(libjmmcg::dyn::fibonacci::result(4), 5ull);
74 }
75 
76 BOOST_AUTO_TEST_CASE(fibonacci_5) {
77  BOOST_CHECK_EQUAL(libjmmcg::dyn::fibonacci::result(5), 8ull);
78 }
79 
80 BOOST_AUTO_TEST_CASE(fibonacci_6) {
81  BOOST_CHECK_EQUAL(libjmmcg::dyn::fibonacci::result(6), 13ull);
82 }
83 
84 BOOST_AUTO_TEST_CASE(fibonacci_7) {
85  BOOST_CHECK_EQUAL(libjmmcg::dyn::fibonacci::result(7), 21ull);
86 }
87 
88 BOOST_AUTO_TEST_CASE(fibonacci_8) {
89  BOOST_CHECK_EQUAL(libjmmcg::dyn::fibonacci::result(8), 34ull);
90 }
91 
92 BOOST_AUTO_TEST_CASE(fibonacci_9) {
93  BOOST_CHECK_EQUAL(libjmmcg::dyn::fibonacci::result(9), 55ull);
94 }
95 
96 BOOST_AUTO_TEST_CASE(fibonacci_10) {
97  BOOST_CHECK_EQUAL(libjmmcg::dyn::fibonacci::result(10), 89ull);
98 }
99 
100 BOOST_AUTO_TEST_SUITE_END()
101 
102 BOOST_AUTO_TEST_SUITE_END()