Boost.Ratio: Added test for some mpl arithmetic operations + cleanup

[SVN r67586]
This commit is contained in:
Vicente J. Botet Escriba 2011-01-02 20:23:36 +00:00
parent bf835551fc
commit cb02b93c96
7 changed files with 307 additions and 33 deletions

View File

@ -84,4 +84,8 @@ project
test-suite "ratio.ext" test-suite "ratio.ext"
: :
[ run ratio_extensions/ratio_ext_pass.cpp ] [ 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 ]
; ;

View File

@ -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, ());
}
}

View File

@ -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, ());
}
}

View File

@ -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>
>
()
);
}

View File

@ -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, ());
}
}

View File

@ -15,34 +15,11 @@
#include <boost/ratio/ratio_io.hpp> #include <boost/ratio/ratio_io.hpp>
#include <boost/detail/lightweight_test.hpp> #include <boost/detail/lightweight_test.hpp>
//~ #include <iostream>
#include <climits> #include <climits>
int main() 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_TEST((
boost::ratio_string<boost::atto, char>::long_name() == "atto" boost::ratio_string<boost::atto, char>::long_name() == "atto"

View File

@ -19,7 +19,7 @@
#if !defined(BOOST_NO_STATIC_ASSERT) #if !defined(BOOST_NO_STATIC_ASSERT)
#define NOTHING "" #define NOTHING ""
#endif #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> template <long long N, long long D, long long eN, long long eD>
void test() void test()
@ -46,12 +46,12 @@ int main()
test<222, -333, -2, 3>(); test<222, -333, -2, 3>();
test<-222, 333, -2, 3>(); 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, -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, -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>();
} }