static_min_max_test.cpp 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // Boost static_min_max.hpp test program -----------------------------------//
  2. // (C) Copyright Daryle Walker 2001.
  3. // Distributed under the Boost Software License, Version 1.0. (See
  4. // accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. // See http://www.boost.org for most recent version including documentation.
  7. // Revision History
  8. // 23 Sep 2001 Initial version (Daryle Walker)
  9. #include <boost/detail/lightweight_test.hpp> // for main, BOOST_TEST
  10. #include <boost/cstdlib.hpp> // for boost::exit_success
  11. #include <boost/integer/static_min_max.hpp> // for boost::static_signed_min, etc.
  12. #include <iostream> // for std::cout (std::endl indirectly)
  13. // Main testing function
  14. int
  15. main
  16. (
  17. int , // "argc" is unused
  18. char * [] // "argv" is unused
  19. )
  20. {
  21. using std::cout;
  22. using std::endl;
  23. using boost::static_signed_min;
  24. using boost::static_signed_max;
  25. using boost::static_unsigned_min;
  26. using boost::static_unsigned_max;
  27. // Two positives
  28. cout << "Doing tests with two positive values." << endl;
  29. BOOST_TEST( (static_signed_min< 9, 14>::value) == 9 );
  30. BOOST_TEST( (static_signed_max< 9, 14>::value) == 14 );
  31. BOOST_TEST( (static_signed_min<14, 9>::value) == 9 );
  32. BOOST_TEST( (static_signed_max<14, 9>::value) == 14 );
  33. BOOST_TEST( (static_unsigned_min< 9, 14>::value) == 9 );
  34. BOOST_TEST( (static_unsigned_max< 9, 14>::value) == 14 );
  35. BOOST_TEST( (static_unsigned_min<14, 9>::value) == 9 );
  36. BOOST_TEST( (static_unsigned_max<14, 9>::value) == 14 );
  37. // Two negatives
  38. cout << "Doing tests with two negative values." << endl;
  39. BOOST_TEST( (static_signed_min< -8, -101>::value) == -101 );
  40. BOOST_TEST( (static_signed_max< -8, -101>::value) == -8 );
  41. BOOST_TEST( (static_signed_min<-101, -8>::value) == -101 );
  42. BOOST_TEST( (static_signed_max<-101, -8>::value) == -8 );
  43. // With zero
  44. cout << "Doing tests with zero and a positive or negative value." << endl;
  45. BOOST_TEST( (static_signed_min< 0, 14>::value) == 0 );
  46. BOOST_TEST( (static_signed_max< 0, 14>::value) == 14 );
  47. BOOST_TEST( (static_signed_min<14, 0>::value) == 0 );
  48. BOOST_TEST( (static_signed_max<14, 0>::value) == 14 );
  49. BOOST_TEST( (static_unsigned_min< 0, 14>::value) == 0 );
  50. BOOST_TEST( (static_unsigned_max< 0, 14>::value) == 14 );
  51. BOOST_TEST( (static_unsigned_min<14, 0>::value) == 0 );
  52. BOOST_TEST( (static_unsigned_max<14, 0>::value) == 14 );
  53. BOOST_TEST( (static_signed_min< 0, -101>::value) == -101 );
  54. BOOST_TEST( (static_signed_max< 0, -101>::value) == 0 );
  55. BOOST_TEST( (static_signed_min<-101, 0>::value) == -101 );
  56. BOOST_TEST( (static_signed_max<-101, 0>::value) == 0 );
  57. // With identical
  58. cout << "Doing tests with two identical values." << endl;
  59. BOOST_TEST( (static_signed_min<0, 0>::value) == 0 );
  60. BOOST_TEST( (static_signed_max<0, 0>::value) == 0 );
  61. BOOST_TEST( (static_unsigned_min<0, 0>::value) == 0 );
  62. BOOST_TEST( (static_unsigned_max<0, 0>::value) == 0 );
  63. BOOST_TEST( (static_signed_min<14, 14>::value) == 14 );
  64. BOOST_TEST( (static_signed_max<14, 14>::value) == 14 );
  65. BOOST_TEST( (static_unsigned_min<14, 14>::value) == 14 );
  66. BOOST_TEST( (static_unsigned_max<14, 14>::value) == 14 );
  67. BOOST_TEST( (static_signed_min< -101, -101>::value) == -101 );
  68. BOOST_TEST( (static_signed_max< -101, -101>::value) == -101 );
  69. return boost::report_errors();
  70. }