1 // Boost.Units - A C++ library for zero-overhead dimensional analysis and
2 // unit/quantity manipulation and conversion
4 // Copyright (C) 2003-2009 Matthias Christian Schabel
5 // Copyright (C) 2007-2009 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_constants.cpp
17 Test all combinations of operators with the constants.
21 #include <boost/units/systems/detail/constants.hpp>
22 #include <boost/units/quantity.hpp>
23 #include <boost/units/systems/si/length.hpp>
24 #include <boost/units/systems/si/time.hpp>
26 using boost::units::quantity;
27 using boost::units::si::length;
28 using boost::units::si::meters;
29 using boost::units::si::seconds;
31 BOOST_UNITS_PHYSICAL_CONSTANT(length_constant, quantity<length>, 2.0 * meters, 0.5 * meters);
34 void check_same(const T&, const T&);
37 typename T::value_type unwrap(const boost::units::constant<T>&);
42 #define BOOST_UNITS_CHECK_RESULT(arg1, op, arg2) check_same((arg1) op (arg2), unwrap(arg1) op unwrap(arg2));
45 BOOST_UNITS_CHECK_RESULT(length_constant, +, length_constant);
46 BOOST_UNITS_CHECK_RESULT(length_constant, +, 1.0 * meters);
47 BOOST_UNITS_CHECK_RESULT(1.0* meters, +, length_constant);
50 void test_subtract() {
51 BOOST_UNITS_CHECK_RESULT(length_constant, -, length_constant);
52 BOOST_UNITS_CHECK_RESULT(length_constant, -, 1.0 * meters);
53 BOOST_UNITS_CHECK_RESULT(1.0* meters, -, length_constant);
56 void test_multiply() {
57 BOOST_UNITS_CHECK_RESULT(length_constant, *, length_constant);
58 BOOST_UNITS_CHECK_RESULT(length_constant, *, 1.0 * seconds);
59 BOOST_UNITS_CHECK_RESULT(1.0 * seconds, *, length_constant);
60 BOOST_UNITS_CHECK_RESULT(length_constant, *, 1.0);
61 BOOST_UNITS_CHECK_RESULT(1.0, *, length_constant);
62 BOOST_UNITS_CHECK_RESULT(length_constant, *, seconds);
63 BOOST_UNITS_CHECK_RESULT(seconds, *, length_constant);
67 BOOST_UNITS_CHECK_RESULT(length_constant, /, length_constant);
68 BOOST_UNITS_CHECK_RESULT(length_constant, /, 1.0 * seconds);
69 BOOST_UNITS_CHECK_RESULT(1.0 * seconds, /, length_constant);
70 BOOST_UNITS_CHECK_RESULT(length_constant, /, 1.0);
71 BOOST_UNITS_CHECK_RESULT(1.0, /, length_constant);
72 BOOST_UNITS_CHECK_RESULT(length_constant, /, seconds);
73 BOOST_UNITS_CHECK_RESULT(seconds, /, length_constant);