test_unit.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Boost.Units - A C++ library for zero-overhead dimensional analysis and
  2. // unit/quantity manipulation and conversion
  3. //
  4. // Copyright (C) 2003-2008 Matthias Christian Schabel
  5. // Copyright (C) 2008 Steven Watanabe
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See
  8. // accompanying file LICENSE_1_0.txt or copy at
  9. // http://www.boost.org/LICENSE_1_0.txt)
  10. /**
  11. \file
  12. \brief test_units_1.cpp
  13. \details
  14. Test unit class.
  15. Output:
  16. @verbatim
  17. @endverbatim
  18. **/
  19. #include "test_header.hpp"
  20. #include <boost/units/pow.hpp>
  21. namespace bu = boost::units;
  22. int test_main(int,char *[])
  23. {
  24. BOOST_CONSTEXPR_OR_CONST bu::dimensionless D;
  25. BOOST_CONSTEXPR_OR_CONST bu::length L;
  26. BOOST_CONSTEXPR_OR_CONST bu::mass M;
  27. BOOST_CONSTEXPR_OR_CONST bu::time T;
  28. BOOST_CHECK(+L == L);
  29. BOOST_CHECK(-L == L);
  30. BOOST_CHECK(L+L == L);
  31. BOOST_CHECK(L-L == L);
  32. BOOST_CHECK(+M == M);
  33. BOOST_CHECK(-M == M);
  34. BOOST_CHECK(M+M == M);
  35. BOOST_CHECK(M-M == M);
  36. BOOST_CONSTEXPR_OR_CONST bu::area A;
  37. BOOST_CONSTEXPR_OR_CONST bu::energy E;
  38. BOOST_CONSTEXPR_OR_CONST bu::velocity V;
  39. BOOST_CHECK(L*L == A);
  40. BOOST_CHECK(A == L*L);
  41. BOOST_CHECK(L/L == D);
  42. BOOST_CHECK(D == L/L);
  43. BOOST_CHECK(L/T == V);
  44. BOOST_CHECK(V == L/T);
  45. BOOST_CHECK(M*L*L/T/T == E);
  46. BOOST_CHECK(M*(L/T)*(L/T) == E);
  47. BOOST_CHECK(M*bu::pow<2>(L/T) == E);
  48. BOOST_CHECK(bu::root<2>(E/M) == V);
  49. return 0;
  50. }