From 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 20:24:20 +0200 Subject: Adding upstream version 14.2.21. Signed-off-by: Daniel Baumann --- src/boost/libs/utility/test/operators_test.cpp | 936 +++++++++++++++++++++++++ 1 file changed, 936 insertions(+) create mode 100644 src/boost/libs/utility/test/operators_test.cpp (limited to 'src/boost/libs/utility/test/operators_test.cpp') diff --git a/src/boost/libs/utility/test/operators_test.cpp b/src/boost/libs/utility/test/operators_test.cpp new file mode 100644 index 00000000..6cf7a76c --- /dev/null +++ b/src/boost/libs/utility/test/operators_test.cpp @@ -0,0 +1,936 @@ +// Demonstrate and test boost/operators.hpp -------------------------------// + +// Copyright Beman Dawes 1999. 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) + +// See http://www.boost.org/libs/utility for documentation. + +// Revision History +// 03 Apr 08 Added convertible_to_bool (Daniel Frey) +// 01 Oct 01 Added tests for "left" operators +// and new grouped operators. (Helmut Zeisel) +// 20 May 01 Output progress messages. Added tests for new operator +// templates. Updated random number generator. Changed tests to +// use Boost Test Tools library. (Daryle Walker) +// 04 Jun 00 Added regression test for a bug I found (David Abrahams) +// 17 Jun 00 Fix for broken compilers (Aleksey Gurtovoy) +// ?? ??? 00 Major update to randomly test all one- and two- argument forms by +// wrapping integral types and comparing the results of operations +// to the results for the raw types (David Abrahams) +// 12 Dec 99 Minor update, output confirmation message. +// 15 Nov 99 Initial version + +#include // for BOOST_MSVC +#include // for the tested items +#include // for boost::detail::minstd_rand +#include + +#include // for std::cout (std::endl indirectly) + + +namespace +{ + // avoiding a template version of true_value so as to not confuse VC++ + int true_value(int x) { return x; } + long true_value(long x) { return x; } + signed char true_value(signed char x) { return x; } + unsigned int true_value(unsigned int x) { return x; } + unsigned long true_value(unsigned long x) { return x; } + unsigned char true_value(unsigned char x) { return x; } + + // verify the minimum requirements for some operators + class convertible_to_bool + { + private: + bool _value; + + typedef bool convertible_to_bool::*unspecified_bool_type; + + void operator!() const; + + public: + convertible_to_bool( const bool value ) : _value( value ) {} + + operator unspecified_bool_type() const + { return _value ? &convertible_to_bool::_value : 0; } + }; + + // The use of operators<> here tended to obscure + // interactions with certain compiler bugs + template + class Wrapped1 + : boost::operators > + , boost::shiftable > + { + public: + explicit Wrapped1( T v = T() ) : _value(v) {} + T value() const { return _value; } + + convertible_to_bool operator<(const Wrapped1& x) const + { return _value < x._value; } + convertible_to_bool operator==(const Wrapped1& x) const + { return _value == x._value; } + + Wrapped1& operator+=(const Wrapped1& x) + { _value += x._value; return *this; } + Wrapped1& operator-=(const Wrapped1& x) + { _value -= x._value; return *this; } + Wrapped1& operator*=(const Wrapped1& x) + { _value *= x._value; return *this; } + Wrapped1& operator/=(const Wrapped1& x) + { _value /= x._value; return *this; } + Wrapped1& operator%=(const Wrapped1& x) + { _value %= x._value; return *this; } + Wrapped1& operator|=(const Wrapped1& x) + { _value |= x._value; return *this; } + Wrapped1& operator&=(const Wrapped1& x) + { _value &= x._value; return *this; } + Wrapped1& operator^=(const Wrapped1& x) + { _value ^= x._value; return *this; } + Wrapped1& operator<<=(const Wrapped1& x) + { _value <<= x._value; return *this; } + Wrapped1& operator>>=(const Wrapped1& x) + { _value >>= x._value; return *this; } + Wrapped1& operator++() { ++_value; return *this; } + Wrapped1& operator--() { --_value; return *this; } + + private: + T _value; + }; + template + T true_value(Wrapped1 x) { return x.value(); } + + template + class Wrapped2 + : boost::operators > + , boost::operators2, U> + , boost::shiftable1 + , boost::shiftable2, U > > + { + public: + explicit Wrapped2( T v = T() ) : _value(v) {} + T value() const { return _value; } + + convertible_to_bool operator<(const Wrapped2& x) const + { return _value < x._value; } + convertible_to_bool operator==(const Wrapped2& x) const + { return _value == x._value; } + + Wrapped2& operator+=(const Wrapped2& x) + { _value += x._value; return *this; } + Wrapped2& operator-=(const Wrapped2& x) + { _value -= x._value; return *this; } + Wrapped2& operator*=(const Wrapped2& x) + { _value *= x._value; return *this; } + Wrapped2& operator/=(const Wrapped2& x) + { _value /= x._value; return *this; } + Wrapped2& operator%=(const Wrapped2& x) + { _value %= x._value; return *this; } + Wrapped2& operator|=(const Wrapped2& x) + { _value |= x._value; return *this; } + Wrapped2& operator&=(const Wrapped2& x) + { _value &= x._value; return *this; } + Wrapped2& operator^=(const Wrapped2& x) + { _value ^= x._value; return *this; } + Wrapped2& operator<<=(const Wrapped2& x) + { _value <<= x._value; return *this; } + Wrapped2& operator>>=(const Wrapped2& x) + { _value >>= x._value; return *this; } + Wrapped2& operator++() { ++_value; return *this; } + Wrapped2& operator--() { --_value; return *this; } + + convertible_to_bool operator<(U u) const + { return _value < u; } + convertible_to_bool operator>(U u) const + { return _value > u; } + convertible_to_bool operator==(U u) const + { return _value == u; } + + Wrapped2& operator+=(U u) { _value += u; return *this; } + Wrapped2& operator-=(U u) { _value -= u; return *this; } + Wrapped2& operator*=(U u) { _value *= u; return *this; } + Wrapped2& operator/=(U u) { _value /= u; return *this; } + Wrapped2& operator%=(U u) { _value %= u; return *this; } + Wrapped2& operator|=(U u) { _value |= u; return *this; } + Wrapped2& operator&=(U u) { _value &= u; return *this; } + Wrapped2& operator^=(U u) { _value ^= u; return *this; } + Wrapped2& operator<<=(U u) { _value <<= u; return *this; } + Wrapped2& operator>>=(U u) { _value >>= u; return *this; } + + private: + T _value; + }; + template + T true_value(Wrapped2 x) { return x.value(); } + + template + class Wrapped3 + : boost::equivalent > + , boost::partially_ordered > + , boost::equality_comparable > + { + public: + explicit Wrapped3( T v = T() ) : _value(v) {} + T value() const { return _value; } + + convertible_to_bool operator<(const Wrapped3& x) const + { return _value < x._value; } + + private: + T _value; + }; + template + T true_value(Wrapped3 x) { return x.value(); } + + template + class Wrapped4 + : boost::equality_comparable1 + , boost::equivalent1 + , boost::partially_ordered1 > > > + , boost::partially_ordered2, U + , boost::equivalent2, U + , boost::equality_comparable2, U> > > + { + public: + explicit Wrapped4( T v = T() ) : _value(v) {} + T value() const { return _value; } + + convertible_to_bool operator<(const Wrapped4& x) const + { return _value < x._value; } + + convertible_to_bool operator<(U u) const + { return _value < u; } + convertible_to_bool operator>(U u) const + { return _value > u; } + + private: + T _value; + }; + template + T true_value(Wrapped4 x) { return x.value(); } + + // U must be convertible to T + template + class Wrapped5 + : boost::ordered_field_operators2, U> + , boost::ordered_field_operators1 > + { + public: + explicit Wrapped5( T v = T() ) : _value(v) {} + + // Conversion from U to Wrapped5 + Wrapped5(U u) : _value(u) {} + + T value() const { return _value; } + + convertible_to_bool operator<(const Wrapped5& x) const + { return _value < x._value; } + convertible_to_bool operator<(U u) const + { return _value < u; } + convertible_to_bool operator>(U u) const + { return _value > u; } + convertible_to_bool operator==(const Wrapped5& u) const + { return _value == u._value; } + convertible_to_bool operator==(U u) const + { return _value == u; } + + Wrapped5& operator/=(const Wrapped5& u) { _value /= u._value; return *this;} + Wrapped5& operator/=(U u) { _value /= u; return *this;} + Wrapped5& operator*=(const Wrapped5& u) { _value *= u._value; return *this;} + Wrapped5& operator*=(U u) { _value *= u; return *this;} + Wrapped5& operator-=(const Wrapped5& u) { _value -= u._value; return *this;} + Wrapped5& operator-=(U u) { _value -= u; return *this;} + Wrapped5& operator+=(const Wrapped5& u) { _value += u._value; return *this;} + Wrapped5& operator+=(U u) { _value += u; return *this;} + + private: + T _value; + }; + template + T true_value(Wrapped5 x) { return x.value(); } + + // U must be convertible to T + template + class Wrapped6 + : boost::ordered_euclidean_ring_operators2, U> + , boost::ordered_euclidean_ring_operators1 > + { + public: + explicit Wrapped6( T v = T() ) : _value(v) {} + + // Conversion from U to Wrapped6 + Wrapped6(U u) : _value(u) {} + + T value() const { return _value; } + + convertible_to_bool operator<(const Wrapped6& x) const + { return _value < x._value; } + convertible_to_bool operator<(U u) const + { return _value < u; } + convertible_to_bool operator>(U u) const + { return _value > u; } + convertible_to_bool operator==(const Wrapped6& u) const + { return _value == u._value; } + convertible_to_bool operator==(U u) const + { return _value == u; } + + Wrapped6& operator%=(const Wrapped6& u) { _value %= u._value; return *this;} + Wrapped6& operator%=(U u) { _value %= u; return *this;} + Wrapped6& operator/=(const Wrapped6& u) { _value /= u._value; return *this;} + Wrapped6& operator/=(U u) { _value /= u; return *this;} + Wrapped6& operator*=(const Wrapped6& u) { _value *= u._value; return *this;} + Wrapped6& operator*=(U u) { _value *= u; return *this;} + Wrapped6& operator-=(const Wrapped6& u) { _value -= u._value; return *this;} + Wrapped6& operator-=(U u) { _value -= u; return *this;} + Wrapped6& operator+=(const Wrapped6& u) { _value += u._value; return *this;} + Wrapped6& operator+=(U u) { _value += u; return *this;} + + private: + T _value; + }; + template + T true_value(Wrapped6 x) { return x.value(); } + + // MyInt uses only the single template-argument form of all_operators<> + typedef Wrapped1 MyInt; + + typedef Wrapped2 MyLong; + + typedef Wrapped3 MyChar; + + typedef Wrapped4 MyShort; + + typedef Wrapped5 MyDoubleInt; + + typedef Wrapped6 MyLongInt; + + template + void sanity_check(X1 x1, Y1 y1, X2 x2, Y2 y2) + { + BOOST_TEST( true_value(y1) == true_value(y2) ); + BOOST_TEST( true_value(x1) == true_value(x2) ); + } + + template + void test_less_than_comparable_aux(X1 x1, Y1 y1, X2 x2, Y2 y2) + { + BOOST_TEST( static_cast(x1 < y1) == static_cast(x2 < y2) ); + BOOST_TEST( static_cast(x1 <= y1) == static_cast(x2 <= y2) ); + BOOST_TEST( static_cast(x1 >= y1) == static_cast(x2 >= y2) ); + BOOST_TEST( static_cast(x1 > y1) == static_cast(x2 > y2) ); + } + + template + void test_less_than_comparable(X1 x1, Y1 y1, X2 x2, Y2 y2) + { + sanity_check( x1, y1, x2, y2 ); + test_less_than_comparable_aux( x1, y1, x2, y2 ); + test_less_than_comparable_aux( y1, x1, y2, x2 ); + } + + template + void test_equality_comparable_aux(X1 x1, Y1 y1, X2 x2, Y2 y2) + { + BOOST_TEST( static_cast(x1 == y1) == static_cast(x2 == y2) ); + BOOST_TEST( static_cast(x1 != y1) == static_cast(x2 != y2) ); + } + + template + void test_equality_comparable(X1 x1, Y1 y1, X2 x2, Y2 y2) + { + sanity_check( x1, y1, x2, y2 ); + test_equality_comparable_aux( x1, y1, x2, y2 ); + test_equality_comparable_aux( y1, x1, y2, x2 ); + } + + template + void test_multipliable_aux(X1 x1, Y1 y1, X2 x2, Y2 y2) + { + BOOST_TEST( (x1 * y1).value() == (x2 * y2) ); + } + + template + void test_multipliable(X1 x1, Y1 y1, X2 x2, Y2 y2) + { + sanity_check( x1, y1, x2, y2 ); + test_multipliable_aux( x1, y1, x2, y2 ); + test_multipliable_aux( y1, x1, y2, x2 ); + } + + template + void test_value_equality(A a, B b) + { + BOOST_TEST(a.value() == b); + } + +#define TEST_OP_R(op) test_value_equality(x1 op y1, x2 op y2) +#define TEST_OP_L(op) test_value_equality(y1 op x1, y2 op x2) + + template + void test_addable_aux(X1 x1, Y1 y1, X2 x2, Y2 y2) + { + TEST_OP_R(+); + } + + template + void test_addable(X1 x1, Y1 y1, X2 x2, Y2 y2) + { + sanity_check( x1, y1, x2, y2 ); + test_addable_aux( x1, y1, x2, y2 ); + test_addable_aux( y1, x1, y2, x2 ); + } + + template + void test_subtractable(X1 x1, Y1 y1, X2 x2, Y2 y2) + { + sanity_check( x1, y1, x2, y2 ); + TEST_OP_R(-); + } + + template + void test_subtractable_left(X1 x1, Y1 y1, X2 x2, Y2 y2) + { + sanity_check( x1, y1, x2, y2 ); + TEST_OP_L(-); + } + + template + void test_dividable(X1 x1, Y1 y1, X2 x2, Y2 y2) + { + sanity_check( x1, y1, x2, y2 ); + if ( y2 != 0 ) + TEST_OP_R(/); + } + + template + void test_dividable_left(X1 x1, Y1 y1, X2 x2, Y2 y2) + { + sanity_check( x1, y1, x2, y2 ); + if ( x2 != 0 ) + TEST_OP_L(/); + } + + template + void test_modable(X1 x1, Y1 y1, X2 x2, Y2 y2) + { + sanity_check( x1, y1, x2, y2 ); + if ( y2 != 0 ) + TEST_OP_R(%); + } + + template + void test_modable_left(X1 x1, Y1 y1, X2 x2, Y2 y2) + { + sanity_check( x1, y1, x2, y2 ); + if ( x2 != 0 ) + TEST_OP_L(%); + } + + template + void test_xorable_aux(X1 x1, Y1 y1, X2 x2, Y2 y2) + { + TEST_OP_R(^); + } + + template + void test_xorable(X1 x1, Y1 y1, X2 x2, Y2 y2) + { + sanity_check( x1, y1, x2, y2 ); + test_xorable_aux( x1, y1, x2, y2 ); + test_xorable_aux( y1, x1, y2, x2 ); + } + + template + void test_andable_aux(X1 x1, Y1 y1, X2 x2, Y2 y2) + { + TEST_OP_R(&); + } + + template + void test_andable(X1 x1, Y1 y1, X2 x2, Y2 y2) + { + sanity_check( x1, y1, x2, y2 ); + test_andable_aux( x1, y1, x2, y2 ); + test_andable_aux( y1, x1, y2, x2 ); + } + + template + void test_orable_aux(X1 x1, Y1 y1, X2 x2, Y2 y2) + { + TEST_OP_R(|); + } + + template + void test_orable(X1 x1, Y1 y1, X2 x2, Y2 y2) + { + sanity_check( x1, y1, x2, y2 ); + test_orable_aux( x1, y1, x2, y2 ); + test_orable_aux( y1, x1, y2, x2 ); + } + + template + void test_left_shiftable(X1 x1, Y1 y1, X2 x2, Y2 y2) + { + sanity_check( x1, y1, x2, y2 ); + TEST_OP_R(<<); + } + + template + void test_right_shiftable(X1 x1, Y1 y1, X2 x2, Y2 y2) + { + sanity_check( x1, y1, x2, y2 ); + TEST_OP_R(>>); + } + + template + void test_incrementable(X1 x1, X2 x2) + { + sanity_check( x1, x1, x2, x2 ); + BOOST_TEST( (x1++).value() == x2++ ); + BOOST_TEST( x1.value() == x2 ); + } + + template + void test_decrementable(X1 x1, X2 x2) + { + sanity_check( x1, x1, x2, x2 ); + BOOST_TEST( (x1--).value() == x2-- ); + BOOST_TEST( x1.value() == x2 ); + } + + template + void test_all(X1 x1, Y1 y1, X2 x2, Y2 y2) + { + test_less_than_comparable( x1, y1, x2, y2 ); + test_equality_comparable( x1, y1, x2, y2 ); + test_multipliable( x1, y1, x2, y2 ); + test_addable( x1, y1, x2, y2 ); + test_subtractable( x1, y1, x2, y2 ); + test_dividable( x1, y1, x2, y2 ); + test_modable( x1, y1, x2, y2 ); + test_xorable( x1, y1, x2, y2 ); + test_andable( x1, y1, x2, y2 ); + test_orable( x1, y1, x2, y2 ); + test_left_shiftable( x1, y1, x2, y2 ); + test_right_shiftable( x1, y1, x2, y2 ); + test_incrementable( x1, x2 ); + test_decrementable( x1, x2 ); + } + + template + void test_left(X1 x1, Y1 y1, X2 x2, Y2 y2) + { + test_subtractable_left( x1, y1, x2, y2 ); + test_dividable_left( x1, y1, x2, y2 ); + test_modable_left( x1, y1, x2, y2 ); + } + + template + struct tester + { + void operator()(boost::detail::minstd_rand& randomizer) const + { + Big b1 = Big( randomizer() ); + Big b2 = Big( randomizer() ); + Small s = Small( randomizer() ); + + test_all( Wrapped1(b1), Wrapped1(b2), b1, b2 ); + test_all( Wrapped2(b1), s, b1, s ); + } + }; + + template + struct tester_left + { + void operator()(boost::detail::minstd_rand& randomizer) const + { + Big b1 = Big( randomizer() ); + Small s = Small( randomizer() ); + + test_left( Wrapped6(b1), s, b1, s ); + } + }; + + // added as a regression test. We had a bug which this uncovered. + struct Point + : boost::addable > + { + Point( int h, int v ) : h(h), v(v) {} + Point() :h(0), v(0) {} + const Point& operator+=( const Point& rhs ) + { h += rhs.h; v += rhs.v; return *this; } + const Point& operator-=( const Point& rhs ) + { h -= rhs.h; v -= rhs.v; return *this; } + + int h; + int v; + }; + +} // unnamed namespace + + +// workaround for MSVC bug; for some reasons the compiler doesn't instantiate +// inherited operator templates at the moment it must, so the following +// explicit instantiations force it to do that. + +#if defined(BOOST_MSVC) && (_MSC_VER < 1300) +template Wrapped1; +template Wrapped1; +template Wrapped1; +template Wrapped1; + +template Wrapped2; +template Wrapped2; +template Wrapped2; +template Wrapped2; +template Wrapped2; +template Wrapped2; +template Wrapped2; +template Wrapped2; +template Wrapped2; +template Wrapped2; + +template Wrapped6; +template Wrapped6; +template Wrapped6; +template Wrapped6; +template Wrapped6; +template Wrapped6; +#endif + +#define PRIVATE_EXPR_TEST(e, t) BOOST_TEST( ((e), (t)) ) + +int +main() +{ + using std::cout; + using std::endl; + + // Regression test. + Point x; + x = x + Point(3, 4); + x = x - Point(3, 4); + + cout << "Created point, and operated on it." << endl; + + for (int n = 0; n < 1000; ++n) // was 10,000 but took too long (Beman) + { + boost::detail::minstd_rand r; + tester()(r); + tester()(r); + tester()(r); + tester()(r); + tester()(r); + + tester()(r); + tester()(r); + tester()(r); + tester()(r); + tester()(r); + + tester_left()(r); + tester_left()(r); + tester_left()(r); + + tester_left()(r); + tester_left()(r); + tester_left()(r); + } + + cout << "Did random tester loop." << endl; + + MyInt i1(1); + MyInt i2(2); + MyInt i; + + BOOST_TEST( i1.value() == 1 ); + BOOST_TEST( i2.value() == 2 ); + BOOST_TEST( i.value() == 0 ); + + cout << "Created MyInt objects.\n"; + + PRIVATE_EXPR_TEST( (i = i2), (i.value() == 2) ); + + BOOST_TEST( static_cast(i2 == i) ); + BOOST_TEST( static_cast(i1 != i2) ); + BOOST_TEST( static_cast(i1 < i2) ); + BOOST_TEST( static_cast(i1 <= i2) ); + BOOST_TEST( static_cast(i <= i2) ); + BOOST_TEST( static_cast(i2 > i1) ); + BOOST_TEST( static_cast(i2 >= i1) ); + BOOST_TEST( static_cast(i2 >= i) ); + + PRIVATE_EXPR_TEST( (i = i1 + i2), (i.value() == 3) ); + PRIVATE_EXPR_TEST( (i = i + i2), (i.value() == 5) ); + PRIVATE_EXPR_TEST( (i = i - i1), (i.value() == 4) ); + PRIVATE_EXPR_TEST( (i = i * i2), (i.value() == 8) ); + PRIVATE_EXPR_TEST( (i = i / i2), (i.value() == 4) ); + PRIVATE_EXPR_TEST( (i = i % ( i - i1 )), (i.value() == 1) ); + PRIVATE_EXPR_TEST( (i = i2 + i2), (i.value() == 4) ); + PRIVATE_EXPR_TEST( (i = i1 | i2 | i), (i.value() == 7) ); + PRIVATE_EXPR_TEST( (i = i & i2), (i.value() == 2) ); + PRIVATE_EXPR_TEST( (i = i + i1), (i.value() == 3) ); + PRIVATE_EXPR_TEST( (i = i ^ i1), (i.value() == 2) ); + PRIVATE_EXPR_TEST( (i = ( i + i1 ) * ( i2 | i1 )), (i.value() == 9) ); + + PRIVATE_EXPR_TEST( (i = i1 << i2), (i.value() == 4) ); + PRIVATE_EXPR_TEST( (i = i2 >> i1), (i.value() == 1) ); + + cout << "Performed tests on MyInt objects.\n"; + + MyLong j1(1); + MyLong j2(2); + MyLong j; + + BOOST_TEST( j1.value() == 1 ); + BOOST_TEST( j2.value() == 2 ); + BOOST_TEST( j.value() == 0 ); + + cout << "Created MyLong objects.\n"; + + PRIVATE_EXPR_TEST( (j = j2), (j.value() == 2) ); + + BOOST_TEST( static_cast(j2 == j) ); + BOOST_TEST( static_cast(2 == j) ); + BOOST_TEST( static_cast(j2 == 2) ); + BOOST_TEST( static_cast(j == j2) ); + BOOST_TEST( static_cast(j1 != j2) ); + BOOST_TEST( static_cast(j1 != 2) ); + BOOST_TEST( static_cast(1 != j2) ); + BOOST_TEST( static_cast(j1 < j2) ); + BOOST_TEST( static_cast(1 < j2) ); + BOOST_TEST( static_cast(j1 < 2) ); + BOOST_TEST( static_cast(j1 <= j2) ); + BOOST_TEST( static_cast(1 <= j2) ); + BOOST_TEST( static_cast(j1 <= j) ); + BOOST_TEST( static_cast(j <= j2) ); + BOOST_TEST( static_cast(2 <= j2) ); + BOOST_TEST( static_cast(j <= 2) ); + BOOST_TEST( static_cast(j2 > j1) ); + BOOST_TEST( static_cast(2 > j1) ); + BOOST_TEST( static_cast(j2 > 1) ); + BOOST_TEST( static_cast(j2 >= j1) ); + BOOST_TEST( static_cast(2 >= j1) ); + BOOST_TEST( static_cast(j2 >= 1) ); + BOOST_TEST( static_cast(j2 >= j) ); + BOOST_TEST( static_cast(2 >= j) ); + BOOST_TEST( static_cast(j2 >= 2) ); + + BOOST_TEST( static_cast((j1 + 2) == 3) ); + BOOST_TEST( static_cast((1 + j2) == 3) ); + PRIVATE_EXPR_TEST( (j = j1 + j2), (j.value() == 3) ); + + BOOST_TEST( static_cast((j + 2) == 5) ); + BOOST_TEST( static_cast((3 + j2) == 5) ); + PRIVATE_EXPR_TEST( (j = j + j2), (j.value() == 5) ); + + BOOST_TEST( static_cast((j - 1) == 4) ); + PRIVATE_EXPR_TEST( (j = j - j1), (j.value() == 4) ); + + BOOST_TEST( static_cast((j * 2) == 8) ); + BOOST_TEST( static_cast((4 * j2) == 8) ); + PRIVATE_EXPR_TEST( (j = j * j2), (j.value() == 8) ); + + BOOST_TEST( static_cast((j / 2) == 4) ); + PRIVATE_EXPR_TEST( (j = j / j2), (j.value() == 4) ); + + BOOST_TEST( static_cast((j % 3) == 1) ); + PRIVATE_EXPR_TEST( (j = j % ( j - j1 )), (j.value() == 1) ); + + PRIVATE_EXPR_TEST( (j = j2 + j2), (j.value() == 4) ); + + BOOST_TEST( static_cast((1 | j2 | j) == 7) ); + BOOST_TEST( static_cast((j1 | 2 | j) == 7) ); + BOOST_TEST( static_cast((j1 | j2 | 4) == 7) ); + PRIVATE_EXPR_TEST( (j = j1 | j2 | j), (j.value() == 7) ); + + BOOST_TEST( static_cast((7 & j2) == 2) ); + BOOST_TEST( static_cast((j & 2) == 2) ); + PRIVATE_EXPR_TEST( (j = j & j2), (j.value() == 2) ); + + PRIVATE_EXPR_TEST( (j = j | j1), (j.value() == 3) ); + + BOOST_TEST( static_cast((3 ^ j1) == 2) ); + BOOST_TEST( static_cast((j ^ 1) == 2) ); + PRIVATE_EXPR_TEST( (j = j ^ j1), (j.value() == 2) ); + + PRIVATE_EXPR_TEST( (j = ( j + j1 ) * ( j2 | j1 )), (j.value() == 9) ); + + BOOST_TEST( static_cast((j1 << 2) == 4) ); + BOOST_TEST( static_cast((j2 << 1) == 4) ); + PRIVATE_EXPR_TEST( (j = j1 << j2), (j.value() == 4) ); + + BOOST_TEST( static_cast((j >> 2) == 1) ); + BOOST_TEST( static_cast((j2 >> 1) == 1) ); + PRIVATE_EXPR_TEST( (j = j2 >> j1), (j.value() == 1) ); + + cout << "Performed tests on MyLong objects.\n"; + + MyChar k1(1); + MyChar k2(2); + MyChar k; + + BOOST_TEST( k1.value() == 1 ); + BOOST_TEST( k2.value() == 2 ); + BOOST_TEST( k.value() == 0 ); + + cout << "Created MyChar objects.\n"; + + PRIVATE_EXPR_TEST( (k = k2), (k.value() == 2) ); + + BOOST_TEST( static_cast(k2 == k) ); + BOOST_TEST( static_cast(k1 != k2) ); + BOOST_TEST( static_cast(k1 < k2) ); + BOOST_TEST( static_cast(k1 <= k2) ); + BOOST_TEST( static_cast(k <= k2) ); + BOOST_TEST( static_cast(k2 > k1) ); + BOOST_TEST( static_cast(k2 >= k1) ); + BOOST_TEST( static_cast(k2 >= k) ); + + cout << "Performed tests on MyChar objects.\n"; + + MyShort l1(1); + MyShort l2(2); + MyShort l; + + BOOST_TEST( l1.value() == 1 ); + BOOST_TEST( l2.value() == 2 ); + BOOST_TEST( l.value() == 0 ); + + cout << "Created MyShort objects.\n"; + + PRIVATE_EXPR_TEST( (l = l2), (l.value() == 2) ); + + BOOST_TEST( static_cast(l2 == l) ); + BOOST_TEST( static_cast(2 == l) ); + BOOST_TEST( static_cast(l2 == 2) ); + BOOST_TEST( static_cast(l == l2) ); + BOOST_TEST( static_cast(l1 != l2) ); + BOOST_TEST( static_cast(l1 != 2) ); + BOOST_TEST( static_cast(1 != l2) ); + BOOST_TEST( static_cast(l1 < l2) ); + BOOST_TEST( static_cast(1 < l2) ); + BOOST_TEST( static_cast(l1 < 2) ); + BOOST_TEST( static_cast(l1 <= l2) ); + BOOST_TEST( static_cast(1 <= l2) ); + BOOST_TEST( static_cast(l1 <= l) ); + BOOST_TEST( static_cast(l <= l2) ); + BOOST_TEST( static_cast(2 <= l2) ); + BOOST_TEST( static_cast(l <= 2) ); + BOOST_TEST( static_cast(l2 > l1) ); + BOOST_TEST( static_cast(2 > l1) ); + BOOST_TEST( static_cast(l2 > 1) ); + BOOST_TEST( static_cast(l2 >= l1) ); + BOOST_TEST( static_cast(2 >= l1) ); + BOOST_TEST( static_cast(l2 >= 1) ); + BOOST_TEST( static_cast(l2 >= l) ); + BOOST_TEST( static_cast(2 >= l) ); + BOOST_TEST( static_cast(l2 >= 2) ); + + cout << "Performed tests on MyShort objects.\n"; + + MyDoubleInt di1(1); + MyDoubleInt di2(2.); + MyDoubleInt half(0.5); + MyDoubleInt di; + MyDoubleInt tmp; + + BOOST_TEST( di1.value() == 1 ); + BOOST_TEST( di2.value() == 2 ); + BOOST_TEST( di2.value() == 2 ); + BOOST_TEST( di.value() == 0 ); + + cout << "Created MyDoubleInt objects.\n"; + + PRIVATE_EXPR_TEST( (di = di2), (di.value() == 2) ); + + BOOST_TEST( static_cast(di2 == di) ); + BOOST_TEST( static_cast(2 == di) ); + BOOST_TEST( static_cast(di == 2) ); + BOOST_TEST( static_cast(di1 < di2) ); + BOOST_TEST( static_cast(1 < di2) ); + BOOST_TEST( static_cast(di1 <= di2) ); + BOOST_TEST( static_cast(1 <= di2) ); + BOOST_TEST( static_cast(di2 > di1) ); + BOOST_TEST( static_cast(di2 > 1) ); + BOOST_TEST( static_cast(di2 >= di1) ); + BOOST_TEST( static_cast(di2 >= 1) ); + BOOST_TEST( static_cast(di1 / di2 == half) ); + BOOST_TEST( static_cast(di1 / 2 == half) ); + BOOST_TEST( static_cast(1 / di2 == half) ); + PRIVATE_EXPR_TEST( (tmp=di1), static_cast((tmp/=2) == half) ); + PRIVATE_EXPR_TEST( (tmp=di1), static_cast((tmp/=di2) == half) ); + BOOST_TEST( static_cast(di1 * di2 == di2) ); + BOOST_TEST( static_cast(di1 * 2 == di2) ); + BOOST_TEST( static_cast(1 * di2 == di2) ); + PRIVATE_EXPR_TEST( (tmp=di1), static_cast((tmp*=2) == di2) ); + PRIVATE_EXPR_TEST( (tmp=di1), static_cast((tmp*=di2) == di2) ); + BOOST_TEST( static_cast(di2 - di1 == di1) ); + BOOST_TEST( static_cast(di2 - 1 == di1) ); + BOOST_TEST( static_cast(2 - di1 == di1) ); + PRIVATE_EXPR_TEST( (tmp=di2), static_cast((tmp-=1) == di1) ); + PRIVATE_EXPR_TEST( (tmp=di2), static_cast((tmp-=di1) == di1) ); + BOOST_TEST( static_cast(di1 + di1 == di2) ); + BOOST_TEST( static_cast(di1 + 1 == di2) ); + BOOST_TEST( static_cast(1 + di1 == di2) ); + PRIVATE_EXPR_TEST( (tmp=di1), static_cast((tmp+=1) == di2) ); + PRIVATE_EXPR_TEST( (tmp=di1), static_cast((tmp+=di1) == di2) ); + + cout << "Performed tests on MyDoubleInt objects.\n"; + + MyLongInt li1(1); + MyLongInt li2(2); + MyLongInt li; + MyLongInt tmp2; + + BOOST_TEST( li1.value() == 1 ); + BOOST_TEST( li2.value() == 2 ); + BOOST_TEST( li.value() == 0 ); + + cout << "Created MyLongInt objects.\n"; + + PRIVATE_EXPR_TEST( (li = li2), (li.value() == 2) ); + + BOOST_TEST( static_cast(li2 == li) ); + BOOST_TEST( static_cast(2 == li) ); + BOOST_TEST( static_cast(li == 2) ); + BOOST_TEST( static_cast(li1 < li2) ); + BOOST_TEST( static_cast(1 < li2) ); + BOOST_TEST( static_cast(li1 <= li2) ); + BOOST_TEST( static_cast(1 <= li2) ); + BOOST_TEST( static_cast(li2 > li1) ); + BOOST_TEST( static_cast(li2 > 1) ); + BOOST_TEST( static_cast(li2 >= li1) ); + BOOST_TEST( static_cast(li2 >= 1) ); + BOOST_TEST( static_cast(li1 % li2 == li1) ); + BOOST_TEST( static_cast(li1 % 2 == li1) ); + BOOST_TEST( static_cast(1 % li2 == li1) ); + PRIVATE_EXPR_TEST( (tmp2=li1), static_cast((tmp2%=2) == li1) ); + PRIVATE_EXPR_TEST( (tmp2=li1), static_cast((tmp2%=li2) == li1) ); + BOOST_TEST( static_cast(li1 / li2 == 0) ); + BOOST_TEST( static_cast(li1 / 2 == 0) ); + BOOST_TEST( static_cast(1 / li2 == 0) ); + PRIVATE_EXPR_TEST( (tmp2=li1), static_cast((tmp2/=2) == 0) ); + PRIVATE_EXPR_TEST( (tmp2=li1), static_cast((tmp2/=li2) == 0) ); + BOOST_TEST( static_cast(li1 * li2 == li2) ); + BOOST_TEST( static_cast(li1 * 2 == li2) ); + BOOST_TEST( static_cast(1 * li2 == li2) ); + PRIVATE_EXPR_TEST( (tmp2=li1), static_cast((tmp2*=2) == li2) ); + PRIVATE_EXPR_TEST( (tmp2=li1), static_cast((tmp2*=li2) == li2) ); + BOOST_TEST( static_cast(li2 - li1 == li1) ); + BOOST_TEST( static_cast(li2 - 1 == li1) ); + BOOST_TEST( static_cast(2 - li1 == li1) ); + PRIVATE_EXPR_TEST( (tmp2=li2), static_cast((tmp2-=1) == li1) ); + PRIVATE_EXPR_TEST( (tmp2=li2), static_cast((tmp2-=li1) == li1) ); + BOOST_TEST( static_cast(li1 + li1 == li2) ); + BOOST_TEST( static_cast(li1 + 1 == li2) ); + BOOST_TEST( static_cast(1 + li1 == li2) ); + PRIVATE_EXPR_TEST( (tmp2=li1), static_cast((tmp2+=1) == li2) ); + PRIVATE_EXPR_TEST( (tmp2=li1), static_cast((tmp2+=li1) == li2) ); + + cout << "Performed tests on MyLongInt objects.\n"; + + return boost::report_errors(); +} -- cgit v1.2.3