libjmmcg  release_579_6_g8cffd
A C++ library containing an eclectic mix of useful, advanced components.
factoring.cpp
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright © 2016 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/factoring.hpp"
25 
26 using namespace libjmmcg;
27 
28 namespace std {
29 
30 std::ostream &operator<<(std::ostream &os, factoring::collection_type const &c) noexcept(false) {
31  std::copy(c.begin(), c.end(), std::ostream_iterator<factoring::collection_type::value_type>(os, ", "));
32  return os;
33 }
34 
35 }
36 
37 BOOST_AUTO_TEST_SUITE(factoring_tests)
38 
39 BOOST_AUTO_TEST_SUITE(division)
40 
41 BOOST_AUTO_TEST_CASE(check_values) {
42  BOOST_CHECK_EQUAL(factoring::division(1), factoring::collection_type{});
43  BOOST_CHECK_EQUAL(factoring::division(2), factoring::collection_type{2});
44  BOOST_CHECK_EQUAL(factoring::division(3), factoring::collection_type{3});
45  BOOST_CHECK_EQUAL(factoring::division(4), factoring::collection_type{2});
46  BOOST_CHECK_EQUAL(factoring::division(5), factoring::collection_type{5});
47  BOOST_CHECK_EQUAL(factoring::division(6), (factoring::collection_type{2, 3}));
48  BOOST_CHECK_EQUAL(factoring::division(7), factoring::collection_type{7});
49  BOOST_CHECK_EQUAL(factoring::division(8), factoring::collection_type{2});
50  BOOST_CHECK_EQUAL(factoring::division(9), factoring::collection_type{3});
51  BOOST_CHECK_EQUAL(factoring::division(10), (factoring::collection_type{2, 5}));
52  BOOST_CHECK_EQUAL(factoring::division(24), (factoring::collection_type{2, 3}));
53  BOOST_CHECK_EQUAL(factoring::division(30), (factoring::collection_type{2, 3, 5}));
54 }
55 
56 BOOST_AUTO_TEST_SUITE_END()
57 
58 BOOST_AUTO_TEST_SUITE(monte_carlo)
59 /* TODO
60 BOOST_AUTO_TEST_CASE(check_values) {
61  BOOST_CHECK_EQUAL(factoring::monte_carlo(1), factoring::collection_type{});
62  BOOST_CHECK_EQUAL(factoring::monte_carlo(2), factoring::collection_type{2});
63  BOOST_CHECK_EQUAL(factoring::monte_carlo(3), factoring::collection_type{3});
64  BOOST_CHECK_EQUAL(factoring::monte_carlo(4), factoring::collection_type{2});
65  BOOST_CHECK_EQUAL(factoring::monte_carlo(5), factoring::collection_type{5});
66  BOOST_CHECK_EQUAL(factoring::monte_carlo(6), (factoring::collection_type{2, 3}));
67  BOOST_CHECK_EQUAL(factoring::monte_carlo(7), factoring::collection_type{7});
68  BOOST_CHECK_EQUAL(factoring::monte_carlo(8), factoring::collection_type{2});
69  BOOST_CHECK_EQUAL(factoring::monte_carlo(9), factoring::collection_type{3});
70  BOOST_CHECK_EQUAL(factoring::monte_carlo(10), (factoring::collection_type{2, 5}));
71  BOOST_CHECK_EQUAL(factoring::monte_carlo(24), (factoring::collection_type{2, 3}));
72  BOOST_CHECK_EQUAL(factoring::monte_carlo(30), (factoring::collection_type{2, 3, 5}));
73 }
74 */
75 BOOST_AUTO_TEST_SUITE_END()
76 
77 BOOST_AUTO_TEST_SUITE_END()