test_absolute.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Boost.Units - A C++ library for zero-overhead dimensional analysis and
  2. // unit/quantity manipulation and conversion
  3. //
  4. // Copyright (C) 2003-2008 Matthias Christian Schabel
  5. // Copyright (C) 2008 Steven Watanabe
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See
  8. // accompanying file LICENSE_1_0.txt or copy at
  9. // http://www.boost.org/LICENSE_1_0.txt)
  10. /**
  11. \file
  12. \brief test_absolute.cpp
  13. \details
  14. Test absolute units.
  15. Output:
  16. @verbatim
  17. @endverbatim
  18. **/
  19. #include <boost/units/quantity.hpp>
  20. #include <boost/units/absolute.hpp>
  21. #include <boost/units/unit.hpp>
  22. #include <boost/units/make_system.hpp>
  23. #include <boost/units/physical_dimensions.hpp>
  24. #include <boost/units/base_units/si/kelvin.hpp>
  25. #include <boost/units/base_units/temperature/celsius.hpp>
  26. #include <boost/units/base_units/temperature/fahrenheit.hpp>
  27. #include <iostream>
  28. #include <boost/test/minimal.hpp>
  29. #define BOOST_UNITS_CHECK_CLOSE(a, b) (BOOST_CHECK((std::abs((a) - (b)) < .0000001)))
  30. namespace bu = boost::units;
  31. using bu::si::kelvin_base_unit;
  32. using bu::temperature::celsius_base_unit;
  33. using bu::temperature::fahrenheit_base_unit;
  34. typedef bu::unit<bu::temperature_dimension,bu::make_system<kelvin_base_unit>::type> kelvin_type;
  35. typedef bu::unit<bu::temperature_dimension,bu::make_system<celsius_base_unit>::type> celsius_type;
  36. typedef bu::unit<bu::temperature_dimension,bu::make_system<fahrenheit_base_unit>::type> fahrenheit_type;
  37. int test_main(int,char *[])
  38. {
  39. BOOST_CONSTEXPR_OR_CONST bu::quantity<bu::absolute<fahrenheit_type> > q1(212.0 * bu::absolute<fahrenheit_type>());
  40. BOOST_CONSTEXPR_OR_CONST bu::quantity<bu::absolute<celsius_type> > q2(0.0 * bu::absolute<celsius_type>());
  41. BOOST_CONSTEXPR_OR_CONST bu::quantity<bu::absolute<fahrenheit_type> > q3(q2);
  42. BOOST_CONSTEXPR_OR_CONST bu::quantity<fahrenheit_type> q4(q1 - q3);
  43. BOOST_UNITS_CHECK_CLOSE(q4.value(), 180.0);
  44. BOOST_CONSTEXPR_OR_CONST bu::quantity<bu::absolute<kelvin_type> > q5(static_cast<bu::quantity<kelvin_type> >(q4) + static_cast<bu::quantity<bu::absolute<kelvin_type> > >(q2));
  45. BOOST_UNITS_CHECK_CLOSE(q5.value(), 373.15);
  46. BOOST_CONSTEXPR_OR_CONST bu::quantity<bu::absolute<fahrenheit_type> > q6(q5);
  47. BOOST_UNITS_CHECK_CLOSE(q6.value(), 212.0);
  48. return(0);
  49. }