mirror of
https://github.com/boostorg/algorithm.git
synced 2025-07-02 15:31:08 +02:00
Merge from develop; new feature 'power'; doc fixes; remove usage of C++11 versions of the algorithms
This commit is contained in:
@ -27,8 +27,10 @@ alias unit_test_framework
|
||||
[ compile-fail search_fail2.cpp : : : : ]
|
||||
[ compile-fail search_fail3.cpp : : : : ]
|
||||
|
||||
# Clamp tests
|
||||
# Misc tests
|
||||
[ run clamp_test.cpp unit_test_framework : : : : clamp_test ]
|
||||
[ run power_test.cpp unit_test_framework : : : : power_test ]
|
||||
[ compile-fail power_fail1.cpp : : : : ]
|
||||
|
||||
# Cxx11 tests
|
||||
[ run all_of_test.cpp unit_test_framework : : : : all_of_test ]
|
||||
|
@ -43,16 +43,17 @@ void test_sequence ( Container &v, Predicate comp, int expected ) {
|
||||
|
||||
res = ba::partition_point ( v.begin (), v.end (), comp );
|
||||
exp = offset_to_iter ( v, expected );
|
||||
std::cout << "Expected(1): " << std::distance ( v.begin (), exp )
|
||||
<< ", got: " << std::distance ( v.begin (), res ) << std::endl;
|
||||
BOOST_CHECK ( exp == res );
|
||||
|
||||
// Duplicate the last element; this checks for any even/odd problems
|
||||
v.push_back ( * v.rbegin ());
|
||||
res = ba::partition_point ( v.begin (), v.end (), comp );
|
||||
exp = offset_to_iter ( v, expected );
|
||||
std::cout << "Expected(2): " << std::distance ( v.begin (), exp )
|
||||
<< ", got: " << std::distance ( v.begin (), res ) << std::endl;
|
||||
BOOST_CHECK ( exp == res );
|
||||
|
||||
// Range based test
|
||||
res = ba::partition_point ( v, comp );
|
||||
exp = offset_to_iter ( v, expected );
|
||||
BOOST_CHECK ( exp == res );
|
||||
}
|
||||
|
||||
|
24
test/power_fail1.cpp
Normal file
24
test/power_fail1.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
/*
|
||||
Copyright (c) Marshall Clow 2014.
|
||||
|
||||
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)
|
||||
|
||||
For more information, see http://www.boost.org
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/algorithm/algorithm.hpp>
|
||||
|
||||
#define BOOST_TEST_MAIN
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
namespace ba = boost::algorithm;
|
||||
|
||||
BOOST_AUTO_TEST_CASE( test_main )
|
||||
{
|
||||
// Second argument must be an integral value
|
||||
BOOST_CHECK ( ba::power(1, 1.0) == 1);
|
||||
}
|
35
test/power_test.cpp
Normal file
35
test/power_test.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
Copyright (c) Marshall Clow 2014.
|
||||
|
||||
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)
|
||||
|
||||
For more information, see http://www.boost.org
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/algorithm/algorithm.hpp>
|
||||
|
||||
#define BOOST_TEST_MAIN
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
namespace ba = boost::algorithm;
|
||||
|
||||
BOOST_AUTO_TEST_CASE( test_main )
|
||||
{
|
||||
BOOST_CHECK ( ba::power(0, 0) == 1);
|
||||
BOOST_CHECK ( ba::power(5, 0) == 1);
|
||||
BOOST_CHECK ( ba::power(1, 1) == 1);
|
||||
BOOST_CHECK ( ba::power(1, 4) == 1);
|
||||
BOOST_CHECK ( ba::power(3, 2) == 9);
|
||||
BOOST_CHECK ( ba::power(2, 3) == 8);
|
||||
BOOST_CHECK ( ba::power(3, 3) == 27);
|
||||
BOOST_CHECK ( ba::power(2, 30) == 0x40000000);
|
||||
BOOST_CHECK ( ba::power(5L, 10) == 3125*3125);
|
||||
BOOST_CHECK ( ba::power(18, 3) == 18*18*18);
|
||||
|
||||
BOOST_CHECK ( ba::power(3,2) == ba::power(3,2, std::multiplies<int>()));
|
||||
BOOST_CHECK ( ba::power(3,2, std::plus<int>()) == 6);
|
||||
}
|
Reference in New Issue
Block a user