/* @copyright Louis Dionne 2014 Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) */ #include #include #include #include #include #include // instances #include #include #include #include #include #include #include using namespace boost::hana; namespace boost { namespace hana { namespace test { template <> auto instances = tuple( type, type, type, type, type, type ); template <> auto objects = tuple( ::std::ratio<0>{}, ::std::ratio<1, 3>{}, ::std::ratio<1, 2>{}, ::std::ratio<2, 6>{}, ::std::ratio<3, 1>{}, ::std::ratio<7, 8>{}, ::std::ratio<3, 5>{}, ::std::ratio<2, 1>{} ); }}} int main() { test::check_datatype(); // Conversions { // IntegralConstant -> Ratio { BOOST_HANA_CONSTANT_CHECK(equal( to(test::cnumeric), std::ratio<0>{} )); BOOST_HANA_CONSTANT_CHECK(equal( to(test::cnumeric), std::ratio<1>{} )); BOOST_HANA_CONSTANT_CHECK(equal( to(test::cnumeric), std::ratio<3>{} )); } } // Comparable { // equal { BOOST_HANA_CONSTANT_CHECK(equal( std::ratio<0>{}, std::ratio<0>{} )); BOOST_HANA_CONSTANT_CHECK(equal( std::ratio<3, 5>{}, std::ratio<6, 10>{} )); BOOST_HANA_CONSTANT_CHECK(not_(equal( std::ratio<4, 5>{}, std::ratio<6, 10>{} ))); } } // Orderable { // less { BOOST_HANA_CONSTANT_CHECK(less( std::ratio<1>{}, std::ratio<3>{} )); BOOST_HANA_CONSTANT_CHECK(less( std::ratio<4, 10>{}, std::ratio<3, 5>{} )); BOOST_HANA_CONSTANT_CHECK(not_(less( std::ratio<3, 5>{}, std::ratio<4, 10>{} ))); } } // Monoid { // plus { BOOST_HANA_CONSTANT_CHECK(equal( plus(std::ratio<3, 4>{}, std::ratio<5, 10>{}), std::ratio<3*10 + 5*4, 4*10>{} )); } // zero { BOOST_HANA_CONSTANT_CHECK(equal( zero(), std::ratio<0, 1>{} )); BOOST_HANA_CONSTANT_CHECK(equal( zero(), std::ratio<0, 2>{} )); } } // Group { // minus { BOOST_HANA_CONSTANT_CHECK(equal( minus(std::ratio<3, 4>{}, std::ratio<5, 10>{}), std::ratio<3*10 - 5*4, 4*10>{} )); } } // Ring { // mult { BOOST_HANA_CONSTANT_CHECK(equal( mult(std::ratio<3, 4>{}, std::ratio<5, 10>{}), std::ratio<3*5, 4*10>{} )); } // one { BOOST_HANA_CONSTANT_CHECK(equal( one(), std::ratio<1, 1>{} )); BOOST_HANA_CONSTANT_CHECK(equal( one(), std::ratio<2, 2>{} )); } } // IntegralDomain { // quot { BOOST_HANA_CONSTANT_CHECK(equal( quot(std::ratio<6>{}, std::ratio<4>{}), std::ratio<6, 4>{} )); BOOST_HANA_CONSTANT_CHECK(equal( quot(std::ratio<3, 4>{}, std::ratio<5, 10>{}), std::ratio<3*10, 4*5>{} )); } // mod { BOOST_HANA_CONSTANT_CHECK(equal( mod(std::ratio<6>{}, std::ratio<4>{}), std::ratio<0>{} )); BOOST_HANA_CONSTANT_CHECK(equal( mod(std::ratio<3, 4>{}, std::ratio<5, 10>{}), std::ratio<0>{} )); } } }