123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260 |
- // Boost.TypeErasure library
- //
- // Copyright 2011 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$
- #include <boost/type_erasure/any.hpp>
- #include <boost/type_erasure/builtin.hpp>
- #include <boost/type_erasure/operators.hpp>
- #include <boost/type_erasure/any_cast.hpp>
- #include <boost/type_erasure/tuple.hpp>
- #include <boost/mpl/vector.hpp>
- #define BOOST_TEST_MAIN
- #include <boost/test/unit_test.hpp>
- using namespace boost::type_erasure;
- BOOST_AUTO_TEST_CASE(test_basic)
- {
- typedef boost::mpl::vector<copy_constructible<>, less_than_comparable<> > test_concept;
- any<test_concept> x(1);
- any<test_concept> y(2);
- BOOST_CHECK((x < y));
- BOOST_CHECK(!(y < x));
- BOOST_CHECK(!(x < x));
- BOOST_CHECK(!(x > y));
- BOOST_CHECK((y > x));
- BOOST_CHECK(!(x > x));
- BOOST_CHECK((x <= y));
- BOOST_CHECK(!(y <= x));
- BOOST_CHECK((x <= x));
-
- BOOST_CHECK(!(x >= y));
- BOOST_CHECK((y >= x));
- BOOST_CHECK((x >= x));
- }
- BOOST_AUTO_TEST_CASE(test_mixed_less)
- {
- typedef boost::mpl::vector<copy_constructible<_a>, copy_constructible<_b>, less_than_comparable<_a, _b> > test_concept;
- tuple<test_concept, _a, _b> t(1, 2.0);
- any<test_concept, _a> x(get<0>(t));
- any<test_concept, _b> y(get<1>(t));
- BOOST_CHECK((x < y));
- BOOST_CHECK((y > x));
- BOOST_CHECK(!(y <= x));
- BOOST_CHECK(!(x >= y));
- }
- BOOST_AUTO_TEST_CASE(test_mixed_equal)
- {
- typedef boost::mpl::vector<copy_constructible<_a>, copy_constructible<_b>, less_than_comparable<_a, _b> > test_concept;
- tuple<test_concept, _a, _b> t(1, 1);
- any<test_concept, _a> x(get<0>(t));
- any<test_concept, _b> y(get<1>(t));
- BOOST_CHECK(!(x < y));
- BOOST_CHECK(!(y > x));
- BOOST_CHECK((y <= x));
- BOOST_CHECK((x >= y));
- }
- BOOST_AUTO_TEST_CASE(test_mixed_greater)
- {
- typedef boost::mpl::vector<copy_constructible<_a>, copy_constructible<_b>, less_than_comparable<_a, _b> > test_concept;
- tuple<test_concept, _a, _b> t(2.0, 1);
- any<test_concept, _a> x(get<0>(t));
- any<test_concept, _b> y(get<1>(t));
- BOOST_CHECK(!(x < y));
- BOOST_CHECK(!(y > x));
- BOOST_CHECK((y <= x));
- BOOST_CHECK((x >= y));
- }
- BOOST_AUTO_TEST_CASE(test_fixed_lhs_less)
- {
- typedef boost::mpl::vector<copy_constructible<>, less_than_comparable<int, _self> > test_concept;
- int x(1);
- any<test_concept> y(2.0);
- BOOST_CHECK((x < y));
- BOOST_CHECK((y > x));
- BOOST_CHECK(!(y <= x));
- BOOST_CHECK(!(x >= y));
- }
- BOOST_AUTO_TEST_CASE(test_fixed_lhs_equal)
- {
- typedef boost::mpl::vector<copy_constructible<>, less_than_comparable<int, _self> > test_concept;
- int x(1);
- any<test_concept> y(1);
- BOOST_CHECK(!(x < y));
- BOOST_CHECK(!(y > x));
- BOOST_CHECK((y <= x));
- BOOST_CHECK((x >= y));
- }
- BOOST_AUTO_TEST_CASE(test_fixed_lhs_greater)
- {
- typedef boost::mpl::vector<copy_constructible<>, less_than_comparable<int, _self> > test_concept;
- int x(1);
- any<test_concept> y(0.5);
- BOOST_CHECK(!(x < y));
- BOOST_CHECK(!(y > x));
- BOOST_CHECK((y <= x));
- BOOST_CHECK((x >= y));
- }
- BOOST_AUTO_TEST_CASE(test_fixed_rhs_less)
- {
- typedef boost::mpl::vector<copy_constructible<>, less_than_comparable<_self, int> > test_concept;
- any<test_concept> x(1.0);
- int y(2);
- BOOST_CHECK((x < y));
- BOOST_CHECK((y > x));
- BOOST_CHECK(!(y <= x));
- BOOST_CHECK(!(x >= y));
- }
- BOOST_AUTO_TEST_CASE(test_fixed_rhs_equal)
- {
- typedef boost::mpl::vector<copy_constructible<>, less_than_comparable<_self, int> > test_concept;
- any<test_concept> x(1);
- int y(1);
- BOOST_CHECK(!(x < y));
- BOOST_CHECK(!(y > x));
- BOOST_CHECK((y <= x));
- BOOST_CHECK((x >= y));
- }
- BOOST_AUTO_TEST_CASE(test_fixed_rhs_greater)
- {
- typedef boost::mpl::vector<copy_constructible<>, less_than_comparable<_self, int> > test_concept;
- any<test_concept> x(2.0);
- int y(1);
- BOOST_CHECK(!(x < y));
- BOOST_CHECK(!(y > x));
- BOOST_CHECK((y <= x));
- BOOST_CHECK((x >= y));
- }
- BOOST_AUTO_TEST_CASE(test_relaxed)
- {
- typedef boost::mpl::vector<copy_constructible<>, less_than_comparable<>, relaxed> test_concept;
- any<test_concept> x(1);
- any<test_concept> y(2);
- any<test_concept> z(std::string("test"));
- BOOST_CHECK((x < y));
- BOOST_CHECK(!(y < x));
- BOOST_CHECK(!(x < x));
- BOOST_CHECK(!(x > y));
- BOOST_CHECK((y > x));
- BOOST_CHECK(!(x > x));
- BOOST_CHECK((x <= y));
- BOOST_CHECK(!(y <= x));
- BOOST_CHECK((x <= x));
-
- BOOST_CHECK(!(x >= y));
- BOOST_CHECK((y >= x));
- BOOST_CHECK((x >= x));
- bool expected = x < z;
- BOOST_CHECK_EQUAL((x < z), expected);
- BOOST_CHECK_EQUAL(!(z < x), expected);
- BOOST_CHECK_EQUAL(!(x > z), expected);
- BOOST_CHECK_EQUAL((z > x), expected);
- BOOST_CHECK_EQUAL((x <= z), expected);
- BOOST_CHECK_EQUAL(!(z <= x), expected);
-
- BOOST_CHECK_EQUAL(!(x >= z), expected);
- BOOST_CHECK_EQUAL((z >= x), expected);
-
- BOOST_CHECK_EQUAL((y < z), expected);
- BOOST_CHECK_EQUAL(!(z < y), expected);
- BOOST_CHECK_EQUAL(!(y > z), expected);
- BOOST_CHECK_EQUAL((z > y), expected);
- BOOST_CHECK_EQUAL((y <= z), expected);
- BOOST_CHECK_EQUAL(!(z <= y), expected);
-
- BOOST_CHECK_EQUAL(!(y >= z), expected);
- BOOST_CHECK_EQUAL((z >= y), expected);
- }
- BOOST_AUTO_TEST_CASE(test_overload)
- {
- typedef boost::mpl::vector<
- copy_constructible<_a>,
- copy_constructible<_b>,
- less_than_comparable<_a>,
- less_than_comparable<_a, int>,
- less_than_comparable<int, _a>,
- less_than_comparable<_b>,
- less_than_comparable<_b, int>,
- less_than_comparable<int, _b>,
- less_than_comparable<_a, _b>
- > test_concept;
- tuple<test_concept, _a, _b> t(1, 2);
- any<test_concept, _a> x(get<0>(t));
- any<test_concept, _b> y(get<1>(t));
- BOOST_CHECK(!(x < x));
- BOOST_CHECK(x <= x);
- BOOST_CHECK(!(x > x));
- BOOST_CHECK(x >= x);
-
- BOOST_CHECK(!(x < 1));
- BOOST_CHECK(x <= 1);
- BOOST_CHECK(!(x > 1));
- BOOST_CHECK(x >= 1);
- BOOST_CHECK(!(1 < x));
- BOOST_CHECK(1 <= x);
- BOOST_CHECK(!(1 > x));
- BOOST_CHECK(1 >= x);
-
- BOOST_CHECK(!(y < y));
- BOOST_CHECK(y <= y);
- BOOST_CHECK(!(y > y));
- BOOST_CHECK(y >= y);
-
- BOOST_CHECK(!(y < 2));
- BOOST_CHECK(y <= 2);
- BOOST_CHECK(!(y > 2));
- BOOST_CHECK(y >= 2);
- BOOST_CHECK(!(2 < y));
- BOOST_CHECK(2 <= y);
- BOOST_CHECK(!(2 > y));
- BOOST_CHECK(2 >= y);
-
- BOOST_CHECK(x < y);
- BOOST_CHECK(y > x);
- BOOST_CHECK(!(y <= x));
- BOOST_CHECK(!(x >= y));
- }
|