]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/units/test/test_absolute.cpp
1 // Boost.Units - A C++ library for zero-overhead dimensional analysis and
2 // unit/quantity manipulation and conversion
4 // Copyright (C) 2003-2008 Matthias Christian Schabel
5 // Copyright (C) 2008 Steven Watanabe
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)
14 \brief test_absolute.cpp
24 #include <boost/units/quantity.hpp>
25 #include <boost/units/absolute.hpp>
26 #include <boost/units/unit.hpp>
27 #include <boost/units/make_system.hpp>
28 #include <boost/units/physical_dimensions.hpp>
29 #include <boost/units/base_units/si/kelvin.hpp>
30 #include <boost/units/base_units/temperature/celsius.hpp>
31 #include <boost/units/base_units/temperature/fahrenheit.hpp>
35 #include <boost/test/minimal.hpp>
37 #define BOOST_UNITS_CHECK_CLOSE(a, b) (BOOST_CHECK((std::abs((a) - (b)) < .0000001)))
39 namespace bu
= boost::units
;
40 using bu::si::kelvin_base_unit
;
41 using bu::temperature::celsius_base_unit
;
42 using bu::temperature::fahrenheit_base_unit
;
44 typedef bu::unit
<bu::temperature_dimension
,bu::make_system
<kelvin_base_unit
>::type
> kelvin_type
;
46 typedef bu::unit
<bu::temperature_dimension
,bu::make_system
<celsius_base_unit
>::type
> celsius_type
;
48 typedef bu::unit
<bu::temperature_dimension
,bu::make_system
<fahrenheit_base_unit
>::type
> fahrenheit_type
;
50 int test_main(int,char *[])
52 bu::quantity
<bu::absolute
<fahrenheit_type
> > q1(212.0 * bu::absolute
<fahrenheit_type
>());
53 bu::quantity
<bu::absolute
<celsius_type
> > q2(0.0 * bu::absolute
<celsius_type
>());
54 bu::quantity
<bu::absolute
<fahrenheit_type
> > q3(q2
);
55 bu::quantity
<fahrenheit_type
> q4(q1
- q3
);
57 BOOST_UNITS_CHECK_CLOSE(q4
.value(), 180.0);
59 bu::quantity
<bu::absolute
<kelvin_type
> > q5(static_cast<bu::quantity
<kelvin_type
> >(q4
) + static_cast<bu::quantity
<bu::absolute
<kelvin_type
> > >(q2
));
61 BOOST_UNITS_CHECK_CLOSE(q5
.value(), 373.15);
63 bu::quantity
<bu::absolute
<fahrenheit_type
> > q6(q5
);
65 BOOST_UNITS_CHECK_CLOSE(q6
.value(), 212.0);