File: static_min_max_test.cpp

package info (click to toggle)
boost1.35 1.35.0-5
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 203,856 kB
  • ctags: 337,867
  • sloc: cpp: 938,683; xml: 56,847; ansic: 41,589; python: 18,999; sh: 11,566; makefile: 664; perl: 494; yacc: 456; asm: 353; csh: 6
file content (93 lines) | stat: -rw-r--r-- 3,600 bytes parent folder | download | duplicates (2)
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
//  Boost static_min_max.hpp test program  -----------------------------------//

//  (C) Copyright Daryle Walker 2001.
//  Distributed under the Boost Software License, Version 1.0. (See
//  accompanying file LICENSE_1_0.txt or copy at
//  http://www.boost.org/LICENSE_1_0.txt)

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

//  Revision History
//  23 Sep 2001  Initial version (Daryle Walker)

#define  BOOST_INCLUDE_MAIN
#include <boost/test/test_tools.hpp>  // for main, BOOST_CHECK

#include <boost/cstdlib.hpp>                 // for boost::exit_success
#include <boost/integer/static_min_max.hpp>  // for boost::static_signed_min, etc.

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


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

    // Two positives
    cout << "Doing tests with two positive values." << endl;

    BOOST_CHECK( (static_signed_min< 9, 14>::value) ==  9 );
    BOOST_CHECK( (static_signed_max< 9, 14>::value) == 14 );
    BOOST_CHECK( (static_signed_min<14,  9>::value) ==  9 );
    BOOST_CHECK( (static_signed_max<14,  9>::value) == 14 );

    BOOST_CHECK( (static_unsigned_min< 9, 14>::value) ==  9 );
    BOOST_CHECK( (static_unsigned_max< 9, 14>::value) == 14 );
    BOOST_CHECK( (static_unsigned_min<14,  9>::value) ==  9 );
    BOOST_CHECK( (static_unsigned_max<14,  9>::value) == 14 );

    // Two negatives
    cout << "Doing tests with two negative values." << endl;

    BOOST_CHECK( (static_signed_min<  -8, -101>::value) == -101 );
    BOOST_CHECK( (static_signed_max<  -8, -101>::value) ==   -8 );
    BOOST_CHECK( (static_signed_min<-101,   -8>::value) == -101 );
    BOOST_CHECK( (static_signed_max<-101,   -8>::value) ==   -8 );

    // With zero
    cout << "Doing tests with zero and a positive or negative value." << endl;

    BOOST_CHECK( (static_signed_min< 0, 14>::value) ==  0 );
    BOOST_CHECK( (static_signed_max< 0, 14>::value) == 14 );
    BOOST_CHECK( (static_signed_min<14,  0>::value) ==  0 );
    BOOST_CHECK( (static_signed_max<14,  0>::value) == 14 );

    BOOST_CHECK( (static_unsigned_min< 0, 14>::value) ==  0 );
    BOOST_CHECK( (static_unsigned_max< 0, 14>::value) == 14 );
    BOOST_CHECK( (static_unsigned_min<14,  0>::value) ==  0 );
    BOOST_CHECK( (static_unsigned_max<14,  0>::value) == 14 );

    BOOST_CHECK( (static_signed_min<   0, -101>::value) == -101 );
    BOOST_CHECK( (static_signed_max<   0, -101>::value) ==    0 );
    BOOST_CHECK( (static_signed_min<-101,    0>::value) == -101 );
    BOOST_CHECK( (static_signed_max<-101,    0>::value) ==    0 );

    // With identical
    cout << "Doing tests with two identical values." << endl;

    BOOST_CHECK( (static_signed_min<0, 0>::value) == 0 );
    BOOST_CHECK( (static_signed_max<0, 0>::value) == 0 );
    BOOST_CHECK( (static_unsigned_min<0, 0>::value) == 0 );
    BOOST_CHECK( (static_unsigned_max<0, 0>::value) == 0 );

    BOOST_CHECK( (static_signed_min<14, 14>::value) == 14 );
    BOOST_CHECK( (static_signed_max<14, 14>::value) == 14 );
    BOOST_CHECK( (static_unsigned_min<14, 14>::value) == 14 );
    BOOST_CHECK( (static_unsigned_max<14, 14>::value) == 14 );

    BOOST_CHECK( (static_signed_min< -101, -101>::value) == -101 );
    BOOST_CHECK( (static_signed_max< -101, -101>::value) == -101 );

    return boost::exit_success;
}