libjmmcg  release_579_6_g8cffd
A C++ library containing an eclectic mix of useful, advanced components.
gcd.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/gcd.hpp"
25 
26 using namespace libjmmcg;
27 
28 BOOST_AUTO_TEST_SUITE(gcd_tests)
29 
30 BOOST_AUTO_TEST_SUITE(use_euclid)
31 
32 BOOST_AUTO_TEST_CASE(check_values) {
33  BOOST_CHECK_EQUAL(euclid::gcd(1, 1), 1);
34  BOOST_CHECK_EQUAL(euclid::gcd(2, 1), 1);
35  BOOST_CHECK_EQUAL(euclid::gcd(1, 2), 1);
36  BOOST_CHECK_EQUAL(euclid::gcd(3, 2), 1);
37  BOOST_CHECK_EQUAL(euclid::gcd(2, 3), 1);
38  BOOST_CHECK_EQUAL(euclid::gcd(2, 6), 2);
39  BOOST_CHECK_EQUAL(euclid::gcd(6, 2), 2);
40  BOOST_CHECK_EQUAL(euclid::gcd(15, 25), 5);
41  BOOST_CHECK_EQUAL(euclid::gcd(18, 24), 6);
42 }
43 
44 BOOST_AUTO_TEST_SUITE_END()
45 
46 BOOST_AUTO_TEST_SUITE(use_binary)
47 
48 BOOST_AUTO_TEST_CASE(check_values) {
49  BOOST_CHECK_EQUAL(binary::gcd(1, 1), 1);
50  BOOST_CHECK_EQUAL(binary::gcd(2, 1), 1);
51  BOOST_CHECK_EQUAL(binary::gcd(1, 2), 1);
52  BOOST_CHECK_EQUAL(binary::gcd(3, 2), 1);
53  BOOST_CHECK_EQUAL(binary::gcd(2, 3), 1);
54  BOOST_CHECK_EQUAL(binary::gcd(2, 6), 2);
55  BOOST_CHECK_EQUAL(binary::gcd(6, 2), 2);
56  BOOST_WARN_EQUAL(binary::gcd(15, 25), 5);
57  BOOST_CHECK_EQUAL(binary::gcd(18, 24), 6);
58 }
59 
60 BOOST_AUTO_TEST_SUITE_END()
61 
62 BOOST_AUTO_TEST_SUITE_END()