File: common_factor_test.cpp

package info (click to toggle)
boost 1.27.0-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 19,908 kB
  • ctags: 26,546
  • sloc: cpp: 122,225; ansic: 10,956; python: 4,412; sh: 855; yacc: 803; makefile: 257; perl: 165; lex: 90; csh: 6
file content (115 lines) | stat: -rw-r--r-- 4,108 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//  Boost GCD & LCM common_factor.hpp test program  --------------------------//

//  (C) Copyright Daryle Walker 2001.  Permission to copy, use, modify, sell
//  and distribute this software is granted provided this copyright
//  notice appears in all copies.  This software is provided "as is" without
//  express or implied warranty, and with no claim as to its suitability for
//  any purpose.

//  See http://www.boost.org for most recent version including documentation.

//  Revision History
//  07 Nov 2001  Initial version (Daryle Walker)

#define  BOOST_INCLUDE_MAIN

#include <boost/config.hpp>              // for BOOST_MSVC
#include <boost/cstdlib.hpp>             // for boost::exit_success
#include <boost/math/common_factor.hpp>  // for boost::math::gcd, etc.
#include <boost/test/test_tools.hpp>     // for main, BOOST_TEST

#include <iostream>  // for std::cout (std::endl indirectly)


// Control to determine what kind of built-in integers are used
#ifndef CONTROL_INT_TYPE
#define CONTROL_INT_TYPE  int
#endif


// Main testing function
int
test_main
(
    int         ,   // "argc" is unused
    char *      []  // "argv" is unused
)
{    
    using std::cout;
    using std::endl;

#ifndef BOOST_MSVC
    using boost::math::gcd;
    using boost::math::static_gcd;
    using boost::math::lcm;
    using boost::math::static_lcm;
#else
    using namespace boost::math;
#endif

    typedef CONTROL_INT_TYPE  int_type;

    // GCD tests
    cout << "Doing tests on gcd." << endl;

    BOOST_TEST( gcd<int_type>(  1,  -1) ==  1 );
    BOOST_TEST( gcd<int_type>( -1,   1) ==  1 );
    BOOST_TEST( gcd<int_type>(  1,   1) ==  1 );
    BOOST_TEST( gcd<int_type>( -1,  -1) ==  1 );
    BOOST_TEST( gcd<int_type>(  0,   0) ==  0 );
    BOOST_TEST( gcd<int_type>(  7,   0) ==  7 );
    BOOST_TEST( gcd<int_type>(  0,   9) ==  9 );
    BOOST_TEST( gcd<int_type>( -7,   0) ==  7 );
    BOOST_TEST( gcd<int_type>(  0,  -9) ==  9 );
    BOOST_TEST( gcd<int_type>( 42,  30) ==  6 );
    BOOST_TEST( gcd<int_type>(  6,  -9) ==  3 );
    BOOST_TEST( gcd<int_type>(-10, -10) == 10 );
    BOOST_TEST( gcd<int_type>(-25, -10) ==  5 );
    BOOST_TEST( gcd<int_type>(  3,   7) ==  1 );
    BOOST_TEST( gcd<int_type>(  8,   9) ==  1 );
    BOOST_TEST( gcd<int_type>(  7,  49) ==  7 );

    cout << "Doing tests on static_gcd." << endl;

    BOOST_TEST( (static_gcd< 1,  1>::value) == 1 );
    BOOST_TEST( (static_gcd< 0,  0>::value) == 0 );
    BOOST_TEST( (static_gcd< 7,  0>::value) == 7 );
    BOOST_TEST( (static_gcd< 0,  9>::value) == 9 );
    BOOST_TEST( (static_gcd<42, 30>::value) == 6 );
    BOOST_TEST( (static_gcd< 3,  7>::value) == 1 );
    BOOST_TEST( (static_gcd< 8,  9>::value) == 1 );
    BOOST_TEST( (static_gcd< 7, 49>::value) == 7 );

    // LCM tests
    cout << "Doing tests on lcm." << endl;

    BOOST_TEST( lcm<int_type>(  1,  -1) ==  1 );
    BOOST_TEST( lcm<int_type>( -1,   1) ==  1 );
    BOOST_TEST( lcm<int_type>(  1,   1) ==  1 );
    BOOST_TEST( lcm<int_type>( -1,  -1) ==  1 );
    BOOST_TEST( lcm<int_type>(  0,   0) ==  0 );
    BOOST_TEST( lcm<int_type>(  6,   0) ==  0 );
    BOOST_TEST( lcm<int_type>(  0,   7) ==  0 );
    BOOST_TEST( lcm<int_type>( -5,   0) ==  0 );
    BOOST_TEST( lcm<int_type>(  0,  -4) ==  0 );
    BOOST_TEST( lcm<int_type>( 18,  30) == 90 );
    BOOST_TEST( lcm<int_type>( -6,   9) == 18 );
    BOOST_TEST( lcm<int_type>(-10, -10) == 10 );
    BOOST_TEST( lcm<int_type>( 25, -10) == 50 );
    BOOST_TEST( lcm<int_type>(  3,   7) == 21 );
    BOOST_TEST( lcm<int_type>(  8,   9) == 72 );
    BOOST_TEST( lcm<int_type>(  7,  49) == 49 );

    cout << "Doing tests on static_lcm." << endl;

    BOOST_TEST( (static_lcm< 1,  1>::value) ==  1 );
    BOOST_TEST( (static_lcm< 0,  0>::value) ==  0 );
    BOOST_TEST( (static_lcm< 6,  0>::value) ==  0 );
    BOOST_TEST( (static_lcm< 0,  7>::value) ==  0 );
    BOOST_TEST( (static_lcm<18, 30>::value) == 90 );
    BOOST_TEST( (static_lcm< 3,  7>::value) == 21 );
    BOOST_TEST( (static_lcm< 8,  9>::value) == 72 );
    BOOST_TEST( (static_lcm< 7, 49>::value) == 49 );

    return boost::exit_success;
}