File: bounds_test.cpp

package info (click to toggle)
boost1.83 1.83.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 545,632 kB
  • sloc: cpp: 3,857,086; xml: 125,552; ansic: 34,414; python: 25,887; asm: 5,276; sh: 4,799; ada: 1,681; makefile: 1,629; perl: 1,212; pascal: 1,139; sql: 810; yacc: 478; ruby: 102; lisp: 24; csh: 6
file content (95 lines) | stat: -rw-r--r-- 2,552 bytes parent folder | download | duplicates (10)
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
//  (c) Copyright Fernando Luis Cacciola Carballal 2000-2004
//  Use, modification, and distribution is subject to 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 library home page at http://www.boost.org/libs/numeric/conversion
//
// Contact the author at: fernando_cacciola@hotmail.com
// 
#include<typeinfo>
#include<iostream>
#include<iomanip>    

#include "boost/numeric/conversion/bounds.hpp"

#ifdef BOOST_BORLANDC
#pragma hdrstop
#endif

#include "test_helpers.cpp"

using namespace std ;
using namespace boost ;
using namespace numeric ;

// Test the fields of boost::numeric::bounds<> against the expected values.
//
template<class T>
void test_bounds( T expected_lowest, T expected_highest, T expected_smallest )
{
  T lowest   = bounds<T>::lowest  () ;
  T highest  = bounds<T>::highest () ;
  T smallest = bounds<T>::smallest() ;

  BOOST_TEST_EQ(lowest, expected_lowest);

  BOOST_TEST_EQ(highest, expected_highest);

  BOOST_TEST_EQ(smallest, expected_smallest);
}


template<class T>
void test_bounds_integer( MATCH_FNTPL_ARG(T) )
{
  test_bounds(  numeric_limits<T>::min BOOST_PREVENT_MACRO_SUBSTITUTION()
              , numeric_limits<T>::max BOOST_PREVENT_MACRO_SUBSTITUTION()
              , static_cast<T>(1)
             ) ;
}
template<class T>
void test_bounds_float( MATCH_FNTPL_ARG(T))
{
  test_bounds(  -numeric_limits<T>::max BOOST_PREVENT_MACRO_SUBSTITUTION ()
               , numeric_limits<T>::max BOOST_PREVENT_MACRO_SUBSTITUTION ()
               , numeric_limits<T>::min BOOST_PREVENT_MACRO_SUBSTITUTION ()
             ) ;
}

void test_bounds_integers()
{
  test_bounds_integer( SET_FNTPL_ARG(unsigned char) ) ;
  test_bounds_integer( SET_FNTPL_ARG(signed char) ) ;
  test_bounds_integer( SET_FNTPL_ARG(char) ) ;
  test_bounds_integer( SET_FNTPL_ARG(unsigned short) ) ;
  test_bounds_integer( SET_FNTPL_ARG(short) ) ;
  test_bounds_integer( SET_FNTPL_ARG(unsigned int) ) ;
  test_bounds_integer( SET_FNTPL_ARG(int) ) ;
  test_bounds_integer( SET_FNTPL_ARG(unsigned long) ) ;
  test_bounds_integer( SET_FNTPL_ARG(long) ) ;
}

void test_bounds_floats()
{
  test_bounds_float( SET_FNTPL_ARG(float) );
  test_bounds_float( SET_FNTPL_ARG(double) );
  test_bounds_float( SET_FNTPL_ARG(long double) );
}

void test_bounds()
{
  test_bounds_integers() ;
  test_bounds_floats  () ;
}


int main( )
{
  cout << setprecision( std::numeric_limits<long double>::digits10 ) ;

  test_bounds();

  return boost::report_errors();
}