File: test_constants.cpp

package info (click to toggle)
boost1.42 1.42.0-4
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 277,864 kB
  • ctags: 401,076
  • sloc: cpp: 1,235,659; xml: 74,142; ansic: 41,313; python: 26,756; sh: 11,840; cs: 2,118; makefile: 655; perl: 494; yacc: 456; asm: 353; csh: 6
file content (74 lines) | stat: -rw-r--r-- 2,517 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// 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

\detailed
Test all combinations of operators with the constants.

**/

#include <boost/units/systems/detail/constants.hpp>
#include <boost/units/quantity.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;

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);
}