diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
commit | 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch) | |
tree | e5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/boost/libs/units/test | |
parent | Initial commit. (diff) | |
download | ceph-upstream.tar.xz ceph-upstream.zip |
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/libs/units/test')
50 files changed, 4118 insertions, 0 deletions
diff --git a/src/boost/libs/units/test/Jamfile.v2 b/src/boost/libs/units/test/Jamfile.v2 new file mode 100644 index 00000000..5dae5562 --- /dev/null +++ b/src/boost/libs/units/test/Jamfile.v2 @@ -0,0 +1,78 @@ +# Jamfile.v2 +# +# Copyright (c) 2007-2009 +# Steven Watanabe +# +# Distributed under 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 + +import testing ; + +warning-options = <warnings>all <warnings-as-errors>on ; +warning-compilers = + <toolset>msvc +; + +project boost/units/test : + requirements + <implicit-dependency>/boost//headers + <toolset>msvc:<asynch-exceptions>on + $(warning-compilers)\:$(warning-options) + # This warning comes from the test library. + <toolset>msvc:<cxxflags>"/wd4701" + # The comes from the exception library + <toolset>msvc,<toolset-msvc:version>7.1:<cxxflags>"/wd4800" +; + +alias test_framework : /boost//unit_test_framework/<warnings-as-errors>off ; + +compile test_predicates.cpp ; +compile test_negative_denominator.cpp ; +compile test_dimensionless_ice1.cpp ; +compile test_dimensionless_ice2.cpp ; +compile test_mixed_value_types.cpp ; +compile test_complicated_system.cpp ; +compile test_reduce_unit.cpp ; +compile test_unscale.cpp ; +compile test_constants.cpp ; + +run test_dimensionless_quantity.cpp ; +run test_implicit_conversion.cpp ; +run test_quantity.cpp ; +run test_unit.cpp ; +run test_conversion.cpp test_framework ; +run test_base_dimension.cpp ; +run test_absolute.cpp ; +run test_default_conversion.cpp ; +run test_cmath.cpp ; +run test_limits.cpp ; +run test_custom_unit.cpp ; +run test_scaled_conversion.cpp ; +run test_lambda.cpp ; +run test_sqrt_scaled_unit.cpp ; +run test_scaled_unit.cpp test_framework ; +run test_output.cpp test_framework /boost//regex/<warnings-as-errors>off : : : <test-info>always_show_run_output ; +run test_trig.cpp test_framework ; +run test_information_units.cpp test_framework ; + +compile-fail fail_implicit_conversion.cpp ; +compile-fail fail_quantity_construct.cpp ; +compile-fail fail_quantity_assign.cpp ; +compile-fail fail_quantity_add.cpp ; +compile-fail fail_quantity_subtract.cpp ; +compile-fail fail_quantity_add_assign.cpp ; +compile-fail fail_quantity_sub_assign.cpp ; +compile-fail fail_quantity_scalar_add.cpp ; +compile-fail fail_quantity_scalar_sub.cpp ; +compile-fail fail_quantity_unit_add.cpp ; +compile-fail fail_quantity_unit_subtract.cpp ; +compile-fail fail_scalar_quantity_add.cpp ; +compile-fail fail_scalar_quantity_sub.cpp ; +compile-fail fail_unit_quantity_add.cpp ; +compile-fail fail_unit_quantity_subtract.cpp ; +compile-fail fail_adl_detail.cpp ; +compile-fail fail_heterogeneous_unit.cpp ; +compile-fail fail_base_dimension.cpp ; +compile-fail fail_add_temperature.cpp ; +compile-fail fail_quantity_non_unit.cpp ; diff --git a/src/boost/libs/units/test/check_conversion_defs.cpp b/src/boost/libs/units/test/check_conversion_defs.cpp new file mode 100644 index 00000000..cb7ff56b --- /dev/null +++ b/src/boost/libs/units/test/check_conversion_defs.cpp @@ -0,0 +1,159 @@ +// Boost.Units - A C++ library for zero-overhead dimensional analysis and +// unit/quantity manipulation and conversion +// +// Copyright (C) 2003-2008 Matthias Christian Schabel +// Copyright (C) 2007-2008 Steven Watanabe +// +// Distributed under 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) + +#include <iterator> +#include <string> +#include <utility> +#include <set> +#include <map> +#include <iostream> + +#include <boost/filesystem.hpp> +#include <boost/filesystem/fstream.hpp> +#include <boost/regex.hpp> + +namespace filesystem = boost::filesystem; + +//struct stop { +// stop() { char c; std::cin >> c; } +//} stop_; + +boost::regex whitespace("\\s*"); +boost::regex blank_line("\\A(?://.*$|\\s)*"); + +boost::regex include_guard("#ifndef (\\w+)\n#define \\1\n"); +boost::regex base_unit("(\\w*_base_unit)(?:;| :)"); + +std::pair<std::string, std::string> get_base_unit_and_include_guard(const filesystem::path& path) { + filesystem::ifstream in(path); + std::string contents(std::istreambuf_iterator<char>(in.rdbuf()), std::istreambuf_iterator<char>()); + in.close(); + boost::smatch include_guard_match; + boost::regex_search(contents, include_guard_match, include_guard); + boost::smatch base_unit_match; + boost::regex_search(contents, base_unit_match, base_unit); + std::cout << "creating map entry: " << base_unit_match[1].str() << " -> "<< include_guard_match[1].str() << std::endl; + return(std::make_pair(base_unit_match[1].str(), include_guard_match[1].str())); +} + +int main() { + std::cout << "In main" << std::endl; + std::map<std::string, std::string> include_guards; + for(filesystem::directory_iterator begin(filesystem::path("../../../boost/units/systems/base_units")), end; begin != end; ++begin) { + if(begin->status().type() == filesystem::regular_file) { + std::cout << "reading file: " << begin->path() << std::endl; + include_guards.insert(get_base_unit_and_include_guard(begin->path())); + } + } + + std::cout << "reading conversions file" << std::endl; + filesystem::ifstream conversions_file(filesystem::path("../../../boost/units/systems/base_units/detail/conversions.hpp")); + + std::string line; + int line_count = 0; + + boost::smatch match; + + std::set<std::string> conversion_guards; + + try { + +boost::regex include_guard_regex("#if defined\\((\\w+)\\) && defined\\((\\w+)\\) &&\\\\"); +std::cout << __LINE__ << std::endl; +boost::regex conversion_guard_regex(" !defined\\((\\w+)\\)"); +std::cout << __LINE__ << std::endl; +boost::regex set_conversion_guard(" #define (\\w+)"); +std::cout << __LINE__ << std::endl; +boost::regex include_conversion(" #include <boost/units/conversion.hpp>"); +std::cout << __LINE__ << std::endl; +boost::regex include_absolute(" #include <boost/units/absolute.hpp>"); +std::cout << __LINE__ << std::endl; +boost::regex define_conversion_factor(" BOOST_UNITS_DEFINE_CONVERSION_FACTOR\\(boost::units::(\\w+_base_unit), boost::units::(\\w+_base_unit), \\w+, (?:[\\d\\.e\\-/ ]*|one\\(\\))\\);"); +std::cout << __LINE__ << std::endl; +boost::regex define_conversion_offset(" BOOST_UNITS_DEFINE_CONVERSION_OFFSET\\(boost::units::(\\w+_base_unit), boost::units::(\\w+_base_unit), \\w+, [\\d\\.e+\\* \\-/]*\\);"); +std::cout << __LINE__ << std::endl; +boost::regex endif("#endif"); +std::cout << __LINE__ << std::endl; + + while(std::getline(conversions_file, line)) { + ++line_count; + std::cout << "on line: " << line_count << std::endl; + if(boost::regex_match(line, match, blank_line)) { + continue; + } else if(boost::regex_match(line, match, include_guard_regex)) { + std::string guard1, guard2, unit1, unit2, conversion_guard; + bool uses_absolute = false; + + guard1 = match[1].str(); + guard2 = match[2].str(); + if(!std::getline(conversions_file, line)) { std::cerr << "unexpected end of file." << std::endl; return(1); } ++line_count; + if(!boost::regex_match(line, match, conversion_guard_regex)) { std::cerr << "error on line: " << line_count << std::endl; return(1); } + + conversion_guard = match[1].str(); + if(!conversion_guards.insert(conversion_guard).second){ std::cerr << "error on line: " << line_count << std::endl; return(1); } + + if(!std::getline(conversions_file, line)) { std::cerr << "unexpected end of file." << std::endl; return(1); } ++line_count; + if(!boost::regex_match(line, match, set_conversion_guard)) { std::cerr << "error on line: " << line_count << std::endl; return(1); } +std::cout << __LINE__ << std::endl; + + if(match[1].str() != conversion_guard) { std::cerr << "error on line: " << line_count << std::endl; return(1); } + + if(!std::getline(conversions_file, line)) { std::cerr << "unexpected end of file." << std::endl; return(1); } ++line_count; + if(!boost::regex_match(line, match, include_conversion)) { std::cerr << "error on line: " << line_count << std::endl; return(1); } +std::cout << __LINE__ << std::endl; + + if(!std::getline(conversions_file, line)) { std::cerr << "unexpected end of file." << std::endl; return(1); } ++line_count; + if(boost::regex_match(line, match, include_absolute)) { + uses_absolute = true; + if(!std::getline(conversions_file, line)) { std::cerr << "unexpected end of file." << std::endl; return(1); } ++line_count; + } + +std::cout << __LINE__ << std::endl; + if(!boost::regex_match(line, match, define_conversion_factor)) { std::cerr << "error on line: " << line_count << std::endl; return(1); } + +std::cout << __LINE__ << ": " << line << std::endl; + unit1 = match[1].str(); + unit2 = match[2].str(); + if(!((include_guards[unit1] == guard1 && include_guards[unit2] == guard2) || + (include_guards[unit1] == guard2 && include_guards[unit2] == guard1))) { + std::cerr << "guard1: " << guard1 << std::endl; + std::cerr << "guard2: " << guard2 << std::endl; + std::cerr << "unit1: " << unit1 << std::endl; + std::cerr << "unit2: " << unit2 << std::endl; + std::cerr << "include_guards[unit1]: " << include_guards[unit1] << std::endl; + std::cerr << "include_guards[unit2]: " << include_guards[unit2] << std::endl; + { std::cerr << "error on line: " << line_count << std::endl; return(1); } + } +std::cout << __LINE__ << std::endl; + + if(!std::getline(conversions_file, line)) { std::cerr << "unexpected end of file." << std::endl; return(1); } ++line_count; +std::cout << __LINE__ << std::endl; + if(boost::regex_match(line, match, define_conversion_offset)) { + if(!uses_absolute) { std::cerr << "error on line: " << line_count << std::endl; return(1); } +std::cout << __LINE__ << std::endl; + if(match[1].str() != unit1 || match[2].str() != unit2) { std::cerr << "error on line: " << line_count << std::endl; return(1); } + if(!std::getline(conversions_file, line)) { std::cerr << "unexpected end of file." << std::endl; return(1); } ++line_count; + } else { + if(uses_absolute) { std::cerr << "error on line: " << line_count << std::endl; return(1); } + } +std::cout << __LINE__ << std::endl; + + + if(!boost::regex_match(line, match, endif)) { std::cerr << "error on line: " << line_count << std::endl; return(1); } + + } + } + + } catch(std::exception& e) { + std::cerr << e.what() << std::endl; + return(1); + } + +} diff --git a/src/boost/libs/units/test/fail_add_temperature.cpp b/src/boost/libs/units/test/fail_add_temperature.cpp new file mode 100644 index 00000000..979b2363 --- /dev/null +++ b/src/boost/libs/units/test/fail_add_temperature.cpp @@ -0,0 +1,38 @@ +// Boost.Units - A C++ library for zero-overhead dimensional analysis and +// unit/quantity manipulation and conversion +// +// Copyright (C) 2003-2008 Matthias Christian Schabel +// Copyright (C) 2008 Steven Watanabe +// +// Distributed under 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) + +/** +\file + +\brief fail_add_temperature.cpp + +\details +Verify that adding two absolute temeratures fails miserably. + +Output: +@verbatim +@endverbatim +**/ + +#include <boost/units/quantity.hpp> +#include <boost/units/absolute.hpp> +#include <boost/units/systems/si/temperature.hpp> + +namespace bu = boost::units; + +int main(int,char *[]) +{ + + bu::quantity<bu::absolute<bu::si::temperature> > q(2.0 * bu::absolute<bu::si::temperature>()); + + q += q; + + return 0; +} diff --git a/src/boost/libs/units/test/fail_adl_detail.cpp b/src/boost/libs/units/test/fail_adl_detail.cpp new file mode 100644 index 00000000..b44788df --- /dev/null +++ b/src/boost/libs/units/test/fail_adl_detail.cpp @@ -0,0 +1,48 @@ +// Boost.Units - A C++ library for zero-overhead dimensional analysis and +// unit/quantity manipulation and conversion +// +// Copyright (C) 2003-2008 Matthias Christian Schabel +// Copyright (C) 2008 Steven Watanabe +// +// Distributed under 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) + +/** +\file + +\brief fail_adl_detail.cpp + +\details +make sure that namespace detail is not pulled in by ADL. + +Output: +@verbatim +@endverbatim +**/ + +#include <boost/units/quantity.hpp> +#include <boost/units/systems/si.hpp> + +namespace bu = boost::units; + +namespace boost { +namespace units { +namespace detail { + + template<class T> + void this_function_should_not_be_found_by_adl(const T&) {}; + +} +} +} + +int main(int argc,char *argv[]) +{ + + bu::quantity<bu::si::energy> q; + + this_function_should_not_be_found_by_adl(q); + + return 0; +} diff --git a/src/boost/libs/units/test/fail_base_dimension.cpp b/src/boost/libs/units/test/fail_base_dimension.cpp new file mode 100644 index 00000000..1dd7a4a0 --- /dev/null +++ b/src/boost/libs/units/test/fail_base_dimension.cpp @@ -0,0 +1,32 @@ +// Boost.Units - A C++ library for zero-overhead dimensional analysis and +// unit/quantity manipulation and conversion +// +// Copyright (C) 2003-2008 Matthias Christian Schabel +// Copyright (C) 2008 Steven Watanabe +// +// Distributed under 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) + +/** +\file + +\brief fail_base_dimension.cpp + +\details +make sure that trying to use the same ordinal for multiple +base dimensions fails. + +Output: +@verbatim +@endverbatim +**/ + +#include <boost/units/base_dimension.hpp> + +struct dim1 : boost::units::base_dimension<dim1, 1> {}; +struct dim2 : boost::units::base_dimension<dim2, 1> {}; + +int main() +{ +} diff --git a/src/boost/libs/units/test/fail_heterogeneous_unit.cpp b/src/boost/libs/units/test/fail_heterogeneous_unit.cpp new file mode 100644 index 00000000..c0f7692e --- /dev/null +++ b/src/boost/libs/units/test/fail_heterogeneous_unit.cpp @@ -0,0 +1,46 @@ +// Boost.Units - A C++ library for zero-overhead dimensional analysis and +// unit/quantity manipulation and conversion +// +// Copyright (C) 2003-2008 Matthias Christian Schabel +// Copyright (C) 2008 Steven Watanabe +// +// Distributed under 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) + +/** +\file + +\brief fail_heterogeneous_unit.cpp + +\details +make sure that trying to bind a heterogeneous system to a different dimension fails. + +Output: +@verbatim +@endverbatim +**/ + +#include <boost/units/pow.hpp> +#include <boost/units/quantity.hpp> +#include <boost/units/systems/si.hpp> +#include <boost/units/systems/cgs.hpp> +//#include <boost/units/systems/conversions/convert_cgs_to_si.hpp> +//#include <boost/units/systems/conversions/convert_si_to_cgs.hpp> + +namespace bu = boost::units; + +template<class System> +bu::quantity<bu::unit<bu::energy_dimension, System> > f(bu::quantity<bu::unit<bu::length_dimension, System> > l) { + return(static_cast<bu::quantity<bu::unit<bu::energy_dimension, System> > >(f(static_cast<bu::quantity<bu::si::length> >(l)))); +} +bu::quantity<bu::si::energy> f(bu::quantity<bu::si::length> l) { + return(l * l * 2.0 * bu::si::kilograms / bu::pow<2>(bu::si::seconds)); +} + +int main() { + + f(1.0 * bu::pow<2>(bu::si::meters) / bu::cgs::centimeters); + + return(0); +} diff --git a/src/boost/libs/units/test/fail_implicit_conversion.cpp b/src/boost/libs/units/test/fail_implicit_conversion.cpp new file mode 100644 index 00000000..bedef1b5 --- /dev/null +++ b/src/boost/libs/units/test/fail_implicit_conversion.cpp @@ -0,0 +1,36 @@ +// Boost.Units - A C++ library for zero-overhead dimensional analysis and +// unit/quantity manipulation and conversion +// +// Copyright (C) 2003-2008 Matthias Christian Schabel +// Copyright (C) 2008 Steven Watanabe +// +// Distributed under 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) + +/** +\file + +\brief fail_implicit_conversion.cpp + +\details +Test implicit conversions for quantity. + +Output: +@verbatim +@endverbatim +**/ + +#include <boost/units/quantity.hpp> +#include <boost/units/systems/si.hpp> +#include <boost/units/systems/cgs.hpp> + +namespace bu = boost::units; + +int main(int,char *[]) +{ + const bu::quantity<bu::si::length> T1(2.0 * bu::si::meters); + const bu::quantity<bu::cgs::length> T2 = T1; + + return 0; +} diff --git a/src/boost/libs/units/test/fail_quantity_add.cpp b/src/boost/libs/units/test/fail_quantity_add.cpp new file mode 100644 index 00000000..e7e37d48 --- /dev/null +++ b/src/boost/libs/units/test/fail_quantity_add.cpp @@ -0,0 +1,35 @@ +// Boost.Units - A C++ library for zero-overhead dimensional analysis and +// unit/quantity manipulation and conversion +// +// Copyright (C) 2003-2008 Matthias Christian Schabel +// Copyright (C) 2008 Steven Watanabe +// +// Distributed under 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) + +/** +\file + +\brief fail_quantity_add.cpp + +\details +Test addition of quantities with different dimensions. + +Output: +@verbatim +@endverbatim +**/ + +#include <boost/units/quantity.hpp> +#include <boost/units/systems/si.hpp> + +namespace bu = boost::units; + +int main(int argc,char *argv[]) +{ + + 2.0 * bu::si::seconds + 2.0 * bu::si::meters; + + return 0; +} diff --git a/src/boost/libs/units/test/fail_quantity_add_assign.cpp b/src/boost/libs/units/test/fail_quantity_add_assign.cpp new file mode 100644 index 00000000..f31df615 --- /dev/null +++ b/src/boost/libs/units/test/fail_quantity_add_assign.cpp @@ -0,0 +1,36 @@ +// Boost.Units - A C++ library for zero-overhead dimensional analysis and +// unit/quantity manipulation and conversion +// +// Copyright (C) 2003-2008 Matthias Christian Schabel +// Copyright (C) 2008 Steven Watanabe +// +// Distributed under 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) + +/** +\file + +\brief fail_quantity_add_assign.cpp + +\details +Test += of quantity from different dimensions. + +Output: +@verbatim +@endverbatim +**/ + +#include <boost/units/quantity.hpp> +#include <boost/units/systems/si.hpp> + +namespace bu = boost::units; + +int main(int,char *[]) +{ + + bu::quantity<bu::si::length> T1; + T1 += 2.0 * bu::si::seconds; + + return 0; +} diff --git a/src/boost/libs/units/test/fail_quantity_assign.cpp b/src/boost/libs/units/test/fail_quantity_assign.cpp new file mode 100644 index 00000000..0f48bf21 --- /dev/null +++ b/src/boost/libs/units/test/fail_quantity_assign.cpp @@ -0,0 +1,36 @@ +// Boost.Units - A C++ library for zero-overhead dimensional analysis and +// unit/quantity manipulation and conversion +// +// Copyright (C) 2003-2008 Matthias Christian Schabel +// Copyright (C) 2008 Steven Watanabe +// +// Distributed under 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) + +/** +\file + +\brief fail_quantity_assign.cpp + +\details +Test assignment of quantity from different dimensions. + +Output: +@verbatim +@endverbatim +**/ + +#include <boost/units/quantity.hpp> +#include <boost/units/systems/si.hpp> + +namespace bu = boost::units; + +int main(int argc,char *argv[]) +{ + + const bu::quantity<bu::si::length> T1; + T1 = 2.0 * bu::si::seconds; + + return 0; +} diff --git a/src/boost/libs/units/test/fail_quantity_construct.cpp b/src/boost/libs/units/test/fail_quantity_construct.cpp new file mode 100644 index 00000000..94506583 --- /dev/null +++ b/src/boost/libs/units/test/fail_quantity_construct.cpp @@ -0,0 +1,35 @@ +// Boost.Units - A C++ library for zero-overhead dimensional analysis and +// unit/quantity manipulation and conversion +// +// Copyright (C) 2003-2008 Matthias Christian Schabel +// Copyright (C) 2008 Steven Watanabe +// +// Distributed under 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) + +/** +\file + +\brief fail_quantity_construct.cpp + +\details +Test construction of quantity from different dimensions. + +Output: +@verbatim +@endverbatim +**/ + +#include <boost/units/quantity.hpp> +#include <boost/units/systems/si.hpp> + +namespace bu = boost::units; + +int main(int,char *[]) +{ + + const bu::quantity<bu::si::length> T1(2.0 * bu::si::seconds); + + return 0; +} diff --git a/src/boost/libs/units/test/fail_quantity_non_unit.cpp b/src/boost/libs/units/test/fail_quantity_non_unit.cpp new file mode 100644 index 00000000..646160d6 --- /dev/null +++ b/src/boost/libs/units/test/fail_quantity_non_unit.cpp @@ -0,0 +1,37 @@ +// Boost.Units - A C++ library for zero-overhead dimensional analysis and +// unit/quantity manipulation and conversion +// +// Copyright (C) 2008 Steven Watanabe +// +// Distributed under 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) + +/** +\file + +\brief fail_quantity_non_unit.cpp + +\details + +Make sure that trying to use a base_unit as though +it were a unit fails. + +Output: +@verbatim +@endverbatim +**/ + +#include <boost/units/quantity.hpp> +#include <boost/units/base_units/si/meter.hpp> + +namespace bu = boost::units; + +int main(int,char *[]) +{ + + bu::quantity<bu::si::meter_base_unit> q; + + + return 0; +} diff --git a/src/boost/libs/units/test/fail_quantity_scalar_add.cpp b/src/boost/libs/units/test/fail_quantity_scalar_add.cpp new file mode 100644 index 00000000..94cc8f27 --- /dev/null +++ b/src/boost/libs/units/test/fail_quantity_scalar_add.cpp @@ -0,0 +1,35 @@ +// Boost.Units - A C++ library for zero-overhead dimensional analysis and +// unit/quantity manipulation and conversion +// +// Copyright (C) 2003-2008 Matthias Christian Schabel +// Copyright (C) 2008 Steven Watanabe +// +// Distributed under 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) + +/** +\file + +\brief fail_quantity_scalar_add.cpp + +\details +Test addition of quantity and scalar. + +Output: +@verbatim +@endverbatim +**/ + +#include <boost/units/quantity.hpp> +#include <boost/units/systems/si.hpp> + +namespace bu = boost::units; + +int main(int argc,char *argv[]) +{ + + 2.0 * bu::si::meters + 2.0; + + return 0; +} diff --git a/src/boost/libs/units/test/fail_quantity_scalar_sub.cpp b/src/boost/libs/units/test/fail_quantity_scalar_sub.cpp new file mode 100644 index 00000000..a4b93f13 --- /dev/null +++ b/src/boost/libs/units/test/fail_quantity_scalar_sub.cpp @@ -0,0 +1,35 @@ +// Boost.Units - A C++ library for zero-overhead dimensional analysis and +// unit/quantity manipulation and conversion +// +// Copyright (C) 2003-2008 Matthias Christian Schabel +// Copyright (C) 2008 Steven Watanabe +// +// Distributed under 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) + +/** +\file + +\brief fail_quantity_scalar_sub.cpp + +\details +Test subtraction of quantity and scalar. + +Output: +@verbatim +@endverbatim +**/ + +#include <boost/units/quantity.hpp> +#include <boost/units/systems/si.hpp> + +namespace bu = boost::units; + +int main(int argc,char *argv[]) +{ + + 2.0 * bu::si::meters - 2.0; + + return 0; +} diff --git a/src/boost/libs/units/test/fail_quantity_sub_assign.cpp b/src/boost/libs/units/test/fail_quantity_sub_assign.cpp new file mode 100644 index 00000000..65ea62fe --- /dev/null +++ b/src/boost/libs/units/test/fail_quantity_sub_assign.cpp @@ -0,0 +1,36 @@ +// Boost.Units - A C++ library for zero-overhead dimensional analysis and +// unit/quantity manipulation and conversion +// +// Copyright (C) 2003-2008 Matthias Christian Schabel +// Copyright (C) 2008 Steven Watanabe +// +// Distributed under 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) + +/** +\file + +\brief fail_quantity_sub_assign.cpp + +\details +Test -= of quantity from different dimensions. + +Output: +@verbatim +@endverbatim +**/ + +#include <boost/units/quantity.hpp> +#include <boost/units/systems/si.hpp> + +namespace bu = boost::units; + +int main(int,char *[]) +{ + + bu::quantity<bu::si::length> T1; + T1 -= 2.0 * bu::si::seconds; + + return 0; +} diff --git a/src/boost/libs/units/test/fail_quantity_subtract.cpp b/src/boost/libs/units/test/fail_quantity_subtract.cpp new file mode 100644 index 00000000..65f71e9b --- /dev/null +++ b/src/boost/libs/units/test/fail_quantity_subtract.cpp @@ -0,0 +1,35 @@ +// Boost.Units - A C++ library for zero-overhead dimensional analysis and +// unit/quantity manipulation and conversion +// +// Copyright (C) 2003-2008 Matthias Christian Schabel +// Copyright (C) 2008 Steven Watanabe +// +// Distributed under 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) + +/** +\file + +\brief fail_quantity_subtract.cpp + +\details +Test subtraction of quantities with different dimensions. + +Output: +@verbatim +@endverbatim +**/ + +#include <boost/units/quantity.hpp> +#include <boost/units/systems/si.hpp> + +namespace bu = boost::units; + +int main(int argc,char *argv[]) +{ + + 2.0 * bu::si::seconds - 2.0 * bu::si::meters; + + return 0; +} diff --git a/src/boost/libs/units/test/fail_quantity_unit_add.cpp b/src/boost/libs/units/test/fail_quantity_unit_add.cpp new file mode 100644 index 00000000..537656bc --- /dev/null +++ b/src/boost/libs/units/test/fail_quantity_unit_add.cpp @@ -0,0 +1,35 @@ +// Boost.Units - A C++ library for zero-overhead dimensional analysis and +// unit/quantity manipulation and conversion +// +// Copyright (C) 2003-2008 Matthias Christian Schabel +// Copyright (C) 2008 Steven Watanabe +// +// Distributed under 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) + +/** +\file + +\brief fail_quantity_unit_add.cpp + +\details +Test addition of quantity and unit. + +Output: +@verbatim +@endverbatim +**/ + +#include <boost/units/quantity.hpp> +#include <boost/units/systems/si.hpp> + +namespace bu = boost::units; + +int main(int argc,char *argv[]) +{ + + 2.0 * bu::si::meters + bu::si::meters; + + return 0; +} diff --git a/src/boost/libs/units/test/fail_quantity_unit_subtract.cpp b/src/boost/libs/units/test/fail_quantity_unit_subtract.cpp new file mode 100644 index 00000000..bcd9260c --- /dev/null +++ b/src/boost/libs/units/test/fail_quantity_unit_subtract.cpp @@ -0,0 +1,35 @@ +// Boost.Units - A C++ library for zero-overhead dimensional analysis and +// unit/quantity manipulation and conversion +// +// Copyright (C) 2003-2008 Matthias Christian Schabel +// Copyright (C) 2008 Steven Watanabe +// +// Distributed under 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) + +/** +\file + +\brief fail_quantity_unit_subtract.cpp + +\details +Test subtraction of quantity and unit. + +Output: +@verbatim +@endverbatim +**/ + +#include <boost/units/quantity.hpp> +#include <boost/units/systems/si.hpp> + +namespace bu = boost::units; + +int main(int argc,char *argv[]) +{ + + 2.0 * bu::si::meters - bu::si::meters; + + return 0; +} diff --git a/src/boost/libs/units/test/fail_scalar_quantity_add.cpp b/src/boost/libs/units/test/fail_scalar_quantity_add.cpp new file mode 100644 index 00000000..07225248 --- /dev/null +++ b/src/boost/libs/units/test/fail_scalar_quantity_add.cpp @@ -0,0 +1,35 @@ +// Boost.Units - A C++ library for zero-overhead dimensional analysis and +// unit/quantity manipulation and conversion +// +// Copyright (C) 2003-2008 Matthias Christian Schabel +// Copyright (C) 2008 Steven Watanabe +// +// Distributed under 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) + +/** +\file + +\brief fail_scalar_quantity_add.cpp + +\details +Test addition of scalar and quantity. + +Output: +@verbatim +@endverbatim +**/ + +#include <boost/units/quantity.hpp> +#include <boost/units/systems/si.hpp> + +namespace bu = boost::units; + +int main(int argc,char *argv[]) +{ + + 2.0 + 2.0 * bu::si::meters; + + return 0; +} diff --git a/src/boost/libs/units/test/fail_scalar_quantity_sub.cpp b/src/boost/libs/units/test/fail_scalar_quantity_sub.cpp new file mode 100644 index 00000000..44e6a7d1 --- /dev/null +++ b/src/boost/libs/units/test/fail_scalar_quantity_sub.cpp @@ -0,0 +1,35 @@ +// Boost.Units - A C++ library for zero-overhead dimensional analysis and +// unit/quantity manipulation and conversion +// +// Copyright (C) 2003-2008 Matthias Christian Schabel +// Copyright (C) 2008 Steven Watanabe +// +// Distributed under 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) + +/** +\file + +\brief fail_scalar_quantity_sub.cpp + +\details +Test subtraction of scalar and quantity. + +Output: +@verbatim +@endverbatim +**/ + +#include <boost/units/quantity.hpp> +#include <boost/units/systems/si.hpp> + +namespace bu = boost::units; + +int main(int argc,char *argv[]) +{ + + 2.0 - 2.0 * bu::si::meters; + + return 0; +} diff --git a/src/boost/libs/units/test/fail_unit_quantity_add.cpp b/src/boost/libs/units/test/fail_unit_quantity_add.cpp new file mode 100644 index 00000000..512d3329 --- /dev/null +++ b/src/boost/libs/units/test/fail_unit_quantity_add.cpp @@ -0,0 +1,35 @@ +// Boost.Units - A C++ library for zero-overhead dimensional analysis and +// unit/quantity manipulation and conversion +// +// Copyright (C) 2003-2008 Matthias Christian Schabel +// Copyright (C) 2008 Steven Watanabe +// +// Distributed under 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) + +/** +\file + +\brief fail_unit_quantity_add.cpp + +\details +Test addition of unit and quantity. + +Output: +@verbatim +@endverbatim +**/ + +#include <boost/units/quantity.hpp> +#include <boost/units/systems/si.hpp> + +namespace bu = boost::units; + +int main(int argc,char *argv[]) +{ + + bu::si::meters + 2.0 * bu::si::meters; + + return 0; +} diff --git a/src/boost/libs/units/test/fail_unit_quantity_subtract.cpp b/src/boost/libs/units/test/fail_unit_quantity_subtract.cpp new file mode 100644 index 00000000..512d3329 --- /dev/null +++ b/src/boost/libs/units/test/fail_unit_quantity_subtract.cpp @@ -0,0 +1,35 @@ +// Boost.Units - A C++ library for zero-overhead dimensional analysis and +// unit/quantity manipulation and conversion +// +// Copyright (C) 2003-2008 Matthias Christian Schabel +// Copyright (C) 2008 Steven Watanabe +// +// Distributed under 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) + +/** +\file + +\brief fail_unit_quantity_add.cpp + +\details +Test addition of unit and quantity. + +Output: +@verbatim +@endverbatim +**/ + +#include <boost/units/quantity.hpp> +#include <boost/units/systems/si.hpp> + +namespace bu = boost::units; + +int main(int argc,char *argv[]) +{ + + bu::si::meters + 2.0 * bu::si::meters; + + return 0; +} diff --git a/src/boost/libs/units/test/test_absolute.cpp b/src/boost/libs/units/test/test_absolute.cpp new file mode 100644 index 00000000..2908612f --- /dev/null +++ b/src/boost/libs/units/test/test_absolute.cpp @@ -0,0 +1,68 @@ +// Boost.Units - A C++ library for zero-overhead dimensional analysis and +// unit/quantity manipulation and conversion +// +// Copyright (C) 2003-2008 Matthias Christian Schabel +// Copyright (C) 2008 Steven Watanabe +// +// Distributed under 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) + +/** +\file + +\brief test_absolute.cpp + +\details +Test absolute units. + +Output: +@verbatim +@endverbatim +**/ + +#include <boost/units/quantity.hpp> +#include <boost/units/absolute.hpp> +#include <boost/units/unit.hpp> +#include <boost/units/make_system.hpp> +#include <boost/units/physical_dimensions.hpp> +#include <boost/units/base_units/si/kelvin.hpp> +#include <boost/units/base_units/temperature/celsius.hpp> +#include <boost/units/base_units/temperature/fahrenheit.hpp> + +#include <iostream> + +#include <boost/test/minimal.hpp> + +#define BOOST_UNITS_CHECK_CLOSE(a, b) (BOOST_CHECK((std::abs((a) - (b)) < .0000001))) + +namespace bu = boost::units; +using bu::si::kelvin_base_unit; +using bu::temperature::celsius_base_unit; +using bu::temperature::fahrenheit_base_unit; + +typedef bu::unit<bu::temperature_dimension,bu::make_system<kelvin_base_unit>::type> kelvin_type; + +typedef bu::unit<bu::temperature_dimension,bu::make_system<celsius_base_unit>::type> celsius_type; + +typedef bu::unit<bu::temperature_dimension,bu::make_system<fahrenheit_base_unit>::type> fahrenheit_type; + +int test_main(int,char *[]) +{ + BOOST_CONSTEXPR_OR_CONST bu::quantity<bu::absolute<fahrenheit_type> > q1(212.0 * bu::absolute<fahrenheit_type>()); + BOOST_CONSTEXPR_OR_CONST bu::quantity<bu::absolute<celsius_type> > q2(0.0 * bu::absolute<celsius_type>()); + BOOST_CONSTEXPR_OR_CONST bu::quantity<bu::absolute<fahrenheit_type> > q3(q2); + BOOST_CONSTEXPR_OR_CONST bu::quantity<fahrenheit_type> q4(q1 - q3); + + BOOST_UNITS_CHECK_CLOSE(q4.value(), 180.0); + + 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)); + + BOOST_UNITS_CHECK_CLOSE(q5.value(), 373.15); + + BOOST_CONSTEXPR_OR_CONST bu::quantity<bu::absolute<fahrenheit_type> > q6(q5); + + BOOST_UNITS_CHECK_CLOSE(q6.value(), 212.0); + + return(0); +} diff --git a/src/boost/libs/units/test/test_base_dimension.cpp b/src/boost/libs/units/test/test_base_dimension.cpp new file mode 100644 index 00000000..27cc6dcd --- /dev/null +++ b/src/boost/libs/units/test/test_base_dimension.cpp @@ -0,0 +1,31 @@ +// Boost.Units - A C++ library for zero-overhead dimensional analysis and +// unit/quantity manipulation and conversion +// +// Copyright (C) 2003-2008 Matthias Christian Schabel +// Copyright (C) 2008 Steven Watanabe +// +// Distributed under 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) + +/** +\file + +\brief test_base_dimension.cpp + +\details +Test base_dimension class. + +Output: +@verbatim +@endverbatim +**/ + +#include <boost/units/base_dimension.hpp> + +struct dimension : boost::units::base_dimension<dimension, 1> { + typedef boost::units::base_dimension<dimension, 1> base; +}; + +int main() { +} diff --git a/src/boost/libs/units/test/test_cmath.cpp b/src/boost/libs/units/test/test_cmath.cpp new file mode 100644 index 00000000..85a5119c --- /dev/null +++ b/src/boost/libs/units/test/test_cmath.cpp @@ -0,0 +1,173 @@ +// Boost.Units - A C++ library for zero-overhead dimensional analysis and +// unit/quantity manipulation and conversion +// +// Copyright (C) 2003-2008 Matthias Christian Schabel +// Copyright (C) 2008 Steven Watanabe +// +// Distributed under 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) + +/** +\file + +\brief test_units_1.cpp + +\details +Test unit class. + +Output: +@verbatim +@endverbatim +**/ + +#include <limits> + +#include <boost/units/cmath.hpp> + +#include "test_header.hpp" + +namespace bu = boost::units; + +int test_main(int,char *[]) +{ + BOOST_CONSTEXPR_OR_CONST double inf = std::numeric_limits<double>::infinity(), + nan = std::numeric_limits<double>::quiet_NaN(); + + // default constructor + BOOST_CONSTEXPR_OR_CONST bu::quantity<bu::energy> E1(0.0*bu::joules), + E2(inf*bu::joules), + E3(nan*bu::joules); + + BOOST_CHECK((bu::isfinite)(E1) == true); + BOOST_CHECK((bu::isfinite)(E2) == false); + BOOST_CHECK((bu::isfinite)(E3) == false); + + BOOST_CHECK((bu::isinf)(E1) == false); + BOOST_CHECK((bu::isinf)(E2) == true); + BOOST_CHECK((bu::isinf)(E3) == false); + + BOOST_CHECK((bu::isnan)(E1) == false); + BOOST_CHECK((bu::isnan)(E2) == false); + BOOST_CHECK((bu::isnan)(E3) == true); + + BOOST_CHECK((bu::isnormal)(E1) == false); + BOOST_CHECK((bu::isnormal)(E2) == false); + BOOST_CHECK((bu::isnormal)(E3) == false); + + BOOST_CONSTEXPR_OR_CONST bu::quantity<bu::energy> E4(-2.5*bu::joules), + E5(2.5*bu::joules); + + BOOST_CHECK((bu::isgreater)(E4,E5) == false); + BOOST_CHECK((bu::isgreater)(E5,E4) == true); + BOOST_CHECK((bu::isgreater)(E4,E4) == false); + BOOST_CHECK((bu::isgreater)(E3,E4) == false); + BOOST_CHECK((bu::isgreater)(E4,E3) == false); + + BOOST_CHECK((bu::isgreaterequal)(E4,E5) == false); + BOOST_CHECK((bu::isgreaterequal)(E5,E4) == true); + BOOST_CHECK((bu::isgreaterequal)(E4,E4) == true); + BOOST_CHECK((bu::isgreaterequal)(E3,E4) == false); + BOOST_CHECK((bu::isgreaterequal)(E4,E3) == false); + + BOOST_CHECK((bu::isless)(E4,E5) == true); + BOOST_CHECK((bu::isless)(E5,E4) == false); + BOOST_CHECK((bu::isless)(E4,E4) == false); + BOOST_CHECK((bu::isless)(E3,E4) == false); + BOOST_CHECK((bu::isless)(E4,E3) == false); + + BOOST_CHECK((bu::islessequal)(E4,E5) == true); + BOOST_CHECK((bu::islessequal)(E5,E4) == false); + BOOST_CHECK((bu::islessequal)(E4,E4) == true); + BOOST_CHECK((bu::islessequal)(E3,E4) == false); + BOOST_CHECK((bu::islessequal)(E4,E3) == false); + + BOOST_CHECK((bu::islessgreater)(E4,E5) == true); + BOOST_CHECK((bu::islessgreater)(E5,E4) == true); + BOOST_CHECK((bu::islessgreater)(E4,E4) == false); + BOOST_CHECK((bu::islessgreater)(E3,E4) == false); + BOOST_CHECK((bu::islessgreater)(E4,E3) == false); + + BOOST_CHECK((bu::isunordered)(E4,E5) == false); + BOOST_CHECK((bu::isunordered)(E5,E4) == false); + BOOST_CHECK((bu::isunordered)(E4,E4) == false); + BOOST_CHECK((bu::isunordered)(E3,E4) == true); + BOOST_CHECK((bu::isunordered)(E4,E3) == true); + + BOOST_CHECK((bu::abs)(E4) == E5); + BOOST_CHECK((bu::ceil)(E4) == -2.0*bu::joules); + BOOST_CHECK((bu::copysign)(E4,E5) == E5); + BOOST_CHECK((bu::fabs)(E4) == E5); + BOOST_CHECK((bu::floor)(E4) == -3.0*bu::joules); + BOOST_CHECK((bu::fdim)(E4,E5) == 0.0*bu::joules); + BOOST_CHECK((bu::fdim)(E5,E4) == E5-E4); + + BOOST_CONSTEXPR_OR_CONST bu::quantity<bu::length> L1(3.0*bu::meters), + L2(4.0*bu::meters); + BOOST_CONSTEXPR_OR_CONST bu::quantity<bu::area> A1(4.0*bu::square_meters), + A2(L1*L2+A1); + +#if 0 + BOOST_CHECK((bu::fma)(L1,L2,A1) == A2); +#endif + + BOOST_CHECK((bu::fmax)(E4,E5) == E5); + BOOST_CHECK((bu::fmin)(E4,E5) == E4); + + // need to test fpclassify + + BOOST_CHECK(bu::hypot(L1,L2) == 5.0*bu::meters); + +#if 0 + +// BOOST_CHECK(bu::llrint(E4).value() == bu::detail::llrint(E4.value())); +// BOOST_CHECK(bu::llround(E4).value() == bu::detail::llround(E4.value())); + BOOST_CHECK((bu::nearbyint)(E4).value() == (bu::detail::nearbyint)(E4.value())); + BOOST_CHECK((bu::rint)(E4).value() == (bu::detail::rint)(E4.value())); + +#endif + + BOOST_CHECK((bu::nextafter)(E4,E5).value() == (boost::math::nextafter)(E4.value(),E5.value())); + BOOST_CHECK((bu::nextafter)(E5,E4).value() == (boost::math::nextafter)(E5.value(),E4.value())); + + BOOST_CHECK((bu::nexttoward)(E4,E5).value() == (boost::math::nextafter)(E4.value(),E5.value())); + BOOST_CHECK((bu::nexttoward)(E5,E4).value() == (boost::math::nextafter)(E5.value(),E4.value())); + + BOOST_CHECK((bu::round)(E4 - 0.00000000001 * bu::joules) == -3.0*bu::joules); + BOOST_CHECK((bu::round)(E5 + 0.00000000001 * bu::joules) == 3.0*bu::joules); + BOOST_CHECK((bu::signbit)(E4) != 0); + BOOST_CHECK((bu::signbit)(E5) == 0); + BOOST_CHECK((bu::trunc)(E4) == -2.0*bu::joules); + BOOST_CHECK((bu::trunc)(E5) == 2.0*bu::joules); + + BOOST_CHECK((bu::fmod)(E4,E5) == -0.0*bu::joules); + + bu::quantity<bu::energy> pint; + + BOOST_CHECK((bu::modf)(E4,&pint) == -0.5*bu::joules); + BOOST_CHECK(pint == -2.0*bu::joules); + + int ex; + const bu::quantity<bu::energy> E6((bu::frexp)(E4,&ex)); + + BOOST_CHECK(E6 == -0.625*bu::joules); + BOOST_CHECK(ex == 2); + BOOST_CHECK((bu::ldexp)(E6,ex) == E4); + + BOOST_CONSTEXPR_OR_CONST bu::quantity<bu::dimensionless> E7(1.0); + + BOOST_CHECK(bu::pow(E7,E7) == 1.0*1.0); + + const bu::quantity<bu::dimensionless> E8((bu::exp)(E7)); + + BOOST_CHECK(std::abs(E8 - std::exp(1.0)) < .000001); + BOOST_CHECK(bu::log(E8) == E7); + + BOOST_CONSTEXPR_OR_CONST bu::quantity<bu::dimensionless> E9(100.0); + + BOOST_CHECK(bu::log10(E9) == 2.0); + + BOOST_CHECK(bu::sqrt(A1) == 2.0*bu::meters); + + return 0; +} diff --git a/src/boost/libs/units/test/test_complicated_system.cpp b/src/boost/libs/units/test/test_complicated_system.cpp new file mode 100644 index 00000000..4ac3a82d --- /dev/null +++ b/src/boost/libs/units/test/test_complicated_system.cpp @@ -0,0 +1,96 @@ +// Boost.Units - A C++ library for zero-overhead dimensional analysis and +// unit/quantity manipulation and conversion +// +// Copyright (C) 2003-2008 Matthias Christian Schabel +// Copyright (C) 2007-2008 Steven Watanabe +// +// Distributed under 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) + +#include <boost/type_traits/is_same.hpp> +#include <boost/mpl/assert.hpp> + +#include <boost/units/base_unit.hpp> +#include <boost/units/derived_dimension.hpp> +#include <boost/units/make_system.hpp> +#include <boost/units/operators.hpp> +#include <boost/units/reduce_unit.hpp> +#include <boost/units/unit.hpp> + +#include <boost/units/physical_dimensions/current.hpp> +#include <boost/units/physical_dimensions/electric_potential.hpp> +#include <boost/units/physical_dimensions/energy.hpp> +#include <boost/units/physical_dimensions/force.hpp> +#include <boost/units/physical_dimensions/length.hpp> +#include <boost/units/physical_dimensions/mass.hpp> +#include <boost/units/physical_dimensions/time.hpp> + +namespace test_system1 { + +// the base units in the system will be: +// +// volts = m^2 kg s^-2 C^-1 +// newtons = m kg s^-2 +// joules = m^2 kg s^-2 + +// we will find the representation of m^-1 C^-1 = V N J^-2 = m^-1 C^-1 + +// reducing the system should generate the matrix equation +// 2 1 2 +// 1 1 1 x = c +// -2 -2 -2 +// -1 0 0 + +struct volt : boost::units::base_unit<volt, boost::units::electric_potential_dimension, 1> {}; +struct newton : boost::units::base_unit<newton, boost::units::force_dimension, 2> {}; +struct joule : boost::units::base_unit<joule, boost::units::energy_dimension, 3> {}; + +typedef boost::units::make_system<volt, newton, joule>::type complicated_system; + +typedef boost::units::derived_dimension< + boost::units::length_base_dimension, -1, + boost::units::time_base_dimension, -1, + boost::units::current_base_dimension, -1 +>::type dimension; + +typedef boost::units::reduce_unit<boost::units::unit<dimension, complicated_system> >::type reduced; + +typedef boost::units::divide_typeof_helper< + boost::units::multiply_typeof_helper<volt::unit_type, newton::unit_type>::type, + boost::units::power_typeof_helper<joule::unit_type, boost::units::static_rational<2> >::type +>::type expected; + +void test() { + BOOST_MPL_ASSERT((boost::is_same<reduced, expected>)); +} + +} + +namespace test_system2 { + +// the base units in the system will be: +// +// kilograms = kg +// meters = m + +// we will find the representation of m and kg + +// reducing the system should generate the matrix equation +// 0 1 +// 1 0 x = c + +struct kilogram : boost::units::base_unit<kilogram, boost::units::mass_dimension, 4> {}; +struct meter : boost::units::base_unit<meter, boost::units::length_dimension, 5> {}; + +typedef boost::units::make_system<meter, kilogram>::type mk_system; + +typedef boost::units::reduce_unit<boost::units::unit<boost::units::mass_dimension, mk_system> >::type mass_unit; +typedef boost::units::reduce_unit<boost::units::unit<boost::units::length_dimension, mk_system> >::type length_unit; + +void test() { + BOOST_MPL_ASSERT((boost::is_same<mass_unit, kilogram::unit_type>)); + BOOST_MPL_ASSERT((boost::is_same<length_unit, meter::unit_type>)); +} + +} diff --git a/src/boost/libs/units/test/test_constants.cpp b/src/boost/libs/units/test/test_constants.cpp new file mode 100644 index 00000000..55b45a1c --- /dev/null +++ b/src/boost/libs/units/test/test_constants.cpp @@ -0,0 +1,87 @@ +// Boost.Units - A C++ library for zero-overhead dimensional analysis and +// unit/quantity manipulation and conversion +// +// Copyright (C) 2003-2009 Matthias Christian Schabel +// Copyright (C) 2007-2009 Steven Watanabe +// +// Distributed under 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) + +/** +\file + +\brief test_constants.cpp + +\details +Test all combinations of operators with the constants. + +**/ + +#include <boost/units/systems/detail/constants.hpp> +#include <boost/units/quantity.hpp> +#include <boost/units/pow.hpp> +#include <boost/units/systems/si/length.hpp> +#include <boost/units/systems/si/time.hpp> + +using boost::units::quantity; +using boost::units::si::length; +using boost::units::si::meters; +using boost::units::si::seconds; +using boost::units::static_rational; +using boost::units::pow; +using boost::units::root; + +BOOST_UNITS_PHYSICAL_CONSTANT(length_constant, quantity<length>, 2.0 * meters, 0.5 * meters); + +template<class T> +void check_same(const T&, const T&); + +template<class T> +typename T::value_type unwrap(const boost::units::constant<T>&); + +template<class T> +T unwrap(const T&); + +#define BOOST_UNITS_CHECK_RESULT(arg1, op, arg2) check_same((arg1) op (arg2), unwrap(arg1) op unwrap(arg2)); + +void test_add() { + BOOST_UNITS_CHECK_RESULT(length_constant, +, length_constant); + BOOST_UNITS_CHECK_RESULT(length_constant, +, 1.0 * meters); + BOOST_UNITS_CHECK_RESULT(1.0* meters, +, length_constant); +} + +void test_subtract() { + BOOST_UNITS_CHECK_RESULT(length_constant, -, length_constant); + BOOST_UNITS_CHECK_RESULT(length_constant, -, 1.0 * meters); + BOOST_UNITS_CHECK_RESULT(1.0* meters, -, length_constant); +} + +void test_multiply() { + BOOST_UNITS_CHECK_RESULT(length_constant, *, length_constant); + BOOST_UNITS_CHECK_RESULT(length_constant, *, 1.0 * seconds); + BOOST_UNITS_CHECK_RESULT(1.0 * seconds, *, length_constant); + BOOST_UNITS_CHECK_RESULT(length_constant, *, 1.0); + BOOST_UNITS_CHECK_RESULT(1.0, *, length_constant); + BOOST_UNITS_CHECK_RESULT(length_constant, *, seconds); + BOOST_UNITS_CHECK_RESULT(seconds, *, length_constant); +} + +void test_divide() { + BOOST_UNITS_CHECK_RESULT(length_constant, /, length_constant); + BOOST_UNITS_CHECK_RESULT(length_constant, /, 1.0 * seconds); + BOOST_UNITS_CHECK_RESULT(1.0 * seconds, /, length_constant); + BOOST_UNITS_CHECK_RESULT(length_constant, /, 1.0); + BOOST_UNITS_CHECK_RESULT(1.0, /, length_constant); + BOOST_UNITS_CHECK_RESULT(length_constant, /, seconds); + BOOST_UNITS_CHECK_RESULT(seconds, /, length_constant); +} + +void test_pow() { + check_same(pow<2>(length_constant), pow<2>(unwrap(length_constant))); + check_same(root<2>(length_constant), root<2>(unwrap(length_constant))); + check_same(pow<5>(length_constant), pow<5>(unwrap(length_constant))); + check_same(root<5>(length_constant), root<5>(unwrap(length_constant))); + check_same(pow<static_rational<2, 3> >(length_constant), pow<static_rational<2, 3> >(unwrap(length_constant))); + check_same(root<static_rational<2, 3> >(length_constant), root<static_rational<2, 3> >(unwrap(length_constant))); +} diff --git a/src/boost/libs/units/test/test_conversion.cpp b/src/boost/libs/units/test/test_conversion.cpp new file mode 100644 index 00000000..17015245 --- /dev/null +++ b/src/boost/libs/units/test/test_conversion.cpp @@ -0,0 +1,110 @@ +// Boost.Units - A C++ library for zero-overhead dimensional analysis and +// unit/quantity manipulation and conversion +// +// Copyright (C) 2003-2008 Matthias Christian Schabel +// Copyright (C) 2008 Steven Watanabe +// +// Distributed under 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) + +/** +\file + +\brief test_conversion.cpp + +\details +Test conversion between quantities. + +Output: +@verbatim +@endverbatim +**/ + +#include <boost/units/quantity.hpp> +#include <boost/units/systems/si.hpp> +#include <boost/units/systems/cgs.hpp> + +#include <iostream> + +#define BOOST_TEST_MAIN + +#include <boost/test/unit_test.hpp> + +#define BOOST_UNITS_CHECK_CLOSE(a, b) BOOST_CHECK_CLOSE_FRACTION(a, b, .0000001) + +namespace bu = boost::units; + +typedef bu::si::length si_length; +typedef bu::si::time si_time; +typedef bu::si::mass si_mass; +typedef bu::si::area si_area; + +typedef bu::cgs::length cgs_length; +typedef bu::cgs::time cgs_time; +typedef bu::cgs::mass cgs_mass; +typedef bu::cgs::area cgs_area; + +typedef bu::multiply_typeof_helper<si_length, cgs_length>::type mixed_length; +typedef bu::multiply_typeof_helper<si_time, cgs_time>::type mixed_time; + +typedef bu::divide_typeof_helper<bu::multiply_typeof_helper<si_mass,cgs_area>::type, mixed_time>::type mixed_energy_1; +typedef bu::divide_typeof_helper<bu::multiply_typeof_helper<cgs_mass,mixed_length>::type, + bu::multiply_typeof_helper<cgs_time,cgs_time>::type >::type mixed_energy_2; + +BOOST_AUTO_TEST_CASE(test_conversion) { + BOOST_CHECK_EQUAL(1, 1); + BOOST_CONSTEXPR_OR_CONST bu::quantity<mixed_length> a1(2.0 * mixed_length()); + BOOST_CONSTEXPR_OR_CONST bu::quantity<si_area> a2(a1); + + BOOST_UNITS_CHECK_CLOSE(a2.value(), .02); + + BOOST_CONSTEXPR_OR_CONST bu::quantity<mixed_length> a3(a2); + + BOOST_UNITS_CHECK_CLOSE(a3.value(), 2.0); + + BOOST_CONSTEXPR_OR_CONST bu::quantity<mixed_energy_1> e1(2.0 * mixed_energy_1()); + BOOST_CONSTEXPR_OR_CONST bu::quantity<mixed_energy_2> e2(e1); + + BOOST_UNITS_CHECK_CLOSE(e2.value(), 20.0); + + BOOST_CONSTEXPR_OR_CONST bu::quantity<bu::si::energy> e3(e1); + BOOST_UNITS_CHECK_CLOSE(e3.value(), .0002); + BOOST_CONSTEXPR_OR_CONST bu::quantity<mixed_energy_2> e4(e3); + BOOST_UNITS_CHECK_CLOSE(e4.value(), 20.0); + + BOOST_CONSTEXPR_OR_CONST bu::quantity<bu::cgs::force> F0 = 20 * bu::cgs::dyne; + BOOST_UNITS_CHECK_CLOSE(F0.value(), 20.0); + + BOOST_CONSTEXPR_OR_CONST bu::quantity<bu::si::force> F3(F0); + BOOST_UNITS_CHECK_CLOSE(F3.value(), 2.0e-4); + + BOOST_CONSTEXPR_OR_CONST bu::quantity<bu::si::force> F5(20 * bu::cgs::dyne); + BOOST_UNITS_CHECK_CLOSE(F5.value(), 2.0e-4); + + // same type + BOOST_CHECK_EQUAL(boost::units::conversion_factor(si_length(), si_length()), 1.0); +} + +BOOST_AUTO_TEST_CASE(test_dimensionless_conversions) { + typedef bu::divide_typeof_helper<bu::cgs::force, bu::si::force>::type mixed_dimensionless; + + BOOST_CONSTEXPR_OR_CONST bu::quantity<bu::si::dimensionless> dimensionless_test1(1.0*bu::cgs::dyne/bu::si::newton); + BOOST_CHECK(dimensionless_test1 == 1e-5); + + typedef bu::multiply_typeof_helper<bu::si::length, bu::cgs::length>::type m_cm; + typedef bu::divide_typeof_helper<m_cm, m_cm>::type heterogeneous_dimensionless; + BOOST_CONSTEXPR_OR_CONST bu::quantity<heterogeneous_dimensionless> dimensionless_test2(1.0*bu::cgs::dyne/bu::si::newton); + BOOST_CHECK(dimensionless_test2.value() == 1e-5); + BOOST_CONSTEXPR_OR_CONST bu::quantity<bu::divide_typeof_helper<bu::cgs::force, bu::si::force>::type> dimensionless_test3(dimensionless_test2); + BOOST_UNITS_CHECK_CLOSE(dimensionless_test3.value(), 1.0); + + BOOST_UNITS_CHECK_CLOSE(boost::units::conversion_factor(mixed_dimensionless(), heterogeneous_dimensionless()), 1e-5); + BOOST_UNITS_CHECK_CLOSE(boost::units::conversion_factor(heterogeneous_dimensionless(), mixed_dimensionless()), 1e5); + + + //m/cm -> g/kg + BOOST_CONSTEXPR_OR_CONST bu::quantity<bu::divide_typeof_helper<bu::si::length, bu::cgs::length>::type> dimensionless_test4(2.0 * bu::si::meters / bu::cgs::centimeters); + BOOST_CONSTEXPR_OR_CONST bu::quantity<bu::divide_typeof_helper<bu::cgs::mass, bu::si::mass>::type> dimensionless_test5(dimensionless_test4); + BOOST_UNITS_CHECK_CLOSE(dimensionless_test5.value(), 2e5); +} diff --git a/src/boost/libs/units/test/test_custom_unit.cpp b/src/boost/libs/units/test/test_custom_unit.cpp new file mode 100644 index 00000000..42e7d6e8 --- /dev/null +++ b/src/boost/libs/units/test/test_custom_unit.cpp @@ -0,0 +1,84 @@ +// Boost.Units - A C++ library for zero-overhead dimensional analysis and +// unit/quantity manipulation and conversion +// +// Copyright (C) 2008 Matthias Christian Schabel +// Copyright (C) 2008 Steven Watanabe +// +// Distributed under 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) + +/** +\file + +\brief test_custom_unit.cpp + +\details +Make sure that a minimal + - * / unit class is fully functional. + +Output: +@verbatim +@endverbatim +**/ + +#include <boost/units/quantity.hpp> + +#include <boost/test/minimal.hpp> + +namespace bu = boost::units; + +template<int Mass, int Length, int Time> +struct simple_unit {}; + +BOOST_TYPEOF_REGISTER_TEMPLATE(simple_unit, (int)(int)(int)) + +template<int Mass, int Length, int Time> +simple_unit<Mass, Length, Time> operator+(const simple_unit<Mass, Length, Time>&, + const simple_unit<Mass, Length, Time>&) +{ + return simple_unit<Mass, Length, Time>(); +} + +template<int Mass, int Length, int Time> +simple_unit<Mass, Length, Time> operator-(const simple_unit<Mass, Length, Time>&, + const simple_unit<Mass, Length, Time>&) +{ + return simple_unit<Mass, Length, Time>(); +} + +template<int Mass1, int Length1, int Time1, int Mass2, int Length2, int Time2> +simple_unit<Mass1 + Mass2, Length1 + Length2, Time1 + Time2> +operator*(const simple_unit<Mass1, Length1, Time1>&, + const simple_unit<Mass2, Length2, Time2>&) +{ + return simple_unit<Mass1 + Mass2, Length1 + Length2, Time1 + Time2>(); +} + +template<int Mass1, int Length1, int Time1, int Mass2, int Length2, int Time2> +simple_unit<Mass1 - Mass2, Length1 - Length2, Time1 - Time2> +operator/(const simple_unit<Mass1, Length1, Time1>&, + const simple_unit<Mass2, Length2, Time2>&) +{ + return simple_unit<Mass1 - Mass2, Length1 - Length2, Time1 - Time2>(); +} + +int test_main(int,char *[]) +{ + bu::quantity<simple_unit<1, 0, 0> > mass = bu::quantity<simple_unit<1, 0, 0> >::from_value(2); + bu::quantity<simple_unit<0, 1, 0> > length = bu::quantity<simple_unit<0, 1, 0> >::from_value(4); + + bu::quantity<simple_unit<1, 1, 0> > ml = mass * length; + bu::quantity<simple_unit<1, -1, 0> > m_per_l = mass/length; + + BOOST_CHECK(ml.value() == 8); + BOOST_CHECK(m_per_l.value() == 0.5); + + mass += mass; + + BOOST_CHECK(mass.value() == 4); + + length -= length; + BOOST_CHECK(length.value() == 0); + + return 0; +} diff --git a/src/boost/libs/units/test/test_default_conversion.cpp b/src/boost/libs/units/test/test_default_conversion.cpp new file mode 100644 index 00000000..f05aac69 --- /dev/null +++ b/src/boost/libs/units/test/test_default_conversion.cpp @@ -0,0 +1,78 @@ +// Boost.Units - A C++ library for zero-overhead dimensional analysis and +// unit/quantity manipulation and conversion +// +// Copyright (C) 2003-2008 Matthias Christian Schabel +// Copyright (C) 2008 Steven Watanabe +// +// Distributed under 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) + +#include <boost/test/minimal.hpp> + +#include <boost/units/base_dimension.hpp> +#include <boost/units/base_unit.hpp> +#include <boost/units/make_system.hpp> +#include <boost/units/scaled_base_unit.hpp> +#include <boost/units/conversion.hpp> +#include <boost/units/unit.hpp> + +struct dimension1_tag : boost::units::base_dimension<dimension1_tag, 1> {}; +struct dimension2_tag : boost::units::base_dimension<dimension2_tag, 2> {}; + +typedef dimension1_tag::dimension_type dimension1; +typedef dimension2_tag::dimension_type dimension2; +typedef boost::mpl::times<dimension1, dimension2>::type dimension12; + +struct unit1_tag : boost::units::base_unit<unit1_tag, dimension1, 1> {}; +struct unit2_tag : boost::units::base_unit<unit2_tag, dimension1, 2> {}; +struct unit3_tag : boost::units::base_unit<unit3_tag, dimension1, 3> {}; +struct unit4_tag : boost::units::base_unit<unit4_tag, dimension2, 4> {}; +struct unit5_tag : boost::units::base_unit<unit5_tag, dimension12, 5> {}; +struct unit6_tag : boost::units::base_unit<unit6_tag, dimension1, 6> {}; +struct unit7_tag : boost::units::base_unit<unit7_tag, dimension1, 7> {}; + +BOOST_UNITS_DEFINE_CONVERSION_FACTOR(unit1_tag, unit2_tag, double, 2.0); +BOOST_UNITS_DEFINE_CONVERSION_FACTOR(unit2_tag, unit3_tag, double, 3.0); +BOOST_UNITS_DEFINE_CONVERSION_FACTOR(unit6_tag, unit3_tag, double, 5.0); +BOOST_UNITS_DEFINE_CONVERSION_FACTOR(unit7_tag, unit1_tag, double, 7.0); + +typedef boost::units::multiply_typeof_helper<unit3_tag::unit_type, unit4_tag::unit_type>::type unit34_type; +BOOST_UNITS_DEFINE_CONVERSION_FACTOR(unit5_tag, unit34_type , double, 5.0); + +template<class BaseUnit> +struct make_unit { + typedef boost::units::unit< + typename BaseUnit::dimension_type, + typename boost::units::make_system<BaseUnit>::type> type; +}; + +BOOST_UNITS_DEFAULT_CONVERSION(unit1_tag, unit2_tag); +BOOST_UNITS_DEFAULT_CONVERSION(unit3_tag, unit2_tag); +BOOST_UNITS_DEFAULT_CONVERSION(unit5_tag, unit34_type); +BOOST_UNITS_DEFAULT_CONVERSION(unit6_tag, make_unit<unit3_tag>::type); +BOOST_UNITS_DEFAULT_CONVERSION(unit7_tag, make_unit<unit1_tag>::type); + +int test_main(int, char*[]) { + BOOST_CONSTEXPR_OR_CONST double value1 = boost::units::conversion_factor(unit3_tag::unit_type(), unit1_tag::unit_type()); + BOOST_CHECK(std::abs(value1 - 1.0/6.0) < .0000000001); + BOOST_CONSTEXPR_OR_CONST double value2 = boost::units::conversion_factor(unit5_tag::unit_type() / unit4_tag::unit_type(), unit1_tag::unit_type()); + BOOST_CHECK(std::abs(value2 - 5.0/6.0) < .0000000001); + typedef boost::units::scaled_base_unit<unit5_tag, boost::units::scale<2, boost::units::static_rational<1> > > scaled_unit5_tag; + BOOST_CONSTEXPR_OR_CONST double value3 = boost::units::conversion_factor(scaled_unit5_tag::unit_type() / unit4_tag::unit_type(), unit1_tag::unit_type()); + BOOST_CHECK(std::abs(value3 - 10.0/6.0) < .0000000001); + + // check homogeneous unit conversions + BOOST_CONSTEXPR_OR_CONST double value4 = boost::units::conversion_factor(make_unit<unit3_tag>::type(), make_unit<unit1_tag>::type()); + BOOST_CHECK(std::abs(value4 - 1.0/6.0) < .0000000001); + BOOST_CONSTEXPR_OR_CONST double value5 = boost::units::conversion_factor(unit3_tag::unit_type(), make_unit<unit1_tag>::type()); + BOOST_CHECK(std::abs(value5 - 1.0/6.0) < .0000000001); + BOOST_CONSTEXPR_OR_CONST double value6 = boost::units::conversion_factor(make_unit<unit3_tag>::type(), unit1_tag::unit_type()); + BOOST_CHECK(std::abs(value6 - 1.0/6.0) < .0000000001); + + // check chained homogeneous conversions + BOOST_CONSTEXPR_OR_CONST double value7 = boost::units::conversion_factor(unit6_tag::unit_type(), unit7_tag::unit_type()); + BOOST_CHECK(std::abs(value7 - 5.0/42.0) < .0000000001); + + return(0); +} diff --git a/src/boost/libs/units/test/test_dimensionless_ice1.cpp b/src/boost/libs/units/test/test_dimensionless_ice1.cpp new file mode 100644 index 00000000..06ab61ee --- /dev/null +++ b/src/boost/libs/units/test/test_dimensionless_ice1.cpp @@ -0,0 +1,26 @@ +// Boost.Units - A C++ library for zero-overhead dimensional analysis and +// unit/quantity manipulation and conversion +// +// Copyright (C) 2003-2008 Matthias Christian Schabel +// Copyright (C) 2008 Steven Watanabe +// +// Distributed under 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) + +#include <boost/core/ignore_unused.hpp> +#include <boost/units/systems/si/base.hpp> +#include <boost/units/quantity.hpp> + +void foo() +{ + BOOST_CONSTEXPR_OR_CONST boost::units::quantity<boost::units::si::dimensionless> d = boost::units::quantity< boost::units::si::dimensionless >(); + boost::ignore_unused(d); +} + +#include <boost/test/test_tools.hpp> + +int main() +{ + BOOST_CHECK( 1 == 2 ); +} diff --git a/src/boost/libs/units/test/test_dimensionless_ice2.cpp b/src/boost/libs/units/test/test_dimensionless_ice2.cpp new file mode 100644 index 00000000..b04e6544 --- /dev/null +++ b/src/boost/libs/units/test/test_dimensionless_ice2.cpp @@ -0,0 +1,25 @@ +// Boost.Units - A C++ library for zero-overhead dimensional analysis and +// unit/quantity manipulation and conversion +// +// Copyright (C) 2003-2008 Matthias Christian Schabel +// Copyright (C) 2008 Steven Watanabe +// +// Distributed under 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) + +#include <boost/units/systems/si/length.hpp> +#include <boost/units/systems/cgs/length.hpp> +#include <boost/units/quantity.hpp> + +void foo() +{ + BOOST_CONSTEXPR_OR_CONST boost::units::quantity<boost::units::si::dimensionless> d(1.0 * boost::units::si::meters / boost::units::cgs::centimeters); +} + +#include <boost/test/test_tools.hpp> + +int main() +{ + BOOST_CHECK( 1 == 2 ); +} diff --git a/src/boost/libs/units/test/test_dimensionless_quantity.cpp b/src/boost/libs/units/test/test_dimensionless_quantity.cpp new file mode 100644 index 00000000..197d7c9d --- /dev/null +++ b/src/boost/libs/units/test/test_dimensionless_quantity.cpp @@ -0,0 +1,216 @@ +// Boost.Units - A C++ library for zero-overhead dimensional analysis and +// unit/quantity manipulation and conversion +// +// Copyright (C) 2003-2008 Matthias Christian Schabel +// Copyright (C) 2008 Steven Watanabe +// +// Distributed under 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) + +/** +\file + +\brief test_dimensionless_quantity.cpp + +\details +Test unit class. + +Output: +@verbatim +@endverbatim +**/ + +#include "test_header.hpp" + +#include <boost/units/pow.hpp> + +namespace bu = boost::units; + +BOOST_STATIC_CONSTEXPR double E_ = 2.718281828459045235360287471352662497757; + +int test_main(int,char *[]) +{ + // default constructor + BOOST_CONSTEXPR_OR_CONST bu::quantity<bu::dimensionless> E1; + BOOST_CHECK(E1.value() == double()); + + // value_type constructor + BOOST_CONSTEXPR_OR_CONST bu::quantity<bu::dimensionless> E2(E_); + BOOST_CHECK(E2.value() == E_); + + // copy constructor + BOOST_CONSTEXPR_OR_CONST bu::quantity<bu::dimensionless> E3(E2); + BOOST_CHECK(E3.value() == E_); + + // operator= + BOOST_CONSTEXPR_OR_CONST bu::quantity<bu::dimensionless> E4 = E2; + BOOST_CHECK(E4.value() == E_); + + // implicit copy constructor value_type conversion + BOOST_CONSTEXPR_OR_CONST bu::quantity<bu::dimensionless,float> E5(E2); + BOOST_UNITS_CHECK_CLOSE(E5.value(), float(E_)); + + BOOST_CONSTEXPR_OR_CONST bu::quantity<bu::dimensionless,long> E6(E2); + BOOST_CHECK(E6.value() == long(E_)); + + // implicit operator= value_type conversion + // narrowing conversion disallowed +// BOOST_CONSTEXPR_OR_CONST bu::quantity<bu::dimensionless,float> E7 = E2; +// BOOST_UNITS_CHECK_CLOSE(E7.value(),float(E_)); + + // narrowing conversion disallowed +// BOOST_CONSTEXPR_OR_CONST bu::quantity<bu::dimensionless,long> E8 = E2; +// BOOST_CHECK(E8.value() == long(E_)); + + // const construction + bu::quantity<bu::dimensionless> E9(E2); + BOOST_CHECK(E9.value() == E_); + +// // value assignment +// E9.value() = 1.5*bu::dimensionless(); +// BOOST_CHECK(E9.value() == 1.5); +// +// // value assignment with implicit conversion +// E9.value() = 1.5; +// BOOST_CHECK(E9.value() == 1.5); +// +// // value assignment with implicit value_type conversion +// E9.value() = 2*bu::dimensionless(); +// BOOST_CHECK(E9.value() == double(2)); +// +// // value assignment with implicit value_type conversion +// E9.value() = 2; +// BOOST_CHECK(E9.value() == double(2)); + + // operator+=(this_type) + E9 = 2.0; + E9 += E9; + BOOST_CHECK(E9.value() == 4.0); + + // operator-=(this_type) + E9 = 2.0; + E9 -= E9; + BOOST_CHECK(E9.value() == 0.0); + + // operator*=(value_type) + E9 = 2.0; + E9 *= 2.0; + BOOST_CHECK(E9.value() == 4.0); + + // operator/=(value_type) + E9 = 2.0; + E9 /= 2.0; + BOOST_CHECK(E9.value() == 1.0); + + // static construct quantity from value_type + BOOST_CONSTEXPR_OR_CONST bu::quantity<bu::dimensionless> E(bu::quantity<bu::dimensionless>::from_value(2.5)); + BOOST_CHECK(E.value() == 2.5); + + // implicit conversion to value_type + const double V1(E9); + BOOST_CHECK(V1 == E9.value()); + + const double V2 = E9; + BOOST_CHECK(V2 == E9.value()); + + // unit * scalar + BOOST_CHECK(bu::dimensionless()*2.0 == bu::quantity<bu::dimensionless>::from_value(2.0)); + + // unit / scalar + BOOST_CHECK(bu::dimensionless()/2.0 == bu::quantity<bu::dimensionless>::from_value(0.5)); + + // scalar * unit + BOOST_CHECK(2.0*bu::dimensionless() == bu::quantity<bu::dimensionless>::from_value(2.0)); + + // scalar / unit + BOOST_CHECK(2.0/bu::dimensionless() == bu::quantity<bu::dimensionless>::from_value(2.0)); + + // quantity * scalar + BOOST_CHECK(E*2.0 == bu::quantity<bu::dimensionless>::from_value(5.0)); + + // quantity / scalar + BOOST_CHECK(E/2.0 == bu::quantity<bu::dimensionless>::from_value(1.25)); + + // scalar * quantity + BOOST_CHECK(2.0*E == bu::quantity<bu::dimensionless>::from_value(5.0)); + + // scalar / quantity + BOOST_CHECK(2.0/E == bu::quantity<bu::dimensionless>::from_value(0.8)); + + BOOST_CONSTEXPR_OR_CONST bu::quantity<bu::dimensionless> D1(1.0), + D2(2.0); + + // unit * quantity + BOOST_CHECK(bu::dimensionless()*D1 == D1); + + // unit / quantity + BOOST_CHECK(bu::dimensionless()/D1 == D1); + + // quantity * unit + BOOST_CHECK(D1*bu::dimensionless() == D1); + + // quantity / unit + BOOST_CHECK(D1*bu::dimensionless() == D1); + + // +quantity + BOOST_CHECK(+D1 == 1.0*bu::dimensionless()); + + // -quantity + BOOST_CHECK(-D1 == -1.0*bu::dimensionless()); + + // quantity + quantity + BOOST_CHECK(D2+D1 == 3.0*bu::dimensionless()); + + // quantity - quantity + BOOST_CHECK(D2-D1 == 1.0*bu::dimensionless()); + + // quantity * quantity + BOOST_CHECK(D1*D2 == 2.0*bu::dimensionless()); + + // quantity / quantity + BOOST_CHECK(D2/D1 == 2.0*bu::dimensionless()); + + // integer power of quantity + BOOST_CHECK(2.0*bu::pow<2>(D2) == 2.0*std::pow(2.0,2.0)*bu::dimensionless()); + + // rational power of quantity + BOOST_CHECK((2.0*bu::pow< bu::static_rational<2,3> >(D2) == 2.0*std::pow(2.0,2.0/3.0)*bu::dimensionless())); + + // integer root of quantity + BOOST_CHECK(2.0*bu::root<2>(D2) == 2.0*std::pow(2.0,1.0/2.0)*bu::dimensionless()); + + // rational root of quantity + BOOST_CHECK((2.0*bu::root< bu::static_rational<3,2> >(D2) == 2.0*std::pow(2.0,2.0/3.0)*bu::dimensionless())); + + BOOST_CONSTEXPR_OR_CONST bu::quantity<bu::dimensionless> A1(0.0), + A2(0.0), + A3(1.0), + A4(-1.0); + + // operator== + BOOST_CHECK((A1 == A2) == true); + BOOST_CHECK((A1 == A3) == false); + + // operator!= + BOOST_CHECK((A1 != A2) == false); + BOOST_CHECK((A1 != A3) == true); + + // operator< + BOOST_CHECK((A1 < A2) == false); + BOOST_CHECK((A1 < A3) == true); + + // operator<= + BOOST_CHECK((A1 <= A2) == true); + BOOST_CHECK((A1 <= A3) == true); + + // operator> + BOOST_CHECK((A1 > A2) == false); + BOOST_CHECK((A1 > A4) == true); + + // operator>= + BOOST_CHECK((A1 >= A2) == true); + BOOST_CHECK((A1 >= A4) == true); + + return 0; +} diff --git a/src/boost/libs/units/test/test_header.hpp b/src/boost/libs/units/test/test_header.hpp new file mode 100644 index 00000000..bc2ec439 --- /dev/null +++ b/src/boost/libs/units/test/test_header.hpp @@ -0,0 +1,126 @@ +// Boost.Units - A C++ library for zero-overhead dimensional analysis and +// unit/quantity manipulation and conversion +// +// Copyright (C) 2003-2008 Matthias Christian Schabel +// Copyright (C) 2008 Steven Watanabe +// +// Distributed under 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) + +/** +\file + +\brief test_header.hpp + +\details +Unit system for test purposes. + +Output: +@verbatim +@endverbatim +**/ + +#ifndef BOOST_UNITS_TEST_HEADER_HPP +#define BOOST_UNITS_TEST_HEADER_HPP + +#include <boost/test/minimal.hpp> + +#include <boost/units/base_dimension.hpp> +#include <boost/units/derived_dimension.hpp> +#include <boost/units/static_constant.hpp> +#include <boost/units/quantity.hpp> +#include <boost/units/io.hpp> +#include <boost/units/base_unit.hpp> +#include <boost/units/make_system.hpp> + +#include <boost/units/physical_dimensions/length.hpp> +#include <boost/units/physical_dimensions/mass.hpp> +#include <boost/units/physical_dimensions/time.hpp> + +#define BOOST_UNITS_CHECK_CLOSE(a, b) (BOOST_CHECK((std::abs((a) - (b)) < .0000001))) + +namespace boost { + +namespace units { + +//struct length_base_dimension : boost::units::base_dimension<length_base_dimension,1> { }; ///> base dimension of length +//struct mass_base_dimension : boost::units::base_dimension<mass_base_dimension,2> { }; ///> base dimension of mass +//struct time_base_dimension : boost::units::base_dimension<time_base_dimension,3> { }; ///> base dimension of time + +typedef length_base_dimension::dimension_type length_dimension; +typedef mass_base_dimension::dimension_type mass_dimension; +typedef time_base_dimension::dimension_type time_dimension; + +typedef derived_dimension<length_base_dimension,2>::type area_dimension; +typedef derived_dimension<mass_base_dimension,1, + length_base_dimension,2, + time_base_dimension,-2>::type energy_dimension; +typedef derived_dimension<mass_base_dimension,-1, + length_base_dimension,-2, + time_base_dimension,2>::type inverse_energy_dim; +typedef derived_dimension<length_base_dimension,1, + time_base_dimension,-1>::type velocity_dimension; +typedef derived_dimension<length_base_dimension,3>::type volume_dimension; + +/// placeholder class defining test unit system +struct length_unit : base_unit<length_unit, length_dimension, 4> {}; +struct mass_unit : base_unit<mass_unit, mass_dimension, 5> {}; +struct time_unit : base_unit<time_unit, time_dimension, 6> {}; + +typedef make_system<length_unit, mass_unit, time_unit>::type system; + +/// unit typedefs +typedef unit<dimensionless_type,system> dimensionless; + +typedef unit<length_dimension,system> length; +typedef unit<mass_dimension,system> mass; +typedef unit<time_dimension,system> time; + +typedef unit<area_dimension,system> area; +typedef unit<energy_dimension,system> energy; +typedef unit<inverse_energy_dim,system> inverse_energy; +typedef unit<velocity_dimension,system> velocity; +typedef unit<volume_dimension,system> volume; + +/// unit constants +BOOST_UNITS_STATIC_CONSTANT(meter,length); +BOOST_UNITS_STATIC_CONSTANT(meters,length); +BOOST_UNITS_STATIC_CONSTANT(kilogram,mass); +BOOST_UNITS_STATIC_CONSTANT(kilograms,mass); +BOOST_UNITS_STATIC_CONSTANT(second,time); +BOOST_UNITS_STATIC_CONSTANT(seconds,time); + +BOOST_UNITS_STATIC_CONSTANT(square_meter,area); +BOOST_UNITS_STATIC_CONSTANT(square_meters,area); +BOOST_UNITS_STATIC_CONSTANT(joule,energy); +BOOST_UNITS_STATIC_CONSTANT(joules,energy); +BOOST_UNITS_STATIC_CONSTANT(meter_per_second,velocity); +BOOST_UNITS_STATIC_CONSTANT(meters_per_second,velocity); +BOOST_UNITS_STATIC_CONSTANT(cubic_meter,volume); +BOOST_UNITS_STATIC_CONSTANT(cubic_meters,volume); + +template<> struct base_unit_info<length_unit> +{ + static std::string name() { return "meter"; } + static std::string symbol() { return "m"; } +}; +//] + +template<> struct base_unit_info<mass_unit> +{ + static std::string name() { return "kilogram"; } + static std::string symbol() { return "kg"; } +}; + +template<> struct base_unit_info<time_unit> +{ + static std::string name() { return "second"; } + static std::string symbol() { return "s"; } +}; + +} // namespace units + +} // namespace boost + +#endif // BOOST_UNITS_TEST_HEADER_HPP diff --git a/src/boost/libs/units/test/test_implicit_conversion.cpp b/src/boost/libs/units/test/test_implicit_conversion.cpp new file mode 100644 index 00000000..41dfca03 --- /dev/null +++ b/src/boost/libs/units/test/test_implicit_conversion.cpp @@ -0,0 +1,113 @@ +// Boost.Units - A C++ library for zero-overhead dimensional analysis and +// unit/quantity manipulation and conversion +// +// Copyright (C) 2003-2008 Matthias Christian Schabel +// Copyright (C) 2008 Steven Watanabe +// +// Distributed under 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) + +/** +\file + +\brief test_implicit_conversion.cpp + +\details +Test implicit conversions for quantity. + +Output: +@verbatim +@endverbatim +**/ + +#include <boost/test/minimal.hpp> + +#include <boost/units/static_constant.hpp> +#include <boost/units/quantity.hpp> +#include <boost/units/systems/si.hpp> +#include <boost/units/systems/cgs.hpp> + +namespace bu = boost::units; + +int test_main(int,char *[]) +{ + //// si->si always true + //BOOST_CHECK((bu::base_unit_is_implicitly_convertible<bu::length_base_dimension,bu::si::system_tag,bu::si::system_tag>::value == true)); + //BOOST_CHECK((bu::base_unit_is_implicitly_convertible<bu::mass_base_dimension,bu::si::system_tag,bu::si::system_tag>::value == true)); + //BOOST_CHECK((bu::base_unit_is_implicitly_convertible<bu::time_base_dimension,bu::si::system_tag,bu::si::system_tag>::value == true)); + //BOOST_CHECK((bu::base_unit_is_implicitly_convertible<bu::current_base_dimension,bu::si::system_tag,bu::si::system_tag>::value == true)); + //BOOST_CHECK((bu::base_unit_is_implicitly_convertible<bu::temperature_base_dimension,bu::si::system_tag,bu::si::system_tag>::value == true)); + //BOOST_CHECK((bu::base_unit_is_implicitly_convertible<bu::amount_base_dimension,bu::si::system_tag,bu::si::system_tag>::value == true)); + //BOOST_CHECK((bu::base_unit_is_implicitly_convertible<bu::luminous_intensity_base_dimension,bu::si::system_tag,bu::si::system_tag>::value == true)); + //BOOST_CHECK((bu::base_unit_is_implicitly_convertible<bu::plane_angle_base_dimension,bu::si::system_tag,bu::si::system_tag>::value == true)); + //BOOST_CHECK((bu::base_unit_is_implicitly_convertible<bu::solid_angle_base_dimension,bu::si::system_tag,bu::si::system_tag>::value == true)); + + //// cgs->cgs always true + //BOOST_CHECK((bu::base_unit_is_implicitly_convertible<bu::length_base_dimension,bu::cgs::system_tag,bu::cgs::system_tag>::value == true)); + //BOOST_CHECK((bu::base_unit_is_implicitly_convertible<bu::mass_base_dimension,bu::cgs::system_tag,bu::cgs::system_tag>::value == true)); + //BOOST_CHECK((bu::base_unit_is_implicitly_convertible<bu::time_base_dimension,bu::cgs::system_tag,bu::cgs::system_tag>::value == true)); + //BOOST_CHECK((bu::base_unit_is_implicitly_convertible<bu::current_base_dimension,bu::cgs::system_tag,bu::cgs::system_tag>::value == true)); + //BOOST_CHECK((bu::base_unit_is_implicitly_convertible<bu::temperature_base_dimension,bu::cgs::system_tag,bu::cgs::system_tag>::value == true)); + //BOOST_CHECK((bu::base_unit_is_implicitly_convertible<bu::amount_base_dimension,bu::cgs::system_tag,bu::cgs::system_tag>::value == true)); + //BOOST_CHECK((bu::base_unit_is_implicitly_convertible<bu::luminous_intensity_base_dimension,bu::cgs::system_tag,bu::cgs::system_tag>::value == true)); + //BOOST_CHECK((bu::base_unit_is_implicitly_convertible<bu::plane_angle_base_dimension,bu::cgs::system_tag,bu::cgs::system_tag>::value == true)); + //BOOST_CHECK((bu::base_unit_is_implicitly_convertible<bu::solid_angle_base_dimension,bu::cgs::system_tag,bu::cgs::system_tag>::value == true)); + + //// si->cgs + //BOOST_CHECK((bu::base_unit_is_implicitly_convertible<bu::length_base_dimension,bu::si::system_tag,bu::cgs::system_tag>::value == false)); + //BOOST_CHECK((bu::base_unit_is_implicitly_convertible<bu::mass_base_dimension,bu::si::system_tag,bu::cgs::system_tag>::value == false)); + //BOOST_CHECK((bu::base_unit_is_implicitly_convertible<bu::time_base_dimension,bu::si::system_tag,bu::cgs::system_tag>::value == true)); + + BOOST_CHECK((bu::is_implicitly_convertible<bu::si::length,bu::cgs::length>::value == false)); + BOOST_CHECK((bu::is_implicitly_convertible<bu::si::mass,bu::cgs::mass>::value == false)); + BOOST_CHECK((bu::is_implicitly_convertible<bu::si::time,bu::cgs::time>::value == true)); + + BOOST_CHECK((bu::is_implicitly_convertible<bu::si::acceleration,bu::cgs::acceleration>::value == false)); + BOOST_CHECK((bu::is_implicitly_convertible<bu::si::area,bu::cgs::area>::value == false)); + BOOST_CHECK((bu::is_implicitly_convertible<bu::si::energy,bu::cgs::energy>::value == false)); + BOOST_CHECK((bu::is_implicitly_convertible<bu::si::force,bu::cgs::force>::value == false)); + BOOST_CHECK((bu::is_implicitly_convertible<bu::si::frequency,bu::cgs::frequency>::value == true)); + BOOST_CHECK((bu::is_implicitly_convertible<bu::si::mass_density,bu::cgs::mass_density>::value == false)); + BOOST_CHECK((bu::is_implicitly_convertible<bu::si::momentum,bu::cgs::momentum>::value == false)); + BOOST_CHECK((bu::is_implicitly_convertible<bu::si::power,bu::cgs::power>::value == false)); + BOOST_CHECK((bu::is_implicitly_convertible<bu::si::pressure,bu::cgs::pressure>::value == false)); + BOOST_CHECK((bu::is_implicitly_convertible<bu::si::velocity,bu::cgs::velocity>::value == false)); + BOOST_CHECK((bu::is_implicitly_convertible<bu::si::wavenumber,bu::cgs::wavenumber>::value == false)); + + //// cgs->si + //BOOST_CHECK((bu::base_unit_is_implicitly_convertible<bu::length_base_dimension,bu::cgs::system_tag,bu::si::system_tag>::value == false)); + //BOOST_CHECK((bu::base_unit_is_implicitly_convertible<bu::mass_base_dimension,bu::cgs::system_tag,bu::si::system_tag>::value == false)); + //BOOST_CHECK((bu::base_unit_is_implicitly_convertible<bu::time_base_dimension,bu::cgs::system_tag,bu::si::system_tag>::value == true)); + + BOOST_CHECK((bu::is_implicitly_convertible<bu::cgs::length,bu::si::length>::value == false)); + BOOST_CHECK((bu::is_implicitly_convertible<bu::cgs::mass,bu::si::mass>::value == false)); + BOOST_CHECK((bu::is_implicitly_convertible<bu::cgs::time,bu::si::time>::value == true)); + + BOOST_CHECK((bu::is_implicitly_convertible<bu::cgs::acceleration,bu::si::acceleration>::value == false)); + BOOST_CHECK((bu::is_implicitly_convertible<bu::cgs::area,bu::si::area>::value == false)); + BOOST_CHECK((bu::is_implicitly_convertible<bu::cgs::energy,bu::si::energy>::value == false)); + BOOST_CHECK((bu::is_implicitly_convertible<bu::cgs::force,bu::si::force>::value == false)); + BOOST_CHECK((bu::is_implicitly_convertible<bu::cgs::frequency,bu::si::frequency>::value == true)); + BOOST_CHECK((bu::is_implicitly_convertible<bu::cgs::mass_density,bu::si::mass_density>::value == false)); + BOOST_CHECK((bu::is_implicitly_convertible<bu::cgs::momentum,bu::si::momentum>::value == false)); + BOOST_CHECK((bu::is_implicitly_convertible<bu::cgs::power,bu::si::power>::value == false)); + BOOST_CHECK((bu::is_implicitly_convertible<bu::cgs::pressure,bu::si::pressure>::value == false)); + BOOST_CHECK((bu::is_implicitly_convertible<bu::cgs::velocity,bu::si::velocity>::value == false)); + BOOST_CHECK((bu::is_implicitly_convertible<bu::cgs::wavenumber,bu::si::wavenumber>::value == false)); + + BOOST_CONSTEXPR_OR_CONST bu::quantity<bu::si::time> S1(2.0*bu::si::seconds); + BOOST_CONSTEXPR_OR_CONST bu::quantity<bu::cgs::time> S2 = S1; + + BOOST_CHECK((S1.value() == S2.value())); + + BOOST_CONSTEXPR_OR_CONST bu::quantity<bu::si::catalytic_activity> S3(2.0*bu::si::catalytic_activity()); + + + BOOST_CONSTEXPR_OR_CONST bu::quantity<bu::cgs::time> C1(2.0*bu::cgs::seconds); + BOOST_CONSTEXPR_OR_CONST bu::quantity<bu::si::time> C2 = C1; + + BOOST_CHECK((C1.value() == C2.value())); + + return 0; +} diff --git a/src/boost/libs/units/test/test_information_units.cpp b/src/boost/libs/units/test/test_information_units.cpp new file mode 100644 index 00000000..80eb04f2 --- /dev/null +++ b/src/boost/libs/units/test/test_information_units.cpp @@ -0,0 +1,242 @@ +// Boost.Units - A C++ library for zero-overhead dimensional analysis and +// unit/quantity manipulation and conversion +// +// Copyright (C) 2014 Erik Erlandson +// +// Distributed under 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) + +#include <iostream> +#include <sstream> + +#include <boost/units/quantity.hpp> +#include <boost/units/conversion.hpp> +#include <boost/units/io.hpp> + +#include <boost/units/systems/si/prefixes.hpp> +#include <boost/units/systems/si/time.hpp> + +// All information systems definitions +#include <boost/units/systems/information.hpp> + +using std::cout; +using std::cerr; +using std::endl; +using std::stringstream; + +namespace bu = boost::units; +namespace si = boost::units::si; + +using bu::quantity; + +using bu::information::bit_base_unit; +using bu::information::byte_base_unit; +using bu::information::nat_base_unit; +using bu::information::hartley_base_unit; +using bu::information::shannon_base_unit; + + +#define BOOST_TEST_MAIN +#include <boost/test/unit_test.hpp> + + +#include <boost/multiprecision/cpp_int.hpp> + +const double close_fraction = 0.0000001; + +// checks that cf(u2,u1) == expected +// also checks invariant property that cf(u2,u1) * cf(u1,u2) == 1 +#define CHECK_DIRECT_CF(u1, u2, expected) \ + BOOST_CHECK_CLOSE_FRACTION(bu::conversion_factor((u2), (u1)), (expected), close_fraction); \ + BOOST_CHECK_CLOSE_FRACTION(bu::conversion_factor((u2), (u1)) * bu::conversion_factor((u1), (u2)), 1.0, close_fraction); + +// check transitive conversion factors +// invariant: cf(u1,u3) = cf(u1,u2)*cf(u2,u3) +#define CHECK_TRANSITIVE_CF(u1, u2, u3) { \ + BOOST_CONSTEXPR_OR_CONST double cf12 = bu::conversion_factor((u2), (u1)) ; \ + BOOST_CONSTEXPR_OR_CONST double cf23 = bu::conversion_factor((u3), (u2)) ; \ + BOOST_CONSTEXPR_OR_CONST double cf13 = bu::conversion_factor((u3), (u1)) ; \ + BOOST_CHECK_CLOSE_FRACTION(cf13, cf12*cf23, close_fraction); \ + BOOST_CONSTEXPR_OR_CONST double cf32 = bu::conversion_factor((u2), (u3)) ; \ + BOOST_CONSTEXPR_OR_CONST double cf21 = bu::conversion_factor((u1), (u2)) ; \ + BOOST_CONSTEXPR_OR_CONST double cf31 = bu::conversion_factor((u1), (u3)) ; \ + BOOST_CHECK_CLOSE_FRACTION(cf31, cf32*cf21, close_fraction); \ +} + + +BOOST_AUTO_TEST_CASE(test_cf_bit_byte) { + CHECK_DIRECT_CF(bit_base_unit::unit_type(), byte_base_unit::unit_type(), 8.0); +} + +BOOST_AUTO_TEST_CASE(test_cf_bit_nat) { + CHECK_DIRECT_CF(bit_base_unit::unit_type(), nat_base_unit::unit_type(), 1.442695040888964); +} + +BOOST_AUTO_TEST_CASE(test_cf_bit_hartley) { + CHECK_DIRECT_CF(bit_base_unit::unit_type(), hartley_base_unit::unit_type(), 3.321928094887363); +} + +BOOST_AUTO_TEST_CASE(test_cf_bit_shannon) { + CHECK_DIRECT_CF(bit_base_unit::unit_type(), shannon_base_unit::unit_type(), 1.0); +} + +///////////////////////////////////////////////////////////////////////////////////// +// spot-check that these are automatically transitive, thru central "hub unit" bit: +// basic pattern is to test invariant property: cf(c,a) = cf(c,b)*cf(b,a) + +BOOST_AUTO_TEST_CASE(test_transitive_byte_nat) { + CHECK_TRANSITIVE_CF(byte_base_unit::unit_type(), bit_base_unit::unit_type(), nat_base_unit::unit_type()); +} +BOOST_AUTO_TEST_CASE(test_transitive_nat_hartley) { + CHECK_TRANSITIVE_CF(nat_base_unit::unit_type(), bit_base_unit::unit_type(), hartley_base_unit::unit_type()); +} +BOOST_AUTO_TEST_CASE(test_transitive_hartley_shannon) { + CHECK_TRANSITIVE_CF(hartley_base_unit::unit_type(), bit_base_unit::unit_type(), shannon_base_unit::unit_type()); +} +BOOST_AUTO_TEST_CASE(test_transitive_shannon_byte) { + CHECK_TRANSITIVE_CF(shannon_base_unit::unit_type(), bit_base_unit::unit_type(), byte_base_unit::unit_type()); +} + +// test transitive factors, none of which are bit, just for good measure +BOOST_AUTO_TEST_CASE(test_transitive_byte_nat_hartley) { + CHECK_TRANSITIVE_CF(byte_base_unit::unit_type(), nat_base_unit::unit_type(), hartley_base_unit::unit_type()); +} + +BOOST_AUTO_TEST_CASE(test_byte_quantity_is_default) { + using namespace bu::information; + BOOST_CONSTEXPR_OR_CONST quantity<info, double> qd(2 * byte); + BOOST_CHECK_EQUAL(qd.value(), double(2)); + BOOST_CONSTEXPR_OR_CONST quantity<info, long> ql(2 * byte); + BOOST_CHECK_EQUAL(ql.value(), long(2)); +} + +BOOST_AUTO_TEST_CASE(test_byte_quantity_explicit) { + using namespace bu::information; + BOOST_CONSTEXPR_OR_CONST quantity<hu::byte::info, double> qd(2 * byte); + BOOST_CHECK_EQUAL(qd.value(), double(2)); + BOOST_CONSTEXPR_OR_CONST quantity<hu::byte::info, long> ql(2 * byte); + BOOST_CHECK_EQUAL(ql.value(), long(2)); +} + +BOOST_AUTO_TEST_CASE(test_bit_quantity) { + using namespace bu::information; + BOOST_CONSTEXPR_OR_CONST quantity<hu::bit::info, double> qd(2 * bit); + BOOST_CHECK_EQUAL(qd.value(), double(2)); + BOOST_CONSTEXPR_OR_CONST quantity<hu::bit::info, long> ql(2 * bit); + BOOST_CHECK_EQUAL(ql.value(), long(2)); +} + +BOOST_AUTO_TEST_CASE(test_nat_quantity) { + using namespace bu::information; + BOOST_CONSTEXPR_OR_CONST quantity<hu::nat::info, double> qd(2 * nat); + BOOST_CHECK_EQUAL(qd.value(), double(2)); + BOOST_CONSTEXPR_OR_CONST quantity<hu::nat::info, long> ql(2 * nat); + BOOST_CHECK_EQUAL(ql.value(), long(2)); +} + +BOOST_AUTO_TEST_CASE(test_hartley_quantity) { + using namespace bu::information; + BOOST_CONSTEXPR_OR_CONST quantity<hu::hartley::info, double> qd(2 * hartley); + BOOST_CHECK_EQUAL(qd.value(), double(2)); + BOOST_CONSTEXPR_OR_CONST quantity<hu::hartley::info, long> ql(2 * hartley); + BOOST_CHECK_EQUAL(ql.value(), long(2)); +} + +BOOST_AUTO_TEST_CASE(test_shannon_quantity) { + using namespace bu::information; + BOOST_CONSTEXPR_OR_CONST quantity<hu::shannon::info, double> qd(2 * shannon); + BOOST_CHECK_EQUAL(qd.value(), double(2)); + BOOST_CONSTEXPR_OR_CONST quantity<hu::shannon::info, long> ql(2 * shannon); + BOOST_CHECK_EQUAL(ql.value(), long(2)); +} + +BOOST_AUTO_TEST_CASE(test_mixed_hu) { + using namespace bu::information; + BOOST_CONSTEXPR_OR_CONST double cf = 0.001; + BOOST_CHECK_CLOSE_FRACTION((quantity<hu::bit::info>(1.0 * bits)).value(), 1.0, cf); + BOOST_CHECK_CLOSE_FRACTION((quantity<hu::byte::info>(1.0 * bits)).value(), 1.0/8.0, cf); + BOOST_CHECK_CLOSE_FRACTION((quantity<hu::nat::info>(1.0 * bits)).value(), 0.69315, cf); + BOOST_CHECK_CLOSE_FRACTION((quantity<hu::hartley::info>(1.0 * bits)).value(), 0.30102, cf); + BOOST_CHECK_CLOSE_FRACTION((quantity<hu::shannon::info>(1.0 * bits)).value(), 1.0, cf); +} + +BOOST_AUTO_TEST_CASE(test_info_prefixes) { + using namespace bu::information; + BOOST_CONSTEXPR_OR_CONST quantity<info, long long> q10(1LL * kibi * byte); + BOOST_CHECK_EQUAL(q10.value(), 1024LL); + + BOOST_CONSTEXPR_OR_CONST quantity<info, long long> q20(1LL * mebi * byte); + BOOST_CHECK_EQUAL(q20.value(), 1048576LL); + + BOOST_CONSTEXPR_OR_CONST quantity<info, long long> q30(1LL * gibi * byte); + BOOST_CHECK_EQUAL(q30.value(), 1073741824LL); + + BOOST_CONSTEXPR_OR_CONST quantity<info, long long> q40(1LL * tebi * byte); + BOOST_CHECK_EQUAL(q40.value(), 1099511627776LL); + + BOOST_CONSTEXPR_OR_CONST quantity<info, long long> q50(1LL * pebi * byte); + BOOST_CHECK_EQUAL(q50.value(), 1125899906842624LL); + + BOOST_CONSTEXPR_OR_CONST quantity<info, long long> q60(1LL * exbi * byte); + BOOST_CHECK_EQUAL(q60.value(), 1152921504606846976LL); + + using boost::multiprecision::int128_t; + + const quantity<info, int128_t> q70(1LL * zebi * byte); + BOOST_CHECK_EQUAL(q70.value(), int128_t("1180591620717411303424")); + + const quantity<info, int128_t> q80(1LL * yobi * byte); + BOOST_CHECK_EQUAL(q80.value(), int128_t("1208925819614629174706176")); + + // sanity check: si prefixes should also operate + BOOST_CONSTEXPR_OR_CONST quantity<info, long long> q1e3(1LL * si::kilo * byte); + BOOST_CHECK_EQUAL(q1e3.value(), 1000LL); + + BOOST_CONSTEXPR_OR_CONST quantity<info, long long> q1e6(1LL * si::mega * byte); + BOOST_CHECK_EQUAL(q1e6.value(), 1000000LL); +} + +BOOST_AUTO_TEST_CASE(test_unit_constant_io) { + using namespace bu::information; + + std::stringstream ss; + ss << bu::symbol_format << bytes; + BOOST_CHECK_EQUAL(ss.str(), "B"); + + ss.str(""); + ss << bu::name_format << bytes; + BOOST_CHECK_EQUAL(ss.str(), "byte"); + + ss.str(""); + ss << bu::symbol_format << bits; + BOOST_CHECK_EQUAL(ss.str(), "b"); + + ss.str(""); + ss << bu::name_format << bits; + BOOST_CHECK_EQUAL(ss.str(), "bit"); + + ss.str(""); + ss << bu::symbol_format << nats; + BOOST_CHECK_EQUAL(ss.str(), "nat"); + + ss.str(""); + ss << bu::name_format << nats; + BOOST_CHECK_EQUAL(ss.str(), "nat"); + + ss.str(""); + ss << bu::symbol_format << hartleys; + BOOST_CHECK_EQUAL(ss.str(), "Hart"); + + ss.str(""); + ss << bu::name_format << hartleys; + BOOST_CHECK_EQUAL(ss.str(), "hartley"); + + ss.str(""); + ss << bu::symbol_format << shannons; + BOOST_CHECK_EQUAL(ss.str(), "Sh"); + + ss.str(""); + ss << bu::name_format << shannons; + BOOST_CHECK_EQUAL(ss.str(), "shannon"); +} diff --git a/src/boost/libs/units/test/test_lambda.cpp b/src/boost/libs/units/test/test_lambda.cpp new file mode 100644 index 00000000..8c3642c7 --- /dev/null +++ b/src/boost/libs/units/test/test_lambda.cpp @@ -0,0 +1,269 @@ +// Boost.Units - A C++ library for zero-overhead dimensional analysis and +// unit/quantity manipulation and conversion +// +// Copyright (C) 2003-2008 Matthias Christian Schabel +// Copyright (C) 2008 Steven Watanabe +// +// Distributed under 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) + +// $Id: test_lambda.cpp 27 2008-06-16 14:50:58Z maehne $ + +//////////////////////////////////////////////////////////////////////// +/// +/// \file test_lambda.hpp +/// +/// \brief Unit test for checking the usage of Boost.Units' quantity, +/// unit, and absolute types in functors created with the +/// Boost.Lambda library. +/// +/// \author Torsten Maehne +/// \date 2008-06-16 +/// +/// This unit test contains a check for each operator action, for +/// which a specialization of Boost.Lambda's return type deduction +/// system is made in lambda.hpp, i.e., for the operators defined for +/// Boost.Units' quantity, unit, and absolute types. +/// +//////////////////////////////////////////////////////////////////////// + +#include <boost/function.hpp> +#include <boost/units/lambda.hpp> +#include <boost/units/absolute.hpp> +#include <boost/units/systems/si/temperature.hpp> +#include "test_header.hpp" + + +namespace bl = boost::lambda; +namespace bu = boost::units; +namespace si = boost::units::si; + + +int test_main(int, char *[]) +{ + + //////////////////////////////////////////////////////////////////////// + // Test for Boost.Lambda working with overloaded operators defined + // in <boost/units/quantity.hpp> + //////////////////////////////////////////////////////////////////////// + + bu::quantity<bu::length> lvar = 0.0 * bu::meter; + + bu::quantity<bu::dimensionless> dlvar = 3.0; + + // quantity<Unit, Y> += quantity<Unit2, YY> + boost::function<bu::quantity<bu::length> (bu::quantity<bu::length>)> + f = (bl::var(lvar) += bl::_1); + + lvar = 1.0 * bu::meter; + BOOST_CHECK((f(2.0 * bu::meter) == 3.0 * bu::meter)); + BOOST_CHECK((f(6.0 * bu::meter) == 9.0 * bu::meter)); + + // quantity<BOOST_UNITS_DIMENSIONLESS_UNIT(System), Y> += quantity<BOOST_UNITS_DIMENSIONLESS_UNIT(System), Y> + dlvar = 4.0; + BOOST_CHECK(((bl::var(dlvar) += bl::_1)(3.0) == 7.0)); + + // quantity<Unit, Y> -= quantity<Unit2, YY> + lvar = 3.0 * bu::meter; + BOOST_CHECK((f(-2.0 * bu::meter) == 1.0 * bu::meter)); + BOOST_CHECK((f(6.0 * bu::meter) == 7.0 * bu::meter)); + + // quantity<BOOST_UNITS_DIMENSIONLESS_UNIT(System), Y> -= quantity<BOOST_UNITS_DIMENSIONLESS_UNIT(System), Y> + dlvar = 4.0; + BOOST_CHECK(((bl::var(dlvar) -= bl::_1)(3.0) == 1.0)); + + // quantity<Unit, Y> *= quantity<Unit2, YY> + dlvar = 2.0; + BOOST_CHECK(((bl::var(dlvar) *= bl::_1)(3.0) == 6.0)); + + // quantity<Unit, Y> /= quantity<Unit2, YY> + dlvar = 6.0; + BOOST_CHECK(((bl::var(dlvar) /= bl::_1)(3.0) == 2.0)); + + // quantity<Unit, Y> *= Y + lvar = 3.0 * bu::meter; + BOOST_CHECK(((bl::var(lvar) *= bl::_1)(2.0) == 6.0 * bu::meter)); + + // quantity<Unit, Y> /= Y + lvar = 6.0 * bu::meter; + BOOST_CHECK(((bl::var(lvar) /= bl::_1)(3.0) == 2.0 * bu::meter)); + + // unit<Dim, System> * Y + BOOST_CHECK(((bl::_1 * bl::_2)(bu::meter, 2.0) == 2.0 * bu::meter)); + BOOST_CHECK(((bu::meter * bl::_1)(2.0) == 2.0 * bu::meter)); + + // unit<Dim, System> / Y + BOOST_CHECK(((bl::_1 / bl::_2)(bu::meter, 0.5) == 2.0 * bu::meter)); + BOOST_CHECK(((bu::meter / bl::_1)(0.5 * bu::second) == 2.0 * bu::meter_per_second)); + + // Y * unit<Dim, System> + BOOST_CHECK(((bl::_1 * bl::_2)(2.0, bu::meter) == 2.0 * bu::meter)); + BOOST_CHECK(((bl::_1 * bu::meter)(2.0 / bu::second) == 2.0 * bu::meter_per_second)); + + // Y / unit<Dim, System> + BOOST_CHECK(((bl::_1 / bl::_2)(3.5, bu::second) == 3.5 / bu::second)); + BOOST_CHECK(((bl::_1 / bu::second)(3.5 * bu::meter) == 3.5 * bu::meter_per_second)); + + // quantity<Unit, X> * X + BOOST_CHECK(((bl::_1 * bl::_2)(2.0, 3.0 * bu::meter) == 6.0 * bu::meter)); + + // X * quantity<Unit, X> + BOOST_CHECK(((bl::_1 * bl::_2)(4.0 * bu::joule, 2.0) == 8.0 * bu::joule)); + + // quantity<Unit, X> / X + BOOST_CHECK(((bl::_1 / bl::_2)(4.0 * bu::joule, 2.0) == 2.0 * bu::joule)); + + // X / quantity<Unit, X> + BOOST_CHECK(((3.0 / bl::_1)(2.0 * bu::second) == 1.5 / bu::second)); + + // unit<Dim1, System1> * quantity<Unit2, Y> + BOOST_CHECK(((bl::_1 * bl::_2)(bu::meter, 12.0 / bu::second) == 12.0 * bu::meter_per_second)); + BOOST_CHECK(((bu::meter * bl::_1)(12.0 / bu::second) == 12.0 * bu::meter_per_second)); + + // unit<Dim1, System1> / quantity<Unit2, Y> + BOOST_CHECK(((bl::_1 / bl::_2)(bu::meter, 0.5 * bu::second) == 2.0 * bu::meter_per_second)); + BOOST_CHECK(((bu::meter / bl::_1)(0.25 * bu::second) == 4.0 * bu::meter_per_second)); + + // quantity<Unit1, Y> * unit<Dim2, System2> + BOOST_CHECK(((bl::_1 * bl::_2)(2.0 / bu::second, bu::meter) == 2.0 * bu::meter_per_second)); + BOOST_CHECK(((bl::_1 * bu::meter)(12.0 / bu::second) == 12.0 * bu::meter_per_second)); + + // quantity<Unit1, Y> / unit<Dim2, System2> + BOOST_CHECK(((bl::_1 / bl::_2)(3.5 * bu::meter, bu::second) == 3.5 * bu::meter_per_second)); + BOOST_CHECK(((bl::_1 / bu::second)(5.0 * bu::second) == 5.0)); + + // +quantity<Unit, Y> + BOOST_CHECK(((+bl::_1)(5.0 * bu::second) == 5.0 * bu::second)); + + // -quantity<Unit, Y> + BOOST_CHECK(((-bl::_1)(5.0 * bu::second) == -5.0 * bu::second)); + + // quantity<Unit1, X> + quantity<Unit2, Y> + BOOST_CHECK(((bl::_1 + bl::_2)(2.0 * bu::meter, 4.0 * bu::meter) == 6.0 * bu::meter)); + + // quantity<dimensionless, X> + Y + BOOST_CHECK(((bl::_1 + 1.0f)(bu::quantity<bu::dimensionless>(2.0)) == 3.0)); + + // X + quantity<dimensionless, Y> + BOOST_CHECK(((1.0f + bl::_1)(bu::quantity<bu::dimensionless>(1.0)) == 2.0)); + + // quantity<Unit1, X> - quantity<Unit2, Y> + BOOST_CHECK(((bl::_1 - bl::_2)(2.0 * bu::meter, 4.0 * bu::meter) == -2.0 * bu::meter)); + + // quantity<dimensionless, X> - Y + BOOST_CHECK(((bl::_1 - 2.0f)(bu::quantity<bu::dimensionless>(1.0)) == -1.0)); + + // X - quantity<dimensionless, Y> + BOOST_CHECK(((2.0f - bl::_1)(bu::quantity<bu::dimensionless>(1.0)) == 1.0)); + + // quantity<Unit1, X> * quantity<Unit2, Y> + BOOST_CHECK(((bl::_1 * bl::_2)(2.0 * bu::kilogram, 4.0 * bu::meter_per_second) == 8.0 * bu::kilogram * bu::meter_per_second)); + + // quantity<Unit1, X> / quantity<Unit2, Y> + BOOST_CHECK(((bl::_1 / bl::_2)(2.0 * bu::meter_per_second, 4.0 * bu::meter_per_second) == 0.5)); + + // quantity<Unit, X> == quantity<Unit, Y> + BOOST_CHECK(((bl::_1 == bl::_2)(2.0 * bu::meter, 2.0 * bu::meter) == true)); + BOOST_CHECK(((bl::_1 == bl::_2)(2.0 * bu::meter, 3.0 * bu::meter) == false)); + + // quantity<Unit, X> != quantity<Unit, Y> + BOOST_CHECK(((bl::_1 != bl::_2)(2.0 * bu::meter, 2.0 * bu::meter) == false)); + BOOST_CHECK(((bl::_1 != bl::_2)(2.0 * bu::meter, 3.0 * bu::meter) == true)); + + // quantity<Unit, X> < quantity<Unit, Y> + BOOST_CHECK(((bl::_1 < bl::_2)(2.0 * bu::meter, 2.0 * bu::meter) == false)); + BOOST_CHECK(((bl::_1 < bl::_2)(2.0 * bu::meter, 3.0 * bu::meter) == true)); + + // quantity<Unit, X> <= quantity<Unit, Y> + BOOST_CHECK(((bl::_1 <= bl::_2)(2.0 * bu::meter, 2.0 * bu::meter) == true)); + BOOST_CHECK(((bl::_1 <= bl::_2)(2.0 * bu::meter, 3.0 * bu::meter) == true)); + BOOST_CHECK(((bl::_1 <= bl::_2)(4.0 * bu::meter, 3.0 * bu::meter) == false)); + + // quantity<Unit, X> > quantity<Unit, Y> + BOOST_CHECK(((bl::_1 > bl::_2)(2.0 * bu::meter, 2.0 * bu::meter) == false)); + BOOST_CHECK(((bl::_1 > bl::_2)(2.0 * bu::meter, 3.0 * bu::meter) == false)); + BOOST_CHECK(((bl::_1 > bl::_2)(4.0 * bu::meter, 3.0 * bu::meter) == true)); + + // quantity<Unit, X> >= quantity<Unit, Y> + BOOST_CHECK(((bl::_1 >= bl::_2)(2.0 * bu::meter, 2.0 * bu::meter) == true)); + BOOST_CHECK(((bl::_1 >= bl::_2)(2.0 * bu::meter, 3.0 * bu::meter) == false)); + BOOST_CHECK(((bl::_1 >= bl::_2)(4.0 * bu::meter, 3.0 * bu::meter) == true)); + + + //////////////////////////////////////////////////////////////////////// + // Test for Boost.Lambda working with overloaded operators defined + // in <boost/units/unit.hpp> + //////////////////////////////////////////////////////////////////////// + + // +unit<Dim, System> + BOOST_CHECK(((+bl::_1)(bu::meter) == bu::meter)); + + // -unit<Dim, System> + BOOST_CHECK(((-bl::_1)(bu::meter) == bu::meter)); + + // unit<Dim1, System1> + unit<Dim2, System2> + BOOST_CHECK(((bl::_1 + bu::meter)(bu::meter) == bu::meter)); + BOOST_CHECK(((bu::meter + bl::_1)(bu::meter) == bu::meter)); + BOOST_CHECK(((bl::_1 + bl::_2)(bu::meter, bu::meter) == bu::meter)); + + // unit<Dim1, System1> - unit<Dim2, System2> + BOOST_CHECK(((bl::_1 - bl::_2)(bu::meter, bu::meter) == bu::meter)); + BOOST_CHECK(((bl::_1 - bu::meter)(bu::meter) == bu::meter)); + BOOST_CHECK(((bu::meter - bl::_1)(bu::meter) == bu::meter)); + + // unit<Dim1, System1> * unit<Dim2, System2> + BOOST_CHECK(((bl::_1 * bl::_2)(bu::meter, bu::meter) == bu::meter * bu::meter)); + BOOST_CHECK(((bl::_1 * bu::meter)(bu::meter) == bu::meter * bu::meter)); + + // unit<Dim1, System1> / unit<Dim2, System2> + BOOST_CHECK(((bl::_1 / bl::_2)(bu::meter, bu::second) == bu::meter_per_second)); + BOOST_CHECK(((bl::_1 / bu::second)(bu::meter) == bu::meter_per_second)); + + // unit<Dim1, System1> == unit<Dim2, System2> + BOOST_CHECK(((bl::_1 == bu::meter)(bu::meter) == true)); + BOOST_CHECK(((bl::_1 == bu::meter)(bu::second) == false)); + + // unit<Dim1, System1> != unit<Dim2, System2> + BOOST_CHECK(((bl::_1 != bu::meter)(bu::meter) == false)); + BOOST_CHECK(((bl::_1 != bu::meter)(bu::second) == true)); + + + //////////////////////////////////////////////////////////////////////// + // Test for Boost.Lambda working with overloaded operators defined + // in <boost/units/absolute.hpp> + //////////////////////////////////////////////////////////////////////// + + // absolute<Y> += Y + bu::quantity<bu::absolute<si::temperature> > Ta = 270.0 * bu::absolute<si::temperature>(); + (Ta += bl::_1)(30.0 * si::kelvin); + BOOST_CHECK(( Ta == 300.0 * bu::absolute<si::temperature>())); + + // absolute<Y> -= Y + Ta = 270 * bu::absolute<si::temperature>(); + (Ta -= bl::_1)(-30.0 * si::kelvin); + BOOST_CHECK(( Ta == 300.0 * bu::absolute<si::temperature>())); + + // absolute<Y> + Y + BOOST_CHECK(((270.0 * bu::absolute<si::temperature>() + bl::_1)(30.0 * si::kelvin) == 300.0 * bu::absolute<si::temperature>())); + + // Y + absolute<Y> + BOOST_CHECK(((bl::_1 + 270.0 * bu::absolute<si::temperature>())(30.0 * si::kelvin) == 300.0 * bu::absolute<si::temperature>())); + + // absolute<Y> - Y + BOOST_CHECK(((270.0 * bu::absolute<si::temperature>() - bl::_1)(30.0 * si::kelvin) == 240.0 * bu::absolute<si::temperature>())); + + // absolute<Y> - absolute<Y> + BOOST_CHECK(((bl::_1 - 270.0 * bu::absolute<si::temperature>())(300.0 * bu::absolute<si::temperature>()) == 30.0 * si::kelvin)); + + // T * absolute<unit<D, S> > + BOOST_CHECK(((bl::_1 * bu::absolute<si::temperature>())(300.0) == 300.0 * bu::absolute<si::temperature>())); + BOOST_CHECK(((bl::_1 * bl::_2)(300.0, bu::absolute<si::temperature>()) == 300.0 * bu::absolute<si::temperature>())); + + // absolute<unit<D, S> > * T + BOOST_CHECK(((bu::absolute<si::temperature>() * bl::_1)(300.0) == 300.0 * bu::absolute<si::temperature>())); + BOOST_CHECK(((bl::_1 * bl::_2)(bu::absolute<si::temperature>(), 300.0) == 300.0 * bu::absolute<si::temperature>())); + + + return 0; +} diff --git a/src/boost/libs/units/test/test_limits.cpp b/src/boost/libs/units/test/test_limits.cpp new file mode 100644 index 00000000..6057cf94 --- /dev/null +++ b/src/boost/libs/units/test/test_limits.cpp @@ -0,0 +1,127 @@ +// Boost.Units - A C++ library for zero-overhead dimensional analysis and +// unit/quantity manipulation and conversion +// +// Copyright (C) 2003-2008 Matthias Christian Schabel +// Copyright (C) 2008 Steven Watanabe +// +// Distributed under 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) + +/** +\file + +\brief test_limits.cpp + +\details +Test numeric_limits specialization. + +Output: +@verbatim +@endverbatim +**/ + +#include <complex> +#include <limits> + +#include <boost/units/limits.hpp> +#include <boost/units/cmath.hpp> + +#include "test_header.hpp" + +typedef boost::units::length unit_type; +using boost::units::quantity; + +template<bool> +struct check_quiet_NaN; + +template<> +struct check_quiet_NaN<true> { + template<class T> + static void apply() { + quantity<unit_type, T> q((std::numeric_limits<quantity<unit_type, T> >::quiet_NaN)()); + bool test = isnan BOOST_PREVENT_MACRO_SUBSTITUTION (q); + BOOST_CHECK(test); + } +}; + +template<> +struct check_quiet_NaN<false> { + template<class T> + static void apply() {} +}; + +template<bool> +struct check_signaling_NaN; + +template<> +struct check_signaling_NaN<true> { + template<class T> + static void apply() { + quantity<unit_type, T> q((std::numeric_limits<quantity<unit_type, T> >::signaling_NaN)()); + bool test = isnan BOOST_PREVENT_MACRO_SUBSTITUTION (q); + BOOST_CHECK(test); + } +}; + +template<> +struct check_signaling_NaN<false> { + template<class T> + static void apply() {} +}; + +template<class T> +void do_check() { + #define CHECK_FUNCTION(name) BOOST_CHECK(((std::numeric_limits<T>::name)() == (std::numeric_limits<quantity<unit_type, T> >::name)().value())) + #define CHECK_CONSTANT(name) BOOST_CHECK((std::numeric_limits<T>::name == std::numeric_limits<quantity<unit_type, T> >::name)) + CHECK_FUNCTION(min); + CHECK_FUNCTION(max); + CHECK_FUNCTION(epsilon); + CHECK_FUNCTION(round_error); + CHECK_FUNCTION(infinity); + CHECK_FUNCTION(denorm_min); + #ifndef BOOST_NO_CXX11_NUMERIC_LIMITS + CHECK_FUNCTION(lowest); + #endif + + CHECK_CONSTANT(is_specialized); + CHECK_CONSTANT(digits); + CHECK_CONSTANT(digits10); + #ifndef BOOST_NO_CXX11_NUMERIC_LIMITS + CHECK_CONSTANT(max_digits10); + #endif + CHECK_CONSTANT(is_signed); + CHECK_CONSTANT(is_integer); + CHECK_CONSTANT(is_exact); + CHECK_CONSTANT(radix); + CHECK_CONSTANT(min_exponent); + CHECK_CONSTANT(min_exponent10); + CHECK_CONSTANT(max_exponent); + CHECK_CONSTANT(max_exponent10); + CHECK_CONSTANT(has_infinity); + CHECK_CONSTANT(has_quiet_NaN); + CHECK_CONSTANT(has_signaling_NaN); + CHECK_CONSTANT(has_denorm); + CHECK_CONSTANT(has_denorm_loss); + CHECK_CONSTANT(is_iec559); + CHECK_CONSTANT(is_bounded); + CHECK_CONSTANT(is_modulo); + CHECK_CONSTANT(traps); + CHECK_CONSTANT(tinyness_before); + CHECK_CONSTANT(round_style); + + check_quiet_NaN<std::numeric_limits<quantity<unit_type, T> >::has_quiet_NaN>::template apply<T>(); + check_signaling_NaN<std::numeric_limits<quantity<unit_type, T> >::has_signaling_NaN>::template apply<T>(); +} + +int test_main(int,char *[]) +{ + do_check<float>(); + do_check<double>(); + do_check<int>(); + do_check<long>(); + do_check<unsigned>(); + do_check<std::complex<double> >(); + + return(0); +} diff --git a/src/boost/libs/units/test/test_mixed_value_types.cpp b/src/boost/libs/units/test/test_mixed_value_types.cpp new file mode 100644 index 00000000..7d86362c --- /dev/null +++ b/src/boost/libs/units/test/test_mixed_value_types.cpp @@ -0,0 +1,22 @@ +// Boost.Units - A C++ library for zero-overhead dimensional analysis and +// unit/quantity manipulation and conversion +// +// Copyright (C) 2003-2008 Matthias Christian Schabel +// Copyright (C) 2007-2008 Steven Watanabe +// +// Distributed under 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) + +#include <boost/units/quantity.hpp> +#include <boost/units/unit.hpp> +#include <boost/units/systems/si/length.hpp> + +namespace bu = boost::units; + +int main() { + bu::quantity<bu::si::length, double> q1; + BOOST_CONSTEXPR_OR_CONST bu::quantity<bu::si::length, int> q2; + q1 + q2; + q1 -= q2; +} diff --git a/src/boost/libs/units/test/test_negative_denominator.cpp b/src/boost/libs/units/test/test_negative_denominator.cpp new file mode 100644 index 00000000..e9b638ab --- /dev/null +++ b/src/boost/libs/units/test/test_negative_denominator.cpp @@ -0,0 +1,32 @@ +// Boost.Units - A C++ library for zero-overhead dimensional analysis and +// unit/quantity manipulation and conversion +// +// Copyright (C) 2003-2008 Matthias Christian Schabel +// Copyright (C) 2008 Steven Watanabe +// +// Distributed under 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) + +/** +\file + +\brief test_negative_denominator.cpp + +\details +Test negative denominator for static_rational class. + +Output: +@verbatim +@endverbatim +**/ + +#include <boost/units/static_rational.hpp> + +#include <boost/mpl/assert.hpp> +#include <boost/type_traits/is_same.hpp> + +BOOST_MPL_ASSERT((boost::is_same<boost::units::static_rational<-2,1>::type, boost::units::static_rational<2, -1>::type>)); + +int main() { +} diff --git a/src/boost/libs/units/test/test_output.cpp b/src/boost/libs/units/test/test_output.cpp new file mode 100644 index 00000000..abc39d85 --- /dev/null +++ b/src/boost/libs/units/test/test_output.cpp @@ -0,0 +1,499 @@ +// Boost.Units - A C++ library for zero-overhead dimensional analysis and +// unit/quantity manipulation and conversion +// +// Copyright (C) 2009 Steven Watanabe +// Copyright Paul A. Bristow 2010 +// +// Distributed under 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) + +/** +\file test_output.cpp + +\brief +Test unit and quantity printing +\details +Tests for output from various units, name, symbol and raw formats, and automatic prefixing in engineering and binary units. +**/ + +#include <boost/units/quantity.hpp> +#include <boost/units/io.hpp> +#include <boost/units/unit.hpp> +#include <boost/units/scale.hpp> +#include <boost/units/scaled_base_unit.hpp> +#include <boost/units/make_scaled_unit.hpp> +#include <boost/units/base_unit.hpp> +#include <boost/units/make_system.hpp> +#include <boost/units/absolute.hpp> +#include <boost/units/physical_dimensions/length.hpp> +#include <boost/units/physical_dimensions/time.hpp> +#include <boost/units/physical_dimensions/velocity.hpp> +#include <boost/units/physical_dimensions/volume.hpp> +#include <boost/units/physical_dimensions/acceleration.hpp> +#include <boost/units/physical_dimensions/area.hpp> + +#include <boost/regex.hpp> + +#include <iostream> +#include <sstream> +#include <boost/config.hpp> +#include <limits> + +#define BOOST_TEST_MAIN +#include <boost/test/unit_test.hpp> + +struct meter_base_unit : boost::units::base_unit<meter_base_unit, boost::units::length_dimension, 1> { + static BOOST_CONSTEXPR const char* name() { return("meter"); } + static BOOST_CONSTEXPR const char* symbol() { return("m"); } +}; + +struct second_base_unit : boost::units::base_unit<second_base_unit, boost::units::time_dimension, 2> { + static BOOST_CONSTEXPR const char* name() { return("second"); } + static BOOST_CONSTEXPR const char* symbol() { return("s"); } +}; + +struct byte_base_unit : boost::units::base_unit<byte_base_unit, boost::units::dimensionless_type, 3> { + static BOOST_CONSTEXPR const char* name() { return("byte"); } + static BOOST_CONSTEXPR const char* symbol() { return("b"); } +}; + +typedef boost::units::make_system<meter_base_unit, second_base_unit>::type my_system; + +typedef boost::units::unit<boost::units::length_dimension, my_system> length; +typedef boost::units::unit<boost::units::velocity_dimension, my_system> velocity; + +typedef boost::units::make_scaled_unit<length, boost::units::scale<10, boost::units::static_rational<3> > >::type scaled_length; +typedef boost::units::make_scaled_unit<velocity, boost::units::scale<10, boost::units::static_rational<3> > >::type scaled_velocity1; + +typedef boost::units::scaled_base_unit<second_base_unit, boost::units::scale<10, boost::units::static_rational<-3> > > millisecond_base_unit; + +typedef boost::units::make_system<meter_base_unit, millisecond_base_unit>::type scaled_system; + +typedef boost::units::unit<boost::units::time_dimension, scaled_system> scaled_time; +typedef boost::units::unit<boost::units::velocity_dimension, scaled_system> scaled_velocity2; + +typedef boost::units::unit<boost::units::area_dimension, my_system> area; +typedef boost::units::make_scaled_unit<area, boost::units::scale<10, boost::units::static_rational<3> > >::type scaled_area; + +typedef boost::units::make_scaled_unit<scaled_length, boost::units::scale<2, boost::units::static_rational<10> > >::type double_scaled_length; + +typedef boost::units::scaled_base_unit<meter_base_unit, boost::units::scale<100, boost::units::static_rational<1> > > scaled_length_base_unit; +namespace boost { +namespace units { +template<> +struct base_unit_info<scaled_length_base_unit> { + static BOOST_CONSTEXPR const char* symbol() { return("scm"); } + static BOOST_CONSTEXPR const char* name() { return("scaled_meter"); } +}; +} +} +typedef boost::units::scaled_base_unit<scaled_length_base_unit, boost::units::scale<10, boost::units::static_rational<3> > > double_scaled_length_base_unit; +typedef double_scaled_length_base_unit::unit_type double_scaled_length2; + +typedef boost::units::reduce_unit<boost::units::unit<boost::units::volume_dimension, my_system> >::type custom1; + +std::string name_string(const custom1&) { return("custom1"); } +std::string symbol_string(const custom1&) { return("c1"); } + +typedef boost::units::reduce_unit<boost::units::unit<boost::units::acceleration_dimension, my_system> >::type custom2; + +BOOST_CONSTEXPR const char* name_string(const custom2&) { return("custom2"); } +BOOST_CONSTEXPR const char* symbol_string(const custom2&) { return("c2"); } + +typedef boost::units::make_scaled_unit<custom1, boost::units::scale<10, boost::units::static_rational<3> > >::type scaled_custom1; +typedef boost::units::make_scaled_unit<custom2, boost::units::scale<10, boost::units::static_rational<3> > >::type scaled_custom2; + +#ifndef BOOST_NO_CWCHAR + +#define BOOST_UNITS_TEST_OUTPUT(v, expected) \ +{ \ + std::ostringstream ss; \ + ss FORMATTERS << v; \ + BOOST_CHECK_EQUAL(ss.str(), expected); \ +} \ +{ \ + std::wostringstream ss; \ + ss FORMATTERS << v; \ + BOOST_CHECK(ss.str() == BOOST_PP_CAT(L, expected)); \ +} + +#define BOOST_UNITS_TEST_OUTPUT_REGEX(v, expected) \ +{ \ + std::ostringstream ss; \ + ss FORMATTERS << v; \ + boost::regex r(expected); \ + BOOST_CHECK_MESSAGE(boost::regex_match(ss.str(), r), \ + ss.str() + " does not match " + expected); \ +} \ +{ \ + std::wostringstream ss; \ + ss FORMATTERS << v; \ + boost::wregex r(BOOST_PP_CAT(L, expected)); \ + BOOST_CHECK(boost::regex_match(ss.str(), r)); \ +} + +#define BOOST_UNITS_TEST_OUTPUT_DISPLAY(v) \ +{ \ + std::ostringstream ss; \ + ss FORMATTERS << v; \ + std::cout << #v << ": " << ss.str() << std::endl; \ +} \ +{ \ + std::wostringstream ss; \ + ss FORMATTERS << v; \ + std::wcout << #v << ": " << ss.str() << std::endl; \ +} + +#else + +#define BOOST_UNITS_TEST_OUTPUT(v, expected) \ +{ \ + std::ostringstream ss; \ + ss FORMATTERS << v; \ + BOOST_CHECK_EQUAL(ss.str(), expected); \ +} + +#define BOOST_UNITS_TEST_OUTPUT_REGEX(v, expected) \ +{ \ + std::ostringstream ss; \ + ss FORMATTERS << v; \ + boost::regex r(expected); \ + BOOST_CHECK_MESSAGE(boost::regex_match(ss.str(), r), \ + ss.str() + " does not match " + expected); \ +} + +#define BOOST_UNITS_TEST_OUTPUT_DISPLAY(v) \ +{ \ + std::ostringstream ss; \ + ss FORMATTERS << v; \ + std::cout << #v << ": " << ss.str() << std::endl; \ +} + +#endif + +BOOST_AUTO_TEST_CASE(test_output_unit_symbol) +{ // base units using default symbol_format (no format specified) and no auto prefixing. +#define FORMATTERS + BOOST_UNITS_TEST_OUTPUT(meter_base_unit::unit_type(), "m"); + BOOST_UNITS_TEST_OUTPUT(velocity(), "m s^-1"); + BOOST_UNITS_TEST_OUTPUT(scaled_length(), "km"); + BOOST_UNITS_TEST_OUTPUT(scaled_velocity1(), "k(m s^-1)"); + BOOST_UNITS_TEST_OUTPUT(millisecond_base_unit::unit_type(), "ms"); + BOOST_UNITS_TEST_OUTPUT(scaled_time(), "ms"); + BOOST_UNITS_TEST_OUTPUT(scaled_velocity2(), "m ms^-1"); + BOOST_UNITS_TEST_OUTPUT(area(), "m^2"); + BOOST_UNITS_TEST_OUTPUT(scaled_area(), "k(m^2)"); + BOOST_UNITS_TEST_OUTPUT(double_scaled_length(), "Kikm"); + BOOST_UNITS_TEST_OUTPUT(double_scaled_length2(), "kscm"); + BOOST_UNITS_TEST_OUTPUT(custom1(), "c1"); + BOOST_UNITS_TEST_OUTPUT(custom2(), "c2"); + BOOST_UNITS_TEST_OUTPUT(scaled_custom1(), "kc1"); + BOOST_UNITS_TEST_OUTPUT(scaled_custom2(), "kc2"); + BOOST_UNITS_TEST_OUTPUT(boost::units::absolute<meter_base_unit::unit_type>(), "absolute m"); +#undef FORMATTERS +} + +BOOST_AUTO_TEST_CASE(test_output_unit_raw) +{ // raw format specified +#define FORMATTERS << boost::units::raw_format + BOOST_UNITS_TEST_OUTPUT(meter_base_unit::unit_type(), "m"); + BOOST_UNITS_TEST_OUTPUT(velocity(), "m s^-1"); + BOOST_UNITS_TEST_OUTPUT(scaled_length(), "km"); + BOOST_UNITS_TEST_OUTPUT(scaled_velocity1(), "k(m s^-1)"); + BOOST_UNITS_TEST_OUTPUT(millisecond_base_unit::unit_type(), "ms"); + BOOST_UNITS_TEST_OUTPUT(scaled_time(), "ms"); + BOOST_UNITS_TEST_OUTPUT(scaled_velocity2(), "m ms^-1"); + BOOST_UNITS_TEST_OUTPUT(area(), "m^2"); + BOOST_UNITS_TEST_OUTPUT(scaled_area(), "k(m^2)"); + BOOST_UNITS_TEST_OUTPUT(double_scaled_length(), "Kikm"); + BOOST_UNITS_TEST_OUTPUT(double_scaled_length2(), "kscm"); + // when using raw format, we ignore the user defined overloads + BOOST_UNITS_TEST_OUTPUT(custom1(), "m^3"); + BOOST_UNITS_TEST_OUTPUT(custom2(), "m s^-2"); + BOOST_UNITS_TEST_OUTPUT(scaled_custom1(), "k(m^3)"); + BOOST_UNITS_TEST_OUTPUT(scaled_custom2(), "k(m s^-2)"); + BOOST_UNITS_TEST_OUTPUT(boost::units::absolute<meter_base_unit::unit_type>(), "absolute m"); +#undef FORMATTERS +} + +BOOST_AUTO_TEST_CASE(test_output_unit_name) +{ // name format specified. +#define FORMATTERS << boost::units::name_format + BOOST_UNITS_TEST_OUTPUT(meter_base_unit::unit_type(), "meter"); + BOOST_UNITS_TEST_OUTPUT(velocity(), "meter second^-1"); + BOOST_UNITS_TEST_OUTPUT(scaled_length(), "kilometer"); + BOOST_UNITS_TEST_OUTPUT(scaled_velocity1(), "kilo(meter second^-1)"); + BOOST_UNITS_TEST_OUTPUT(millisecond_base_unit::unit_type(), "millisecond"); + BOOST_UNITS_TEST_OUTPUT(scaled_time(), "millisecond"); + BOOST_UNITS_TEST_OUTPUT(scaled_velocity2(), "meter millisecond^-1"); + BOOST_UNITS_TEST_OUTPUT(area(), "meter^2"); + BOOST_UNITS_TEST_OUTPUT(scaled_area(), "kilo(meter^2)"); + BOOST_UNITS_TEST_OUTPUT(double_scaled_length(), "kibikilometer"); + BOOST_UNITS_TEST_OUTPUT(double_scaled_length2(), "kiloscaled_meter"); + BOOST_UNITS_TEST_OUTPUT(custom1(), "custom1"); + BOOST_UNITS_TEST_OUTPUT(custom2(), "custom2"); + BOOST_UNITS_TEST_OUTPUT(scaled_custom1(), "kilocustom1"); + BOOST_UNITS_TEST_OUTPUT(scaled_custom2(), "kilocustom2"); + BOOST_UNITS_TEST_OUTPUT(boost::units::absolute<meter_base_unit::unit_type>(), "absolute meter"); +#undef FORMATTERS +} + + +BOOST_AUTO_TEST_CASE(test_output_quantity_symbol) +{ // quantity symbols using default format. +#define FORMATTERS + BOOST_UNITS_TEST_OUTPUT(1.5*meter_base_unit::unit_type(), "1.5 m"); + BOOST_UNITS_TEST_OUTPUT(1.5*velocity(), "1.5 m s^-1"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_length(), "1.5 km"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_velocity1(), "1.5 k(m s^-1)"); + BOOST_UNITS_TEST_OUTPUT(1.5*millisecond_base_unit::unit_type(), "1.5 ms"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_time(), "1.5 ms"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_velocity2(), "1.5 m ms^-1"); + BOOST_UNITS_TEST_OUTPUT(1.5*area(), "1.5 m^2"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_area(), "1.5 k(m^2)"); + BOOST_UNITS_TEST_OUTPUT(1.5*double_scaled_length(), "1.5 Kikm"); + BOOST_UNITS_TEST_OUTPUT(1.5*double_scaled_length2(), "1.5 kscm"); + BOOST_UNITS_TEST_OUTPUT(1.5*custom1(), "1.5 c1"); + BOOST_UNITS_TEST_OUTPUT(1.5*custom2(), "1.5 c2"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_custom1(), "1.5 kc1"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_custom2(), "1.5 kc2"); + BOOST_UNITS_TEST_OUTPUT(1.5*boost::units::absolute<meter_base_unit::unit_type>(), "1.5 absolute m"); + BOOST_UNITS_TEST_OUTPUT(std::pow(2., 10) * byte_base_unit::unit_type(), "1024 b"); + +#undef FORMATTERS +} + +BOOST_AUTO_TEST_CASE(test_output_quantity_raw) +{ // quantity symbols using raw format. +#define FORMATTERS << boost::units::raw_format + BOOST_UNITS_TEST_OUTPUT(1.5*meter_base_unit::unit_type(), "1.5 m"); + BOOST_UNITS_TEST_OUTPUT(1.5*velocity(), "1.5 m s^-1"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_length(), "1.5 km"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_velocity1(), "1.5 k(m s^-1)"); + BOOST_UNITS_TEST_OUTPUT(1.5*millisecond_base_unit::unit_type(), "1.5 ms"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_time(), "1.5 ms"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_velocity2(), "1.5 m ms^-1"); + BOOST_UNITS_TEST_OUTPUT(1.5*area(), "1.5 m^2"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_area(), "1.5 k(m^2)"); + BOOST_UNITS_TEST_OUTPUT(1.5*double_scaled_length(), "1.5 Kikm"); + BOOST_UNITS_TEST_OUTPUT(1.5*double_scaled_length2(), "1.5 kscm"); + // when using raw format, we ignore the user defined overloads + BOOST_UNITS_TEST_OUTPUT(1.5*custom1(), "1.5 m^3"); + BOOST_UNITS_TEST_OUTPUT(1.5*custom2(), "1.5 m s^-2"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_custom1(), "1.5 k(m^3)"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_custom2(), "1.5 k(m s^-2)"); + BOOST_UNITS_TEST_OUTPUT(1.5*boost::units::absolute<meter_base_unit::unit_type>(), "1.5 absolute m"); +#undef FORMATTERS +} + +BOOST_AUTO_TEST_CASE(test_output_quantity_name) +{ // // quantity symbols using name format. +#define FORMATTERS << boost::units::name_format + BOOST_UNITS_TEST_OUTPUT(1.5*meter_base_unit::unit_type(), "1.5 meter"); + BOOST_UNITS_TEST_OUTPUT(1.5*velocity(), "1.5 meter second^-1"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_length(), "1.5 kilometer"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_velocity1(), "1.5 kilo(meter second^-1)"); + BOOST_UNITS_TEST_OUTPUT(1.5*millisecond_base_unit::unit_type(), "1.5 millisecond"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_time(), "1.5 millisecond"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_velocity2(), "1.5 meter millisecond^-1"); + BOOST_UNITS_TEST_OUTPUT(1.5*area(), "1.5 meter^2"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_area(), "1.5 kilo(meter^2)"); + BOOST_UNITS_TEST_OUTPUT(1.5*double_scaled_length(), "1.5 kibikilometer"); + BOOST_UNITS_TEST_OUTPUT(1.5*double_scaled_length2(), "1.5 kiloscaled_meter"); + BOOST_UNITS_TEST_OUTPUT(1.5*custom1(), "1.5 custom1"); + BOOST_UNITS_TEST_OUTPUT(1.5*custom2(), "1.5 custom2"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_custom1(), "1.5 kilocustom1"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_custom2(), "1.5 kilocustom2"); + BOOST_UNITS_TEST_OUTPUT(1.5*boost::units::absolute<meter_base_unit::unit_type>(), "1.5 absolute meter"); +#undef FORMATTERS +} + +BOOST_AUTO_TEST_CASE(test_output_autoprefixed_quantity_name) +{ // Engineering autoprefix, with name format. +#define FORMATTERS << boost::units::name_format << boost::units::engineering_prefix + // Single base unit like meter. + BOOST_UNITS_TEST_OUTPUT(1.5*meter_base_unit::unit_type(), "1.5 meter"); + BOOST_UNITS_TEST_OUTPUT(1500.0*meter_base_unit::unit_type(), "1.5 kilometer"); + BOOST_UNITS_TEST_OUTPUT(1.5e7*meter_base_unit::unit_type(), "15 megameter"); + BOOST_UNITS_TEST_OUTPUT(1.5e-3*meter_base_unit::unit_type(), "1.5 millimeter"); + BOOST_UNITS_TEST_OUTPUT(1.5e-9*meter_base_unit::unit_type(), "1.5 nanometer"); + BOOST_UNITS_TEST_OUTPUT(1.5e-8*meter_base_unit::unit_type(), "15 nanometer"); + BOOST_UNITS_TEST_OUTPUT(1.5e-10*meter_base_unit::unit_type(), "150 picometer"); + BOOST_UNITS_TEST_OUTPUT(0.0000000012345 * meter_base_unit::unit_type(), "1.2345 nanometer"); + + // Too small or large for a multiple name. + BOOST_UNITS_TEST_OUTPUT_REGEX(9.99999e-25 * meter_base_unit::unit_type(), "9\\.99999e-0?25 meter"); // Just too small for multiple. + BOOST_UNITS_TEST_OUTPUT_REGEX(1e+28 * meter_base_unit::unit_type(), "1e\\+0?28 meter"); // Just too large for multiple. + BOOST_UNITS_TEST_OUTPUT_REGEX(1.5e-25 * meter_base_unit::unit_type(), "1\\.5e-0?25 meter"); // Too small for multiple. + BOOST_UNITS_TEST_OUTPUT_REGEX(1.5e+28 * meter_base_unit::unit_type(), "1\\.5e\\+0?28 meter"); // Too large for multiple. + // Too 'biggest or too smallest'. + BOOST_UNITS_TEST_OUTPUT_REGEX((std::numeric_limits<float>::max)()*meter_base_unit::unit_type(), "3\\.40282e\\+0?38 meter"); + BOOST_UNITS_TEST_OUTPUT_REGEX((std::numeric_limits<float>::min)()*meter_base_unit::unit_type(), "1\\.17549e-0?38 meter"); + BOOST_UNITS_TEST_OUTPUT((std::numeric_limits<double>::max)()*meter_base_unit::unit_type(), "1.79769e+308 meter"); + BOOST_UNITS_TEST_OUTPUT((std::numeric_limits<double>::min)()*meter_base_unit::unit_type(), "2.22507e-308 meter"); + // Infinity and NaN + BOOST_UNITS_TEST_OUTPUT_REGEX(std::numeric_limits<float>::infinity()*meter_base_unit::unit_type(), "(1\\.#INF|inf|INF|Inf) meter"); + BOOST_UNITS_TEST_OUTPUT_REGEX(-std::numeric_limits<float>::infinity()*meter_base_unit::unit_type(), "-(1\\.#INF|inf|INF|Inf) meter"); + BOOST_UNITS_TEST_OUTPUT_REGEX(std::numeric_limits<double>::quiet_NaN()*meter_base_unit::unit_type(), "(1\\.#QNAN|nan|NaNQ|NaN) meter"); + BOOST_UNITS_TEST_OUTPUT_REGEX(-std::numeric_limits<double>::quiet_NaN()*meter_base_unit::unit_type(), "-?(1\\.#IND|nan|nan\\(ind\\)|NaNQ|NaN) meter"); + + BOOST_UNITS_TEST_OUTPUT(1.5*velocity(), "1.5 meter second^-1"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_length(), "1.5 kilometer"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_velocity1(), "1.5 kilo(meter second^-1)"); + BOOST_UNITS_TEST_OUTPUT(1.5*millisecond_base_unit::unit_type(), "1.5 millisecond"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_time(), "1.5 millisecond"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_velocity2(), "1.5 meter millisecond^-1"); + BOOST_UNITS_TEST_OUTPUT(1.5*area(), "1.5 meter^2"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_area(), "1.5 kilo(meter^2)"); + BOOST_UNITS_TEST_OUTPUT(1.5*double_scaled_length(), "1.536 megameter"); // 1.5 * 2^10 = 1.5 * 1024 = 1.536 + BOOST_UNITS_TEST_OUTPUT(1.5*double_scaled_length2(), "1.5 kiloscaled_meter"); + BOOST_UNITS_TEST_OUTPUT(1.5*custom1(), "1.5 custom1"); + BOOST_UNITS_TEST_OUTPUT(1.5*custom2(), "1.5 custom2"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_custom1(), "1.5 kilocustom1"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_custom2(), "1.5 kilocustom2"); + BOOST_UNITS_TEST_OUTPUT(1.5*boost::units::absolute<meter_base_unit::unit_type>(), "1.5 absolute meter"); + BOOST_UNITS_TEST_OUTPUT(std::pow(2., 10) * byte_base_unit::unit_type(), "1.024 kilobyte"); + + BOOST_UNITS_TEST_OUTPUT(1.5, "1.5"); // scalar. + BOOST_UNITS_TEST_OUTPUT(1567., "1567"); // scalars are *not* autoprefixed. + BOOST_UNITS_TEST_OUTPUT(0.00015, "0.00015"); // scalars are *not* autoprefixed. + BOOST_UNITS_TEST_OUTPUT(-1.5, "-1.5"); // scalar. + BOOST_UNITS_TEST_OUTPUT(-1567., "-1567"); // scalars are *not* autoprefixed. + BOOST_UNITS_TEST_OUTPUT(-0.00015, "-0.00015"); // scalars are *not* autoprefixed. +#undef FORMATTERS +} + +BOOST_AUTO_TEST_CASE(test_output_autoprefixed_quantity_symbol) +{ // Engineering autoprefix, with symbol format. +#define FORMATTERS << boost::units::symbol_format << boost::units::engineering_prefix + // Single base unit like m. + BOOST_UNITS_TEST_OUTPUT(1.5*meter_base_unit::unit_type(), "1.5 m"); + BOOST_UNITS_TEST_OUTPUT(1500.0*meter_base_unit::unit_type(), "1.5 km"); + BOOST_UNITS_TEST_OUTPUT(1.5e7*meter_base_unit::unit_type(), "15 Mm"); + BOOST_UNITS_TEST_OUTPUT(1.5e-3*meter_base_unit::unit_type(), "1.5 mm"); + BOOST_UNITS_TEST_OUTPUT(1.5e-9*meter_base_unit::unit_type(), "1.5 nm"); + BOOST_UNITS_TEST_OUTPUT(1.5e-8*meter_base_unit::unit_type(), "15 nm"); + BOOST_UNITS_TEST_OUTPUT(1.5e-10*meter_base_unit::unit_type(), "150 pm"); + // Too small or large for a multiple name. + BOOST_UNITS_TEST_OUTPUT_REGEX(9.99999e-25 * meter_base_unit::unit_type(), "9\\.99999e-0?25 m"); // Just too small for multiple. + BOOST_UNITS_TEST_OUTPUT_REGEX(1e+28 * meter_base_unit::unit_type(), "1e\\+0?28 m"); // Just too large for multiple. + BOOST_UNITS_TEST_OUTPUT_REGEX(1.5e-25 * meter_base_unit::unit_type(), "1\\.5e-0?25 m"); // Too small for multiple. + BOOST_UNITS_TEST_OUTPUT_REGEX(1.5e+28 * meter_base_unit::unit_type(), "1\\.5e\\+0?28 m"); // Too large for multiple. + // + BOOST_UNITS_TEST_OUTPUT_REGEX((std::numeric_limits<float>::max)()*meter_base_unit::unit_type(), "3\\.40282e\\+0?38 m"); + BOOST_UNITS_TEST_OUTPUT_REGEX((std::numeric_limits<float>::min)()*meter_base_unit::unit_type(), "1\\.17549e-0?38 m"); + BOOST_UNITS_TEST_OUTPUT((std::numeric_limits<double>::max)()*meter_base_unit::unit_type(), "1.79769e+308 m"); + BOOST_UNITS_TEST_OUTPUT((std::numeric_limits<double>::min)()*meter_base_unit::unit_type(), "2.22507e-308 m"); + + BOOST_UNITS_TEST_OUTPUT(1.5*velocity(), "1.5 m s^-1"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_length(), "1.5 km"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_velocity1(), "1.5 k(m s^-1)"); + BOOST_UNITS_TEST_OUTPUT(1.5*millisecond_base_unit::unit_type(), "1.5 ms"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_time(), "1.5 ms"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_velocity2(), "1.5 m ms^-1"); + BOOST_UNITS_TEST_OUTPUT(1.5*area(), "1.5 m^2"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_area(), "1.5 k(m^2)"); + BOOST_UNITS_TEST_OUTPUT(1.5*double_scaled_length(), "1.536 Mm"); // 1.5 * 2^10 = 1.5 * 1024 = 1.536 + BOOST_UNITS_TEST_OUTPUT(1.5*double_scaled_length2(), "1.5 kscm"); + BOOST_UNITS_TEST_OUTPUT(1.5*custom1(), "1.5 c1"); + BOOST_UNITS_TEST_OUTPUT(1.5*custom2(), "1.5 c2"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_custom1(), "1.5 kc1"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_custom2(), "1.5 kc2"); + BOOST_UNITS_TEST_OUTPUT(1.5*boost::units::absolute<meter_base_unit::unit_type>(), "1.5 absolute m"); + BOOST_UNITS_TEST_OUTPUT(std::pow(2., 10) * byte_base_unit::unit_type(), "1.024 kb"); + +#undef FORMATTERS +} + +BOOST_AUTO_TEST_CASE(test_output_auto_binary_prefixed_quantity_symbol) +{ // Binary prefix with symbol format. +#define FORMATTERS << boost::units::symbol_format << boost::units::binary_prefix + BOOST_UNITS_TEST_OUTPUT(1024 * byte_base_unit::unit_type(), "1 Kib"); + BOOST_UNITS_TEST_OUTPUT(std::pow(2., 20) * byte_base_unit::unit_type(), "1 Mib"); + BOOST_UNITS_TEST_OUTPUT(std::pow(2., 30) * byte_base_unit::unit_type(), "1 Gib"); + BOOST_UNITS_TEST_OUTPUT(std::pow(2., 40) * byte_base_unit::unit_type(), "1 Tib"); + BOOST_UNITS_TEST_OUTPUT(std::pow(2., 50) * byte_base_unit::unit_type(), "1 Pib"); + BOOST_UNITS_TEST_OUTPUT(std::pow(2., 60) * byte_base_unit::unit_type(), "1 Eib"); + BOOST_UNITS_TEST_OUTPUT(std::pow(2., 70) * byte_base_unit::unit_type(), "1 Zib"); + BOOST_UNITS_TEST_OUTPUT(std::pow(2., 80) * byte_base_unit::unit_type(), "1 Yib"); + BOOST_UNITS_TEST_OUTPUT(42, "42"); // integer scalar. + BOOST_UNITS_TEST_OUTPUT(-42, "-42"); // integer scalar. + BOOST_UNITS_TEST_OUTPUT(1567, "1567"); // scalars are *not* autoprefixed. + BOOST_UNITS_TEST_OUTPUT(-1567, "-1567"); // scalars are *not* autoprefixed. +#undef FORMATTERS +} + +BOOST_AUTO_TEST_CASE(test_output_auto_binary_prefixed_quantity_name) +{ // Binary prefix with name format. + // http://physics.nist.gov/cuu/Units/binary.html + // 1998 the International Electrotechnical Commission (IEC) approved + // IEC 60027-2, Second edition, 2000-11, Letter symbols to be used in electrical technology + // - Part 2: Telecommunications and electronics. + // IEC 80000-13:2008, Quantities and units + // - Part 13: Information science and technology +#define FORMATTERS << boost::units::name_format << boost::units::binary_prefix + BOOST_UNITS_TEST_OUTPUT(2048 * byte_base_unit::unit_type(), "2 kibibyte"); + BOOST_UNITS_TEST_OUTPUT(std::pow(2., 32) *byte_base_unit::unit_type(), "4 gibibyte"); + BOOST_UNITS_TEST_OUTPUT(std::pow(2., 41) *byte_base_unit::unit_type(), "2 tebibyte"); // http://en.wikipedia.org/wiki/Tebibyte + BOOST_UNITS_TEST_OUTPUT(std::pow(2., 50) *byte_base_unit::unit_type(), "1 pebibyte"); + BOOST_UNITS_TEST_OUTPUT(std::pow(2., 60) *byte_base_unit::unit_type(), "1 exbibyte"); + BOOST_UNITS_TEST_OUTPUT(std::pow(2., 70) *byte_base_unit::unit_type(), "1 zebibyte"); + BOOST_UNITS_TEST_OUTPUT(std::pow(2., 80) *byte_base_unit::unit_type(), "1 yobibyte"); + BOOST_UNITS_TEST_OUTPUT(2048, "2048"); // scalars are *not* autoprefixed. + BOOST_UNITS_TEST_OUTPUT(-4096, "-4096"); // scalars are *not* autoprefixed. +#undef FORMATTERS +} + +// Tests on using more than one format or prefix - only the last specified should be used. +// (This may indicate a programming mistake, but it is ignored). +BOOST_AUTO_TEST_CASE(test_output_quantity_name_duplicate) +{ // Ensure that if more than one format specified, only the last is used. +#define FORMATTERS << boost::units::symbol_format << boost::units::name_format + BOOST_UNITS_TEST_OUTPUT(1.5*meter_base_unit::unit_type(), "1.5 meter"); +#undef FORMATTERS +} + +BOOST_AUTO_TEST_CASE(test_output_quantity_symbol_duplicate) +{ // Ensure that if more than one format specified, only the last is used. +#define FORMATTERS << boost::units::name_format << boost::units::symbol_format + BOOST_UNITS_TEST_OUTPUT(1.5*meter_base_unit::unit_type(), "1.5 m"); +#undef FORMATTERS +} + +BOOST_AUTO_TEST_CASE(test_output_auto_binary_prefixed_quantity_name_duplicate) +{ // Ensure that if more than one auto prefix specified, only the last is used. +#define FORMATTERS << boost::units::name_format << boost::units::binary_prefix << boost::units::engineering_prefix + BOOST_UNITS_TEST_OUTPUT(2048 * byte_base_unit::unit_type(), "2.048 kilobyte"); +#undef FORMATTERS +} + +BOOST_AUTO_TEST_CASE(test_output_auto_binary_prefixed_quantity_symbol_duplicate) +{ // Ensure that if more than one auto prefix specified, only the last is used. +#define FORMATTERS << boost::units::symbol_format << boost::units::engineering_prefix << boost::units::binary_prefix + BOOST_UNITS_TEST_OUTPUT(2048 * byte_base_unit::unit_type(), "2 Kib"); +#undef FORMATTERS +} + +BOOST_AUTO_TEST_CASE(test_output_typename_format) +{ // Displays typename formatting result. The test doesn't check the formatting result + // and thus doesn't fail because the formatting result is platform-dependent. +#define FORMATTERS << boost::units::typename_format + BOOST_UNITS_TEST_OUTPUT_DISPLAY(meter_base_unit::unit_type()); + BOOST_UNITS_TEST_OUTPUT_DISPLAY(velocity()); + BOOST_UNITS_TEST_OUTPUT_DISPLAY(scaled_length()); + BOOST_UNITS_TEST_OUTPUT_DISPLAY(scaled_velocity1()); + BOOST_UNITS_TEST_OUTPUT_DISPLAY(millisecond_base_unit::unit_type()); + BOOST_UNITS_TEST_OUTPUT_DISPLAY(scaled_time()); + BOOST_UNITS_TEST_OUTPUT_DISPLAY(scaled_velocity2()); + BOOST_UNITS_TEST_OUTPUT_DISPLAY(area()); + BOOST_UNITS_TEST_OUTPUT_DISPLAY(scaled_area()); + BOOST_UNITS_TEST_OUTPUT_DISPLAY(double_scaled_length()); + BOOST_UNITS_TEST_OUTPUT_DISPLAY(double_scaled_length2()); + BOOST_UNITS_TEST_OUTPUT_DISPLAY(custom1()); + BOOST_UNITS_TEST_OUTPUT_DISPLAY(custom2()); + BOOST_UNITS_TEST_OUTPUT_DISPLAY(scaled_custom1()); + BOOST_UNITS_TEST_OUTPUT_DISPLAY(scaled_custom2()); + BOOST_UNITS_TEST_OUTPUT_DISPLAY(boost::units::absolute<meter_base_unit::unit_type>()); +#undef FORMATTERS +} diff --git a/src/boost/libs/units/test/test_predicates.cpp b/src/boost/libs/units/test/test_predicates.cpp new file mode 100644 index 00000000..d05c4eaf --- /dev/null +++ b/src/boost/libs/units/test/test_predicates.cpp @@ -0,0 +1,100 @@ +// Boost.Units - A C++ library for zero-overhead dimensional analysis and +// unit/quantity manipulation and conversion +// +// Copyright (C) 2003-2008 Matthias Christian Schabel +// Copyright (C) 2008 Steven Watanabe +// +// Distributed under 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) + +/** +\file + +\brief test_predicates.cpp + +\details +Test metafunctions is_unit, is_quantity, is_dimension_list .... + +Output: +@verbatim +@endverbatim +**/ + +#include <boost/mpl/assert.hpp> +#include <boost/mpl/list/list0.hpp> + +#include <boost/units/base_dimension.hpp> +#include <boost/units/base_unit.hpp> +#include <boost/units/dimension.hpp> +#include <boost/units/is_dimension_list.hpp> +#include <boost/units/is_quantity.hpp> +#include <boost/units/is_quantity_of_dimension.hpp> +#include <boost/units/is_quantity_of_system.hpp> +#include <boost/units/is_unit.hpp> +#include <boost/units/is_unit_of_dimension.hpp> +#include <boost/units/is_unit_of_system.hpp> +#include <boost/units/make_system.hpp> +#include <boost/units/quantity.hpp> +#include <boost/units/unit.hpp> + +namespace bu = boost::units; + +struct dimension_tag : boost::units::base_dimension<dimension_tag,0> { }; + +typedef dimension_tag::dimension_type dimension; + +struct base_unit1 : bu::base_unit<base_unit1, dimension, 100> {}; +struct base_unit2 : bu::base_unit<base_unit2, dimension, 101> {}; + +typedef bu::make_system<base_unit1>::type system1; +typedef bu::make_system<base_unit2>::type system2; + +int main(int,char *[]) +{ + BOOST_MPL_ASSERT((bu::is_dimension_list<bu::dimensionless_type>)); + BOOST_MPL_ASSERT((bu::is_dimension_list<dimension>)); + BOOST_MPL_ASSERT_NOT((bu::is_dimension_list<boost::mpl::list0<> >)); + BOOST_MPL_ASSERT_NOT((bu::is_dimension_list<int>)); + + BOOST_MPL_ASSERT((bu::is_unit<bu::unit<bu::dimensionless_type, system1> >)); + BOOST_MPL_ASSERT((bu::is_unit<bu::unit<dimension, system1> >)); + BOOST_MPL_ASSERT_NOT((bu::is_unit<int>)); + + BOOST_MPL_ASSERT((bu::is_unit_of_system<bu::unit<bu::dimensionless_type, system1>, system1>)); + BOOST_MPL_ASSERT((bu::is_unit_of_system<bu::unit<dimension, system1>, system1>)); + BOOST_MPL_ASSERT_NOT((bu::is_unit_of_system<bu::unit<bu::dimensionless_type, system1>, system2>)); + BOOST_MPL_ASSERT_NOT((bu::is_unit_of_system<bu::unit<dimension, system1>, system2>)); + BOOST_MPL_ASSERT_NOT((bu::is_unit_of_system<int, system1>)); + BOOST_MPL_ASSERT_NOT((bu::is_unit_of_system<int, system2>)); + + BOOST_MPL_ASSERT((bu::is_unit_of_dimension<bu::unit<bu::dimensionless_type, system1>, bu::dimensionless_type>)); + BOOST_MPL_ASSERT((bu::is_unit_of_dimension<bu::unit<dimension, system1>, dimension>)); + BOOST_MPL_ASSERT_NOT((bu::is_unit_of_dimension<bu::unit<bu::dimensionless_type, system1>, dimension>)); + BOOST_MPL_ASSERT_NOT((bu::is_unit_of_dimension<bu::unit<dimension, system1>, bu::dimensionless_type>)); + BOOST_MPL_ASSERT_NOT((bu::is_unit_of_dimension<int, bu::dimensionless_type>)); + BOOST_MPL_ASSERT_NOT((bu::is_unit_of_dimension<int, dimension>)); + + BOOST_MPL_ASSERT((bu::is_quantity<bu::quantity<bu::unit<bu::dimensionless_type, system1> > >)); + BOOST_MPL_ASSERT((bu::is_quantity<bu::quantity<bu::unit<dimension, system1> > >)); + BOOST_MPL_ASSERT_NOT((bu::is_quantity<int>)); + + BOOST_MPL_ASSERT((bu::is_quantity<bu::quantity<bu::unit<bu::dimensionless_type, system1>, int> >)); + BOOST_MPL_ASSERT((bu::is_quantity<bu::quantity<bu::unit<dimension, system1>, int> >)); + + BOOST_MPL_ASSERT((bu::is_quantity_of_system<bu::quantity<bu::unit<bu::dimensionless_type, system1> >, system1>)); + BOOST_MPL_ASSERT((bu::is_quantity_of_system<bu::quantity<bu::unit<dimension, system1> >, system1>)); + BOOST_MPL_ASSERT_NOT((bu::is_quantity_of_system<bu::quantity<bu::unit<bu::dimensionless_type, system1> >, system2>)); + BOOST_MPL_ASSERT_NOT((bu::is_quantity_of_system<bu::quantity<bu::unit<dimension, system1> >, system2>)); + BOOST_MPL_ASSERT_NOT((bu::is_quantity_of_system<int, system1>)); + BOOST_MPL_ASSERT_NOT((bu::is_quantity_of_system<int, system2>)); + + BOOST_MPL_ASSERT((bu::is_quantity_of_dimension<bu::quantity<bu::unit<bu::dimensionless_type, system1> >, bu::dimensionless_type>)); + BOOST_MPL_ASSERT((bu::is_quantity_of_dimension<bu::quantity<bu::unit<dimension, system1> >, dimension>)); + BOOST_MPL_ASSERT_NOT((bu::is_quantity_of_dimension<bu::quantity<bu::unit<bu::dimensionless_type, system1> >, dimension>)); + BOOST_MPL_ASSERT_NOT((bu::is_quantity_of_dimension<bu::quantity<bu::unit<dimension, system1> >, bu::dimensionless_type>)); + BOOST_MPL_ASSERT_NOT((bu::is_quantity_of_dimension<int, bu::dimensionless_type>)); + BOOST_MPL_ASSERT_NOT((bu::is_quantity_of_dimension<int, dimension>)); + + return 0; +} diff --git a/src/boost/libs/units/test/test_quantity.cpp b/src/boost/libs/units/test/test_quantity.cpp new file mode 100644 index 00000000..b6461bf2 --- /dev/null +++ b/src/boost/libs/units/test/test_quantity.cpp @@ -0,0 +1,203 @@ +// Boost.Units - A C++ library for zero-overhead dimensional analysis and +// unit/quantity manipulation and conversion +// +// Copyright (C) 2003-2008 Matthias Christian Schabel +// Copyright (C) 2008 Steven Watanabe +// +// Distributed under 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) + +/** +\file + +\brief test_units_1.cpp + +\details +Test unit class. + +Output: +@verbatim +@endverbatim +**/ + +#include "test_header.hpp" + +#include <boost/units/pow.hpp> + +namespace bu = boost::units; + +BOOST_STATIC_CONSTEXPR double E_ = 2.718281828459045235360287471352662497757; + +int test_main(int,char *[]) +{ + // default constructor + BOOST_CONSTEXPR_OR_CONST bu::quantity<bu::energy> E1; + BOOST_CHECK(E1.value() == double()); + + // value_type constructor + BOOST_CONSTEXPR_OR_CONST bu::quantity<bu::energy> E2(E_*bu::joules); + BOOST_CHECK(E2.value() == E_); + + // copy constructor + BOOST_CONSTEXPR_OR_CONST bu::quantity<bu::energy> E3(E2); + BOOST_CHECK(E3.value() == E_); + + // operator= + BOOST_CONSTEXPR_OR_CONST bu::quantity<bu::energy> E4 = E2; + BOOST_CHECK(E4.value() == E_); + + // implicit copy constructor value_type conversion + BOOST_CONSTEXPR_OR_CONST bu::quantity<bu::energy,float> E5(E2); + BOOST_UNITS_CHECK_CLOSE(E5.value(),float(E_)); + + // implicit operator= value_type conversion + //BOOST_CONSTEXPR_OR_CONST bu::quantity<bu::energy,float> E7 = E2; + //BOOST_UNITS_CHECK_CLOSE(E7.value(),float(E_)); + + //BOOST_CONSTEXPR_OR_CONST bu::quantity<bu::energy,long> E8 = E2; + //BOOST_CHECK(E8.value() == long(E_)); + + // const construction + bu::quantity<bu::energy> E9(E2); + BOOST_CHECK(E9.value() == E_); + + // value assignment + bu::quantity_cast<double&>(E9) = 1.5; + BOOST_CHECK(E9.value() == 1.5); + + // value assignment with implicit value_type conversion + bu::quantity_cast<double&>(E9) = 2; + BOOST_CHECK(E9.value() == double(2)); + + // operator+=(this_type) + E9 = 2.0*bu::joules; + E9 += E9; + BOOST_CHECK(E9.value() == 4.0); + + // operator-=(this_type) + E9 = 2.0*bu::joules; + E9 -= E9; + BOOST_CHECK(E9.value() == 0.0); + + // operator*=(value_type) + E9 = 2.0*bu::joules; + E9 *= 2.0; + BOOST_CHECK(E9.value() == 4.0); + + // operator/=(value_type) + E9 = 2.0*bu::joules; + E9 /= 2.0; + BOOST_CHECK(E9.value() == 1.0); + + // static construct quantity from value_type + BOOST_CONSTEXPR_OR_CONST bu::quantity<bu::energy> E(bu::quantity<bu::energy>::from_value(2.5)); + BOOST_CHECK(E.value() == 2.5); + + // quantity_cast + + // unit * scalar + BOOST_CHECK(bu::joules*2.0 == bu::quantity<bu::energy>::from_value(2.0)); + + // unit / scalar + BOOST_CHECK(bu::joules/2.0 == bu::quantity<bu::energy>::from_value(0.5)); + + // scalar * unit + BOOST_CHECK(2.0*bu::joules == bu::quantity<bu::energy>::from_value(2.0)); + + // scalar / unit + BOOST_CHECK(2.0/bu::joules == bu::quantity<bu::inverse_energy>::from_value(2.0)); + + // quantity * scalar + BOOST_CHECK(E*2.0 == bu::quantity<bu::energy>::from_value(5.0)); + + // quantity / scalar + BOOST_CHECK(E/2.0 == bu::quantity<bu::energy>::from_value(1.25)); + + // scalar * quantity + BOOST_CHECK(2.0*E == bu::quantity<bu::energy>::from_value(5.0)); + + // scalar / quantity + BOOST_CHECK(2.0/E == bu::quantity<bu::inverse_energy>::from_value(0.8)); + + BOOST_CONSTEXPR_OR_CONST bu::quantity<bu::length> L(1.0*bu::meters); + BOOST_CONSTEXPR_OR_CONST bu::quantity<bu::mass> M(2.0*bu::kilograms); + BOOST_CONSTEXPR_OR_CONST bu::quantity<bu::time> T(3.0*bu::seconds); + BOOST_CONSTEXPR_OR_CONST bu::quantity<bu::velocity> V(bu::quantity<bu::velocity>::from_value(4.0)); + + // unit * quantity + BOOST_CHECK(bu::seconds*V == 4.0*bu::meters); + + // unit / quantity + BOOST_CHECK(bu::meters/V == 0.25*bu::seconds); + + // quantity * unit + BOOST_CHECK(V*bu::seconds == 4.0*bu::meters); + + // quantity / unit + BOOST_CHECK(V/bu::meters == 4.0/bu::seconds); + + // +quantity + BOOST_CHECK(+V == 4.0*bu::meters_per_second); + + // -quantity + BOOST_CHECK(-V == -4.0*bu::meters_per_second); + + // quantity + quantity + BOOST_CHECK(V+V == 8.0*bu::meters_per_second); + + // quantity - quantity + BOOST_CHECK(V-V == 0.0*bu::meters_per_second); + + // quantity * quantity + BOOST_CHECK(V*T == 12.0*bu::meters); + + // quantity / quantity + BOOST_CHECK(L/V == 0.25*bu::seconds); + + BOOST_CONSTEXPR_OR_CONST bu::quantity<bu::area> A(2.0*bu::square_meters); + BOOST_CONSTEXPR_OR_CONST bu::quantity<bu::volume> VL(1.0*bu::cubic_meters); + + // integer power of quantity + BOOST_CHECK(2.0*bu::pow<2>(L) == A); + + // rational power of quantity + BOOST_CHECK((bu::pow< bu::static_rational<2,3> >(VL) == 0.5*A)); + + // integer root of quantity + BOOST_CHECK(bu::root<2>(A) == std::sqrt(2.0)*L); + + // rational root of quantity + BOOST_CHECK((bu::root< bu::static_rational<3,2> >(VL) == 0.5*A)); + + BOOST_CONSTEXPR_OR_CONST bu::quantity<bu::area> A1(0.0*bu::square_meters), + A2(0.0*bu::square_meters), + A3(1.0*bu::square_meters), + A4(-1.0*bu::square_meters); + + // operator== + BOOST_CHECK((A1 == A2) == true); + BOOST_CHECK((A1 == A3) == false); + + // operator!= + BOOST_CHECK((A1 != A2) == false); + BOOST_CHECK((A1 != A3) == true); + + // operator< + BOOST_CHECK((A1 < A2) == false); + BOOST_CHECK((A1 < A3) == true); + + // operator<= + BOOST_CHECK((A1 <= A2) == true); + BOOST_CHECK((A1 <= A3) == true); + + // operator> + BOOST_CHECK((A1 > A2) == false); + BOOST_CHECK((A1 > A4) == true); + + // operator>= + BOOST_CHECK((A1 >= A2) == true); + BOOST_CHECK((A1 >= A4) == true); + + return 0; +} diff --git a/src/boost/libs/units/test/test_reduce_unit.cpp b/src/boost/libs/units/test/test_reduce_unit.cpp new file mode 100644 index 00000000..c9daed09 --- /dev/null +++ b/src/boost/libs/units/test/test_reduce_unit.cpp @@ -0,0 +1,30 @@ +// Boost.Units - A C++ library for zero-overhead dimensional analysis and +// unit/quantity manipulation and conversion +// +// Copyright (C) 2003-2008 Matthias Christian Schabel +// Copyright (C) 2007-2008 Steven Watanabe +// +// Distributed under 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) + +/** +\file + +\brief test_reduce_unit.cpp + +\details +Test that reduce_unit works correctly by itself to try to isolate problems. + +Output: +@verbatim +@endverbatim +**/ + +#include <boost/units/reduce_unit.hpp> +#include <boost/units/base_units/si/kelvin.hpp> + +#include <boost/mpl/assert.hpp> +#include <boost/type_traits/is_same.hpp> + +BOOST_MPL_ASSERT((boost::is_same<boost::units::reduce_unit<boost::units::si::kelvin_base_unit::unit_type>::type, boost::units::si::kelvin_base_unit::unit_type>)); diff --git a/src/boost/libs/units/test/test_scaled_conversion.cpp b/src/boost/libs/units/test/test_scaled_conversion.cpp new file mode 100644 index 00000000..c9da8fcf --- /dev/null +++ b/src/boost/libs/units/test/test_scaled_conversion.cpp @@ -0,0 +1,66 @@ +// Boost.Units - A C++ library for zero-overhead dimensional analysis and +// unit/quantity manipulation and conversion +// +// Copyright (C) 2003-2008 Matthias Christian Schabel +// Copyright (C) 2007-2008 Steven Watanabe +// +// Distributed under 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) + +/** +\file + +\brief test_scaled_conversion.cpp + +\details +Test unit scaling + +Output: +@verbatim +@endverbatim +**/ + +#include <boost/units/quantity.hpp> +#include <boost/units/conversion.hpp> +#include <boost/units/unit.hpp> +#include <boost/units/base_unit.hpp> +#include <boost/units/scaled_base_unit.hpp> +#include <boost/units/scale.hpp> +#include <boost/units/base_dimension.hpp> +#include <boost/units/derived_dimension.hpp> + +#include <boost/test/minimal.hpp> + +#define BOOST_UNITS_CHECK_CLOSE(a, b) (BOOST_CHECK((std::abs((a) - (b)) < .0000001))) + +namespace bu = boost::units; + +struct base_dimension1 : bu::base_dimension<base_dimension1, 1> {}; +struct base_dimension2 : bu::base_dimension<base_dimension2, 2> {}; +struct base_dimension3 : bu::base_dimension<base_dimension3, 3> {}; + +typedef bu::derived_dimension<base_dimension1, 1, base_dimension2, 1, base_dimension3, 1>::type dimension4; + +struct base_unit1 : bu::base_unit<base_unit1, base_dimension1::dimension_type, 1> {}; +struct base_unit2 : bu::base_unit<base_unit2, base_dimension1::dimension_type, 2> {}; +struct base_unit3 : bu::base_unit<base_unit3, base_dimension1::dimension_type, 3> {}; +struct base_unit4 : bu::base_unit<base_unit4, dimension4, 4> {}; +struct base_unit5 : bu::base_unit<base_unit5, base_dimension3::dimension_type, 5> {}; + +typedef bu::scaled_base_unit<base_unit2, bu::scale<10, bu::static_rational<3> > > scaled_base_unit2; +typedef bu::scaled_base_unit<base_unit4, bu::scale<10, bu::static_rational<3> > > scaled_base_unit4; + +BOOST_UNITS_DEFINE_CONVERSION_FACTOR(base_unit1, scaled_base_unit2, double, 5); +BOOST_UNITS_DEFINE_CONVERSION_FACTOR(scaled_base_unit2, base_unit3, double, 3); + +int test_main(int,char *[]) +{ + BOOST_UNITS_CHECK_CLOSE(bu::conversion_factor(base_unit1::unit_type(), base_unit2::unit_type()), 5000); + BOOST_UNITS_CHECK_CLOSE(bu::conversion_factor(base_unit2::unit_type(), base_unit3::unit_type()), 0.003); + BOOST_UNITS_CHECK_CLOSE(bu::conversion_factor(scaled_base_unit2::unit_type(), base_unit2::unit_type()), 1000); + + BOOST_UNITS_CHECK_CLOSE(bu::conversion_factor(base_unit4::unit_type()/base_unit5::unit_type(), scaled_base_unit4::unit_type()/base_unit5::unit_type()), 1e-3); + + return(0); +} diff --git a/src/boost/libs/units/test/test_scaled_unit.cpp b/src/boost/libs/units/test/test_scaled_unit.cpp new file mode 100644 index 00000000..2357a98d --- /dev/null +++ b/src/boost/libs/units/test/test_scaled_unit.cpp @@ -0,0 +1,76 @@ +// Boost.Units - A C++ library for zero-overhead dimensional analysis and +// unit/quantity manipulation and conversion +// +// Copyright (C) 2003-2008 Matthias Christian Schabel +// Copyright (C) 2007-2008 Steven Watanabe +// +// Distributed under 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) + +/** +\file + +\brief test_scaled_conversion.cpp + +\details +Test unit scaling + +Output: +@verbatim +@endverbatim +**/ + +#define BOOST_TEST_MAIN + +#include <boost/units/systems/si/prefixes.hpp> +#include <boost/units/systems/si/time.hpp> +#include <boost/units/quantity.hpp> +#include <boost/units/io.hpp> + +#include <sstream> + +#include <boost/test/unit_test.hpp> +#include <boost/test/floating_point_comparison.hpp> + +namespace bu = boost::units; +namespace si = boost::units::si; + +BOOST_AUTO_TEST_CASE(test_scaled_to_plain) { + BOOST_CONSTEXPR_OR_CONST bu::quantity<si::time> s1 = 12.5 * si::seconds; + BOOST_CONSTEXPR_OR_CONST bu::quantity<si::time> s2(si::nano * s1); + BOOST_CHECK_CLOSE_FRACTION(1e-9 * s1.value(), s2.value(), 0.000000001); +} + +BOOST_AUTO_TEST_CASE(test_plain_to_scaled) { + BOOST_CONSTEXPR_OR_CONST bu::quantity<si::time> s1 = 12.5 * si::seconds; + typedef bu::multiply_typeof_helper<si::nano_type, si::time>::type time_unit; + BOOST_CONSTEXPR_OR_CONST bu::quantity<time_unit> s2(s1); + BOOST_CHECK_CLOSE_FRACTION(1e9 * s1.value(), s2.value(), 0.000000001); +} + +BOOST_AUTO_TEST_CASE(test_scaled_to_scaled) { + typedef bu::multiply_typeof_helper<si::mega_type, si::time>::type mega_time_unit; + typedef bu::multiply_typeof_helper<si::micro_type, si::time>::type micro_time_unit; + BOOST_CONSTEXPR_OR_CONST bu::quantity<mega_time_unit> s1(12.5 * si::seconds); + BOOST_CONSTEXPR_OR_CONST bu::quantity<micro_time_unit> s2(s1); + BOOST_CHECK_CLOSE_FRACTION(1e12 * s1.value(), s2.value(), 0.000000001); +} + +BOOST_AUTO_TEST_CASE(test_conversion_factor) { + BOOST_CHECK_CLOSE_FRACTION(conversion_factor(si::nano*si::seconds, si::seconds), 1e-9, 0.000000001); + BOOST_CHECK_CLOSE_FRACTION(conversion_factor(si::seconds, si::nano*si::seconds), 1e9, 0.000000001); + BOOST_CHECK_CLOSE_FRACTION(conversion_factor(si::mega*si::seconds, si::micro*si::seconds), 1e12, 0.000000001); +} + +BOOST_AUTO_TEST_CASE(test_output) { + std::stringstream stream; + stream << si::nano * 12.5 * si::seconds; + BOOST_CHECK_EQUAL(stream.str(), "12.5 ns"); +} + +BOOST_AUTO_TEST_CASE(test_output_name) { + std::stringstream stream; + stream << bu::name_format << si::nano * 12.5 * si::seconds; + BOOST_CHECK_EQUAL(stream.str(), "12.5 nanosecond"); +} diff --git a/src/boost/libs/units/test/test_sqrt_scaled_unit.cpp b/src/boost/libs/units/test/test_sqrt_scaled_unit.cpp new file mode 100644 index 00000000..8224fa25 --- /dev/null +++ b/src/boost/libs/units/test/test_sqrt_scaled_unit.cpp @@ -0,0 +1,48 @@ +// Boost.Units - A C++ library for zero-overhead dimensional analysis and +// unit/quantity manipulation and conversion +// +// Copyright (C) 2003-2008 Matthias Christian Schabel +// Copyright (C) 2008 Steven Watanabe +// +// Distributed under 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) + +/** +\file + +\brief test_units_1.cpp + +\details +Test unit class. + +Output: +@verbatim +@endverbatim +**/ + +#include "test_header.hpp" + +#include <boost/units/cmath.hpp> +#include <boost/units/scale.hpp> +#include <boost/units/make_scaled_unit.hpp> + +namespace bu = boost::units; + +static const double E_ = 2.718281828459045235360287471352662497757; + +typedef bu::make_scaled_unit<bu::length, + bu::scale<10, bu::static_rational<-3> > >::type milli_meter_unit; + +typedef bu::make_scaled_unit<bu::area, + bu::scale<10, bu::static_rational<-6> > >::type micro_meter2_unit; + +int test_main(int,char *[]) +{ + const bu::quantity<micro_meter2_unit> E1 = E_*micro_meter2_unit(); + const bu::quantity<milli_meter_unit> E2 = sqrt(E1); + + BOOST_CHECK(E1.value() == E_); + BOOST_CHECK(E2.value() == sqrt(E_)); + return 0; +} diff --git a/src/boost/libs/units/test/test_trig.cpp b/src/boost/libs/units/test/test_trig.cpp new file mode 100644 index 00000000..574c460a --- /dev/null +++ b/src/boost/libs/units/test/test_trig.cpp @@ -0,0 +1,79 @@ +// Boost.Units - A C++ library for zero-overhead dimensional analysis and +// unit/quantity manipulation and conversion +// +// Copyright (C) 2009 Steven Watanabe +// +// Distributed under 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) + +/** +\file + +\brief test_trig.cpp + +\details +Test trigonometric functions. + +Output: +@verbatim +@endverbatim +**/ + +#include <cmath> +#include <boost/units/cmath.hpp> +#include <boost/units/io.hpp> +#include <boost/units/systems/si/plane_angle.hpp> +#include <boost/units/systems/si/length.hpp> +#include <boost/units/systems/si/dimensionless.hpp> +#include <boost/units/systems/angle/degrees.hpp> + +#define BOOST_TEST_MAIN +#include <boost/test/unit_test.hpp> + +using boost::units::si::radians; +using boost::units::si::si_dimensionless; +using boost::units::degree::degrees; +BOOST_UNITS_STATIC_CONSTANT(degree_dimensionless, boost::units::degree::dimensionless); +using boost::units::si::meters; +BOOST_UNITS_STATIC_CONSTANT(heterogeneous_dimensionless, boost::units::reduce_unit<boost::units::si::dimensionless>::type); + +BOOST_AUTO_TEST_CASE(test_sin) { + BOOST_CHECK_EQUAL(boost::units::sin(2.0 * radians), std::sin(2.0) * si_dimensionless); + BOOST_CHECK_CLOSE_FRACTION(static_cast<double>(boost::units::sin(15.0 * degrees)), 0.2588, 0.0004); +} + +BOOST_AUTO_TEST_CASE(test_cos) { + BOOST_CHECK_EQUAL(boost::units::cos(2.0 * radians), std::cos(2.0) * si_dimensionless); + BOOST_CHECK_CLOSE_FRACTION(static_cast<double>(boost::units::cos(75.0 * degrees)), 0.2588, 0.0004); +} + +BOOST_AUTO_TEST_CASE(test_tan) { + BOOST_CHECK_EQUAL(boost::units::tan(2.0 * radians), std::tan(2.0) * si_dimensionless); + BOOST_CHECK_CLOSE_FRACTION(static_cast<double>(boost::units::tan(45.0 * degrees)), 1.0, 0.0001); +} + +BOOST_AUTO_TEST_CASE(test_asin) { + BOOST_CHECK_EQUAL(boost::units::asin(0.2 * si_dimensionless), std::asin(0.2) * radians); + BOOST_CHECK_CLOSE_FRACTION(boost::units::asin(0.5 * degree_dimensionless).value(), 30.0, 0.0001); + BOOST_CHECK_EQUAL(boost::units::asin(0.2 * heterogeneous_dimensionless).value(), std::asin(0.2)); +} + +BOOST_AUTO_TEST_CASE(test_acos) { + BOOST_CHECK_EQUAL(boost::units::acos(0.2 * si_dimensionless), std::acos(0.2) * radians); + BOOST_CHECK_CLOSE_FRACTION(boost::units::acos(0.5 * degree_dimensionless).value(), 60.0, 0.0001); + BOOST_CHECK_EQUAL(boost::units::acos(0.2 * heterogeneous_dimensionless).value(), std::acos(0.2)); +} + +BOOST_AUTO_TEST_CASE(test_atan) { + BOOST_CHECK_EQUAL(boost::units::atan(0.2 * si_dimensionless), std::atan(0.2) * radians); + BOOST_CHECK_CLOSE_FRACTION(boost::units::atan(1.0 * degree_dimensionless).value(), 45.0, 0.0001); + BOOST_CHECK_EQUAL(boost::units::atan(0.2 * heterogeneous_dimensionless).value(), std::atan(0.2)); +} + +BOOST_AUTO_TEST_CASE(test_atan2) { + BOOST_CHECK_EQUAL(boost::units::atan2(0.2 * si_dimensionless, 0.3 * si_dimensionless), std::atan2(0.2, 0.3) * radians); + BOOST_CHECK_EQUAL(boost::units::atan2(0.2 * meters, 0.3 * meters), std::atan2(0.2, 0.3) * radians); + BOOST_CHECK_CLOSE_FRACTION(boost::units::atan2(0.8660*degree_dimensionless,0.5*degree_dimensionless).value(), 60., 0.0002); + BOOST_CHECK_EQUAL(boost::units::atan2(0.2 * heterogeneous_dimensionless, 0.3 * heterogeneous_dimensionless).value(), std::atan2(0.2, 0.3)); +} diff --git a/src/boost/libs/units/test/test_unit.cpp b/src/boost/libs/units/test/test_unit.cpp new file mode 100644 index 00000000..ed80430f --- /dev/null +++ b/src/boost/libs/units/test/test_unit.cpp @@ -0,0 +1,67 @@ +// Boost.Units - A C++ library for zero-overhead dimensional analysis and +// unit/quantity manipulation and conversion +// +// Copyright (C) 2003-2008 Matthias Christian Schabel +// Copyright (C) 2008 Steven Watanabe +// +// Distributed under 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) + +/** +\file + +\brief test_units_1.cpp + +\details +Test unit class. + +Output: +@verbatim +@endverbatim +**/ + +#include "test_header.hpp" + +#include <boost/units/pow.hpp> + +namespace bu = boost::units; + +int test_main(int,char *[]) +{ + BOOST_CONSTEXPR_OR_CONST bu::dimensionless D; + + BOOST_CONSTEXPR_OR_CONST bu::length L; + BOOST_CONSTEXPR_OR_CONST bu::mass M; + BOOST_CONSTEXPR_OR_CONST bu::time T; + + BOOST_CHECK(+L == L); + BOOST_CHECK(-L == L); + BOOST_CHECK(L+L == L); + BOOST_CHECK(L-L == L); + + BOOST_CHECK(+M == M); + BOOST_CHECK(-M == M); + BOOST_CHECK(M+M == M); + BOOST_CHECK(M-M == M); + + BOOST_CONSTEXPR_OR_CONST bu::area A; + BOOST_CONSTEXPR_OR_CONST bu::energy E; + BOOST_CONSTEXPR_OR_CONST bu::velocity V; + + BOOST_CHECK(L*L == A); + BOOST_CHECK(A == L*L); + + BOOST_CHECK(L/L == D); + BOOST_CHECK(D == L/L); + + BOOST_CHECK(L/T == V); + BOOST_CHECK(V == L/T); + + BOOST_CHECK(M*L*L/T/T == E); + BOOST_CHECK(M*(L/T)*(L/T) == E); + BOOST_CHECK(M*bu::pow<2>(L/T) == E); + BOOST_CHECK(bu::root<2>(E/M) == V); + + return 0; +} diff --git a/src/boost/libs/units/test/test_unscale.cpp b/src/boost/libs/units/test/test_unscale.cpp new file mode 100644 index 00000000..d81a144d --- /dev/null +++ b/src/boost/libs/units/test/test_unscale.cpp @@ -0,0 +1,58 @@ +// Boost.Units - A C++ library for zero-overhead dimensional analysis and +// unit/quantity manipulation and conversion +// +// Copyright (C) 2003-2008 Matthias Christian Schabel +// Copyright (C) 2007-2008 Steven Watanabe +// +// Distributed under 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) + +/** +\file + +\brief test_unscale.cpp + +\details +Test that unscale works in an attempt to isolate the sun problems. + +Output: +@verbatim +@endverbatim +**/ + +#include <boost/units/reduce_unit.hpp> +#include <boost/units/detail/unscale.hpp> +#include <boost/units/base_units/temperature/fahrenheit.hpp> + +#include <boost/mpl/assert.hpp> +#include <boost/type_traits/is_same.hpp> + +BOOST_MPL_ASSERT((boost::is_same<boost::units::unscale<boost::units::temperature::fahrenheit_base_unit::unit_type::system_type>::type, + boost::units::temperature::fahrenheit_base_unit::unit_type::system_type>)); + +BOOST_MPL_ASSERT((boost::is_same<boost::units::unscale<boost::units::temperature::fahrenheit_base_unit::unit_type>::type, + boost::units::temperature::fahrenheit_base_unit::unit_type>)); + +BOOST_MPL_ASSERT((boost::is_same<boost::units::unscale<boost::units::reduce_unit<boost::units::temperature::fahrenheit_base_unit::unit_type>::type>::type, + boost::units::temperature::fahrenheit_base_unit::unit_type>)); + +BOOST_MPL_ASSERT((boost::is_same< + boost::units::temperature::fahrenheit_base_unit::unit_type, + boost::units::unit< + boost::units::temperature_dimension, + boost::units::heterogeneous_system< + boost::units::heterogeneous_system_impl< + boost::units::list< + boost::units::heterogeneous_system_dim< + boost::units::temperature::fahrenheit_base_unit, + boost::units::static_rational<1> + >, + boost::units::dimensionless_type + >, + boost::units::temperature_dimension, + boost::units::dimensionless_type + > + > + > +>)); |