From cb02b93c96cb902912400f4ab3470dd288dfa727 Mon Sep 17 00:00:00 2001 From: "Vicente J. Botet Escriba" Date: Sun, 2 Jan 2011 20:23:36 +0000 Subject: [PATCH] Boost.Ratio: Added test for some mpl arithmetic operations + cleanup [SVN r67586] --- test/Jamfile.v2 | 4 + test/ratio_extensions/mpl_divides_pass.cpp | 67 ++++++++++++++++ test/ratio_extensions/mpl_minus_pass.cpp | 68 ++++++++++++++++ test/ratio_extensions/mpl_plus_pass.cpp | 91 ++++++++++++++++++++++ test/ratio_extensions/mpl_times_pass.cpp | 67 ++++++++++++++++ test/ratio_io/ratio_io_pass.cpp | 25 +----- test/ratio_ratio/ratio_pass.cpp | 18 ++--- 7 files changed, 307 insertions(+), 33 deletions(-) create mode 100644 test/ratio_extensions/mpl_divides_pass.cpp create mode 100644 test/ratio_extensions/mpl_minus_pass.cpp create mode 100644 test/ratio_extensions/mpl_plus_pass.cpp create mode 100644 test/ratio_extensions/mpl_times_pass.cpp diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index f29c6d7..10874e8 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -84,4 +84,8 @@ project test-suite "ratio.ext" : [ run ratio_extensions/ratio_ext_pass.cpp ] + [ compile ratio_extensions/mpl_plus_pass.cpp ] + [ compile ratio_extensions/mpl_minus_pass.cpp ] + [ compile ratio_extensions/mpl_times_pass.cpp ] + [ compile ratio_extensions/mpl_divides_pass.cpp ] ; diff --git a/test/ratio_extensions/mpl_divides_pass.cpp b/test/ratio_extensions/mpl_divides_pass.cpp new file mode 100644 index 0000000..9db6e24 --- /dev/null +++ b/test/ratio_extensions/mpl_divides_pass.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +// test mpl::divides + +#define BOOST_RATIO_EXTENSIONS + +#include +#if !defined(BOOST_NO_STATIC_ASSERT) +#define NOTHING "" +#endif + +void test() +{ + { + typedef boost::ratio<1, 1> R1; + typedef boost::ratio<1, 1> R2; + typedef boost::mpl::divides R; + BOOST_RATIO_STATIC_ASSERT(R::num == 1 && R::den == 1, NOTHING, ()); + } + { + typedef boost::ratio<1, 2> R1; + typedef boost::ratio<1, 1> R2; + typedef boost::mpl::divides R; + BOOST_RATIO_STATIC_ASSERT(R::num == 1 && R::den == 2, NOTHING, ()); + } + { + typedef boost::ratio<-1, 2> R1; + typedef boost::ratio<1, 1> R2; + typedef boost::mpl::divides R; + BOOST_RATIO_STATIC_ASSERT(R::num == -1 && R::den == 2, NOTHING, ()); + } + { + typedef boost::ratio<1, -2> R1; + typedef boost::ratio<1, 1> R2; + typedef boost::mpl::divides R; + BOOST_RATIO_STATIC_ASSERT(R::num == -1 && R::den == 2, NOTHING, ()); + } + { + typedef boost::ratio<1, 2> R1; + typedef boost::ratio<-1, 1> R2; + typedef boost::mpl::divides R; + BOOST_RATIO_STATIC_ASSERT(R::num == -1 && R::den == 2, NOTHING, ()); + } + { + typedef boost::ratio<1, 2> R1; + typedef boost::ratio<1, -1> R2; + typedef boost::mpl::divides R; + BOOST_RATIO_STATIC_ASSERT(R::num == -1 && R::den == 2, NOTHING, ()); + } + { + typedef boost::ratio<56987354, 467584654> R1; + typedef boost::ratio<544668, 22145> R2; + typedef boost::mpl::divides R; + BOOST_RATIO_STATIC_ASSERT(R::num == 630992477165LL && R::den == 127339199162436LL, NOTHING, ()); + } +} diff --git a/test/ratio_extensions/mpl_minus_pass.cpp b/test/ratio_extensions/mpl_minus_pass.cpp new file mode 100644 index 0000000..0198206 --- /dev/null +++ b/test/ratio_extensions/mpl_minus_pass.cpp @@ -0,0 +1,68 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +// test mpl::minus + +#define BOOST_RATIO_EXTENSIONS + +#include +#if !defined(BOOST_NO_STATIC_ASSERT) +#define NOTHING "" +#endif + +void test() +{ + + { + typedef boost::ratio<1, 1> R1; + typedef boost::ratio<1, 1> R2; + typedef boost::mpl::minus R; + BOOST_RATIO_STATIC_ASSERT(R::num == 0 && R::den == 1, NOTHING, ()); + } + { + typedef boost::ratio<1, 2> R1; + typedef boost::ratio<1, 1> R2; + typedef boost::mpl::minus R; + BOOST_RATIO_STATIC_ASSERT(R::num == -1 && R::den == 2, NOTHING, ()); + } + { + typedef boost::ratio<-1, 2> R1; + typedef boost::ratio<1, 1> R2; + typedef boost::mpl::minus R; + BOOST_RATIO_STATIC_ASSERT(R::num == -3 && R::den == 2, NOTHING, ()); + } + { + typedef boost::ratio<1, -2> R1; + typedef boost::ratio<1, 1> R2; + typedef boost::mpl::minus R; + BOOST_RATIO_STATIC_ASSERT(R::num == -3 && R::den == 2, NOTHING, ()); + } + { + typedef boost::ratio<1, 2> R1; + typedef boost::ratio<-1, 1> R2; + typedef boost::mpl::minus R; + BOOST_RATIO_STATIC_ASSERT(R::num == 3 && R::den == 2, NOTHING, ()); + } + { + typedef boost::ratio<1, 2> R1; + typedef boost::ratio<1, -1> R2; + typedef boost::mpl::minus R; + BOOST_RATIO_STATIC_ASSERT(R::num == 3 && R::den == 2, NOTHING, ()); + } + { + typedef boost::ratio<56987354, 467584654> R1; + typedef boost::ratio<544668, 22145> R2; + typedef boost::mpl::minus R; + BOOST_RATIO_STATIC_ASSERT(R::num == -126708206685271LL && R::den == 5177331081415LL, NOTHING, ()); + } +} diff --git a/test/ratio_extensions/mpl_plus_pass.cpp b/test/ratio_extensions/mpl_plus_pass.cpp new file mode 100644 index 0000000..0b89509 --- /dev/null +++ b/test/ratio_extensions/mpl_plus_pass.cpp @@ -0,0 +1,91 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +// test mpl::plus + +#define BOOST_RATIO_EXTENSIONS + +#include +#if !defined(BOOST_NO_STATIC_ASSERT) +#define NOTHING "" +#endif + +void test() +{ + { + typedef boost::ratio<1, 1> R1; + typedef boost::mpl::int_<1> R2; + typedef boost::mpl::plus R; + BOOST_RATIO_STATIC_ASSERT(R::num == 2 && R::den == 1, NOTHING, ()); + typedef boost::mpl::plus RR; + BOOST_RATIO_STATIC_ASSERT(RR::num == 3 && RR::den == 1, NOTHING, ()); + } + { + typedef boost::mpl::int_<1> R1; + typedef boost::ratio<1, 2> R2; + typedef boost::mpl::plus R; + BOOST_RATIO_STATIC_ASSERT(R::num == 3 && R::den == 2, NOTHING, ()); + } + { + typedef boost::ratio<-1, 2> R1; + typedef boost::ratio<1, 1> R2; + typedef boost::mpl::plus R; + BOOST_RATIO_STATIC_ASSERT(R::num == 1 && R::den == 2, NOTHING, ()); + } + { + typedef boost::ratio<1, -2> R1; + typedef boost::ratio<1, 1> R2; + typedef boost::mpl::plus R; + BOOST_RATIO_STATIC_ASSERT(R::num == 1 && R::den == 2, NOTHING, ()); + } + { + typedef boost::ratio<1, 2> R1; + typedef boost::ratio<-1, 1> R2; + typedef boost::mpl::plus R; + BOOST_RATIO_STATIC_ASSERT(R::num == -1 && R::den == 2, NOTHING, ()); + } + { + typedef boost::ratio<1, 2> R1; + typedef boost::ratio<1, -1> R2; + typedef boost::mpl::plus R; + BOOST_RATIO_STATIC_ASSERT(R::num == -1 && R::den == 2, NOTHING, ()); + } + { + typedef boost::ratio<56987354, 467584654> R1; + typedef boost::ratio<544668, 22145> R2; + typedef boost::mpl::plus R; + BOOST_RATIO_STATIC_ASSERT(R::num == 127970191639601LL && R::den == 5177331081415LL, NOTHING, ()); + } + { + typedef boost::ratio R1; + typedef boost::ratio<-1, 1> R2; + typedef boost::mpl::plus::type RT; + } + +} + +boost::intmax_t func(boost::ratio<5,6> s) { + return s.num; +} + + +boost::intmax_t test_conversion() { + return func( + boost::mpl::plus< + boost::ratio<1,2>, + boost::ratio<1,3> + > + () + ); +} + diff --git a/test/ratio_extensions/mpl_times_pass.cpp b/test/ratio_extensions/mpl_times_pass.cpp new file mode 100644 index 0000000..d58a1c4 --- /dev/null +++ b/test/ratio_extensions/mpl_times_pass.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +// test mpl::times + +#define BOOST_RATIO_EXTENSIONS + +#include +#if !defined(BOOST_NO_STATIC_ASSERT) +#define NOTHING "" +#endif + +void test() +{ + { + typedef boost::ratio<1, 1> R1; + typedef boost::ratio<1, 1> R2; + typedef boost::mpl::times R; + BOOST_RATIO_STATIC_ASSERT(R::num == 1 && R::den == 1, NOTHING, ()); + } + { + typedef boost::ratio<1, 2> R1; + typedef boost::ratio<1, 1> R2; + typedef boost::mpl::times R; + BOOST_RATIO_STATIC_ASSERT(R::num == 1 && R::den == 2, NOTHING, ()); + } + { + typedef boost::ratio<-1, 2> R1; + typedef boost::ratio<1, 1> R2; + typedef boost::mpl::times R; + BOOST_RATIO_STATIC_ASSERT(R::num == -1 && R::den == 2, NOTHING, ()); + } + { + typedef boost::ratio<1, -2> R1; + typedef boost::ratio<1, 1> R2; + typedef boost::mpl::times R; + BOOST_RATIO_STATIC_ASSERT(R::num == -1 && R::den == 2, NOTHING, ()); + } + { + typedef boost::ratio<1, 2> R1; + typedef boost::ratio<-1, 1> R2; + typedef boost::mpl::times R; + BOOST_RATIO_STATIC_ASSERT(R::num == -1 && R::den == 2, NOTHING, ()); + } + { + typedef boost::ratio<1, 2> R1; + typedef boost::ratio<1, -1> R2; + typedef boost::mpl::times R; + BOOST_RATIO_STATIC_ASSERT(R::num == -1 && R::den == 2, NOTHING, ()); + } + { + typedef boost::ratio<56987354, 467584654> R1; + typedef boost::ratio<544668, 22145> R2; + typedef boost::mpl::times R; + BOOST_RATIO_STATIC_ASSERT(R::num == 15519594064236LL && R::den == 5177331081415LL, NOTHING, ()); + } +} diff --git a/test/ratio_io/ratio_io_pass.cpp b/test/ratio_io/ratio_io_pass.cpp index 3d4e22d..c4bc2a8 100644 --- a/test/ratio_io/ratio_io_pass.cpp +++ b/test/ratio_io/ratio_io_pass.cpp @@ -15,34 +15,11 @@ #include #include -//~ #include #include int main() { - //~ std::cout << std::hex<< boost::integer_traits::const_min << std::dec << std::endl; - typedef boost::mpl::integral_c::const_min> tmin; - typedef boost::mpl::integral_c::const_max> tmax; - //~ std::cout << std::hex<< boost::integer_traits::const_max << std::dec << std::endl; - typedef boost::mpl::integral_c::const_max <0)? -boost::integer_traits::const_max:boost::integer_traits::const_max - > tmmax; - //~ std::cout << std::hex<< boost::mpl::integral_c::const_max - //~ >::value << std::dec << std::endl; - -// typedef boost::mpl::integral_c::const_max <0)? -boost::integer_traits::const_max:boost::integer_traits::const_max -// >::next tmmaxn; -// typedef boost::mpl::integral_c::const_max <0)? -boost::integer_traits::const_max:boost::integer_traits::const_max -// >::prior tmmaxp; - - - //~ std::cout << std::hex<< -0x7FFFFFFFFFFFFFFFLL+1 << std::dec << std::endl; - //~ std::cout << std::hex<< -0x7FFFFFFFFFFFFFFFLL-1 << std::dec << std::endl; - //~ std::cout << std::hex<< -0x7FFFFFFFFFFFFFFFLL << std::dec << std::endl; - //~ std::cout << std::hex<< 0x7FFFFFFFFFFFFFFFLL-1 << std::dec << std::endl; + { BOOST_TEST(( boost::ratio_string::long_name() == "atto" diff --git a/test/ratio_ratio/ratio_pass.cpp b/test/ratio_ratio/ratio_pass.cpp index 088c009..7a409e2 100644 --- a/test/ratio_ratio/ratio_pass.cpp +++ b/test/ratio_ratio/ratio_pass.cpp @@ -19,7 +19,7 @@ #if !defined(BOOST_NO_STATIC_ASSERT) #define NOTHING "" #endif -#define BOOST_RATIO_INTMAX_T_MAX (0x7FFFFFFFFFFFFFFFLL-1) +#define BOOST_RATIO_INTMAX_T_MAX (0x7FFFFFFFFFFFFFFFLL) template void test() @@ -46,12 +46,12 @@ int main() test<222, -333, -2, 3>(); test<-222, 333, -2, 3>(); test<-222, -333, 2, 3>(); - //~ test(); - //~ test<-BOOST_RATIO_INTMAX_T_MAX, 127, -72624976668147841LL, 1>(); - //~ test(); - //~ test<-BOOST_RATIO_INTMAX_T_MAX, -127, 72624976668147841LL, 1>(); - test(); - test<-BOOST_RATIO_INTMAX_T_MAX, 127, -BOOST_RATIO_INTMAX_T_MAX, 127>(); - test(); - test<-BOOST_RATIO_INTMAX_T_MAX, -127, BOOST_RATIO_INTMAX_T_MAX, 127>(); + test(); + test<-BOOST_RATIO_INTMAX_T_MAX, 127, -72624976668147841LL, 1>(); + test(); + test<-BOOST_RATIO_INTMAX_T_MAX, -127, 72624976668147841LL, 1>(); + //~ test(); + //~ test<-BOOST_RATIO_INTMAX_T_MAX, 127, -BOOST_RATIO_INTMAX_T_MAX, 127>(); + //~ test(); + //~ test<-BOOST_RATIO_INTMAX_T_MAX, -127, BOOST_RATIO_INTMAX_T_MAX, 127>(); }