Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r67586 - in trunk/libs/ratio/test: . ratio_extensions ratio_io ratio_ratio
From: vicente.botet_at_[hidden]
Date: 2011-01-02 15:23:37


Author: viboes
Date: 2011-01-02 15:23:36 EST (Sun, 02 Jan 2011)
New Revision: 67586
URL: http://svn.boost.org/trac/boost/changeset/67586

Log:
Boost.Ratio: Added test for some mpl arithmetic operations + cleanup
Added:
   trunk/libs/ratio/test/ratio_extensions/mpl_divides_pass.cpp (contents, props changed)
   trunk/libs/ratio/test/ratio_extensions/mpl_minus_pass.cpp (contents, props changed)
   trunk/libs/ratio/test/ratio_extensions/mpl_plus_pass.cpp (contents, props changed)
   trunk/libs/ratio/test/ratio_extensions/mpl_times_pass.cpp (contents, props changed)
Text files modified:
   trunk/libs/ratio/test/Jamfile.v2 | 4 ++++
   trunk/libs/ratio/test/ratio_io/ratio_io_pass.cpp | 25 +------------------------
   trunk/libs/ratio/test/ratio_ratio/ratio_pass.cpp | 18 +++++++++---------
   3 files changed, 14 insertions(+), 33 deletions(-)

Modified: trunk/libs/ratio/test/Jamfile.v2
==============================================================================
--- trunk/libs/ratio/test/Jamfile.v2 (original)
+++ trunk/libs/ratio/test/Jamfile.v2 2011-01-02 15:23:36 EST (Sun, 02 Jan 2011)
@@ -84,4 +84,8 @@
     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 ]
         ;

Added: trunk/libs/ratio/test/ratio_extensions/mpl_divides_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/ratio/test/ratio_extensions/mpl_divides_pass.cpp 2011-01-02 15:23:36 EST (Sun, 02 Jan 2011)
@@ -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 <boost/ratio/mpl/divides.hpp>
+#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<R1, R2> 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<R1, R2> 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<R1, R2> 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<R1, R2> 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<R1, R2> 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<R1, R2> 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<R1, R2> R;
+ BOOST_RATIO_STATIC_ASSERT(R::num == 630992477165LL && R::den == 127339199162436LL, NOTHING, ());
+ }
+}

Added: trunk/libs/ratio/test/ratio_extensions/mpl_minus_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/ratio/test/ratio_extensions/mpl_minus_pass.cpp 2011-01-02 15:23:36 EST (Sun, 02 Jan 2011)
@@ -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 <boost/ratio/mpl/minus.hpp>
+#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<R1, R2> 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<R1, R2> 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<R1, R2> 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<R1, R2> 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<R1, R2> 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<R1, R2> 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<R1, R2> R;
+ BOOST_RATIO_STATIC_ASSERT(R::num == -126708206685271LL && R::den == 5177331081415LL, NOTHING, ());
+ }
+}

Added: trunk/libs/ratio/test/ratio_extensions/mpl_plus_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/ratio/test/ratio_extensions/mpl_plus_pass.cpp 2011-01-02 15:23:36 EST (Sun, 02 Jan 2011)
@@ -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 <boost/ratio/mpl/plus.hpp>
+#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<R1, R2> R;
+ BOOST_RATIO_STATIC_ASSERT(R::num == 2 && R::den == 1, NOTHING, ());
+ typedef boost::mpl::plus<R, R2> 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<R1, R2> 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<R1, R2> 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<R1, R2> 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<R1, R2> 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<R1, R2> 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<R1, R2> R;
+ BOOST_RATIO_STATIC_ASSERT(R::num == 127970191639601LL && R::den == 5177331081415LL, NOTHING, ());
+ }
+ {
+ typedef boost::ratio<BOOST_RATIO_INTMAX_C(0x7FFFFFFFFFFFFFFF), 1> R1;
+ typedef boost::ratio<-1, 1> R2;
+ typedef boost::mpl::plus<R1, R2>::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>
+ >
+ ()
+ );
+}
+

Added: trunk/libs/ratio/test/ratio_extensions/mpl_times_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/ratio/test/ratio_extensions/mpl_times_pass.cpp 2011-01-02 15:23:36 EST (Sun, 02 Jan 2011)
@@ -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 <boost/ratio/mpl/times.hpp>
+#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<R1, R2> 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<R1, R2> 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<R1, R2> 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<R1, R2> 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<R1, R2> 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<R1, R2> 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<R1, R2> R;
+ BOOST_RATIO_STATIC_ASSERT(R::num == 15519594064236LL && R::den == 5177331081415LL, NOTHING, ());
+ }
+}

Modified: trunk/libs/ratio/test/ratio_io/ratio_io_pass.cpp
==============================================================================
--- trunk/libs/ratio/test/ratio_io/ratio_io_pass.cpp (original)
+++ trunk/libs/ratio/test/ratio_io/ratio_io_pass.cpp 2011-01-02 15:23:36 EST (Sun, 02 Jan 2011)
@@ -15,34 +15,11 @@
 
 #include <boost/ratio/ratio_io.hpp>
 #include <boost/detail/lightweight_test.hpp>
-//~ #include <iostream>
 #include <climits>
 
 int main()
 {
- //~ std::cout << std::hex<< boost::integer_traits<boost::intmax_t>::const_min << std::dec << std::endl;
- typedef boost::mpl::integral_c<boost::intmax_t, boost::integer_traits<boost::intmax_t>::const_min> tmin;
- typedef boost::mpl::integral_c<boost::intmax_t, boost::integer_traits<boost::intmax_t>::const_max> tmax;
- //~ std::cout << std::hex<< boost::integer_traits<boost::intmax_t>::const_max << std::dec << std::endl;
- typedef boost::mpl::integral_c<boost::intmax_t,
- (boost::integer_traits<boost::intmax_t>::const_max <0)? -boost::integer_traits<boost::intmax_t>::const_max:boost::integer_traits<boost::intmax_t>::const_max
- > tmmax;
- //~ std::cout << std::hex<< boost::mpl::integral_c<boost::intmax_t,
- //~ boost::integer_traits<boost::intmax_t>::const_max
- //~ >::value << std::dec << std::endl;
-
-// typedef boost::mpl::integral_c<boost::intmax_t,
-// (boost::integer_traits<boost::intmax_t>::const_max <0)? -boost::integer_traits<boost::intmax_t>::const_max:boost::integer_traits<boost::intmax_t>::const_max
-// >::next tmmaxn;
-// typedef boost::mpl::integral_c<boost::intmax_t,
-// (boost::integer_traits<boost::intmax_t>::const_max <0)? -boost::integer_traits<boost::intmax_t>::const_max:boost::integer_traits<boost::intmax_t>::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<boost::atto, char>::long_name() == "atto"

Modified: trunk/libs/ratio/test/ratio_ratio/ratio_pass.cpp
==============================================================================
--- trunk/libs/ratio/test/ratio_ratio/ratio_pass.cpp (original)
+++ trunk/libs/ratio/test/ratio_ratio/ratio_pass.cpp 2011-01-02 15:23:36 EST (Sun, 02 Jan 2011)
@@ -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 <long long N, long long D, long long eN, long long eD>
 void test()
@@ -46,12 +46,12 @@
     test<222, -333, -2, 3>();
     test<-222, 333, -2, 3>();
     test<-222, -333, 2, 3>();
- //~ test<BOOST_RATIO_INTMAX_T_MAX, 127, 72624976668147841LL, 1>();
- //~ test<-BOOST_RATIO_INTMAX_T_MAX, 127, -72624976668147841LL, 1>();
- //~ test<BOOST_RATIO_INTMAX_T_MAX, -127, -72624976668147841LL, 1>();
- //~ test<-BOOST_RATIO_INTMAX_T_MAX, -127, 72624976668147841LL, 1>();
- test<BOOST_RATIO_INTMAX_T_MAX, 127, BOOST_RATIO_INTMAX_T_MAX, 127>();
- test<-BOOST_RATIO_INTMAX_T_MAX, 127, -BOOST_RATIO_INTMAX_T_MAX, 127>();
- test<BOOST_RATIO_INTMAX_T_MAX, -127, -BOOST_RATIO_INTMAX_T_MAX, 127>();
- test<-BOOST_RATIO_INTMAX_T_MAX, -127, BOOST_RATIO_INTMAX_T_MAX, 127>();
+ test<BOOST_RATIO_INTMAX_T_MAX, 127, 72624976668147841LL, 1>();
+ test<-BOOST_RATIO_INTMAX_T_MAX, 127, -72624976668147841LL, 1>();
+ test<BOOST_RATIO_INTMAX_T_MAX, -127, -72624976668147841LL, 1>();
+ test<-BOOST_RATIO_INTMAX_T_MAX, -127, 72624976668147841LL, 1>();
+ //~ test<BOOST_RATIO_INTMAX_T_MAX, 127, BOOST_RATIO_INTMAX_T_MAX, 127>();
+ //~ test<-BOOST_RATIO_INTMAX_T_MAX, 127, -BOOST_RATIO_INTMAX_T_MAX, 127>();
+ //~ test<BOOST_RATIO_INTMAX_T_MAX, -127, -BOOST_RATIO_INTMAX_T_MAX, 127>();
+ //~ test<-BOOST_RATIO_INTMAX_T_MAX, -127, BOOST_RATIO_INTMAX_T_MAX, 127>();
 }


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk