Updated constexpr tests for all affected modules. Added conditional constexpr to equal, which uses std::distance.

This commit is contained in:
MMaximoff
2017-04-07 22:31:23 +03:00
parent 8d095e9d30
commit dfa332e915
15 changed files with 625 additions and 185 deletions

View File

@ -10,6 +10,8 @@
#include <boost/config.hpp>
#include <boost/algorithm/cxx11/copy_if.hpp>
#include "iterator_test.hpp"
#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>
@ -20,6 +22,7 @@
#include <list>
#include <boost/algorithm/cxx11/all_of.hpp>
#include <boost/algorithm/cxx14/equal.hpp>
#include <boost/algorithm/cxx11/none_of.hpp>
namespace ba = boost::algorithm;
@ -29,21 +32,8 @@ BOOST_CXX14_CONSTEXPR bool is_true ( int v ) { return true; }
BOOST_CXX14_CONSTEXPR bool is_false ( int v ) { return false; }
BOOST_CXX14_CONSTEXPR bool is_even ( int v ) { return v % 2 == 0; }
BOOST_CXX14_CONSTEXPR bool is_odd ( int v ) { return v % 2 == 1; }
BOOST_CXX14_CONSTEXPR bool is_zero ( int v ) { return v == 0; }
BOOST_CXX14_CONSTEXPR inline bool constexpr_helper(const int* from, const int* to) {
bool res = true;
int out_data[64] = {0};
int* out = out_data;
ba::copy_if ( from, to, out, is_false);
res = (res && out == out_data);
ba::copy_if ( from, to, out, is_true);
res = (res && out == out_data + (to - from));
return res;
}
template <typename Container>
void test_copy_if ( Container const &c ) {
@ -170,6 +160,71 @@ void test_copy_until ( Container const &c ) {
BOOST_CHECK ( ba::none_of ( v.begin (), v.end (), is_even ));
BOOST_CHECK ( std::equal ( v.begin (), v.end (), c.begin ()));
}
BOOST_CXX14_CONSTEXPR inline bool constexpr_test_copy_if() {
const int sz = 64;
int in_data[sz] = {0};
bool res = true;
const int* from = in_data;
const int* to = in_data + sz;
int out_data[sz] = {0};
int* out = out_data;
out = ba::copy_if ( from, to, out, is_false ); // copy none
res = (res && out == out_data);
out = ba::copy_if ( from, to, out, is_true ); // copy all
res = (res && out == out_data + sz
&& ba::equal( input_iterator<const int *>(out_data), input_iterator<const int *>(out_data + sz),
input_iterator<const int *>(from), input_iterator<const int *>(to)));
return res;
}
BOOST_CXX14_CONSTEXPR inline bool constexpr_test_copy_while() {
const int sz = 64;
int in_data[sz] = {0};
bool res = true;
const int* from = in_data;
const int* to = in_data + sz;
int out_data[sz] = {0};
int* out = out_data;
out = ba::copy_while ( from, to, out, is_false ).second; // copy none
res = (res && out == out_data && ba::all_of(out, out + sz, is_zero));
out = ba::copy_while ( from, to, out, is_true ).second; // copy all
res = (res && out == out_data + sz
&& ba::equal( input_iterator<const int *>(out_data), input_iterator<const int *>(out_data + sz),
input_iterator<const int *>(from), input_iterator<const int *>(to)));
return res;
}
BOOST_CXX14_CONSTEXPR inline bool constexpr_test_copy_until() {
const int sz = 64;
int in_data[sz] = {0};
bool res = true;
const int* from = in_data;
const int* to = in_data + sz;
int out_data[sz] = {0};
int* out = out_data;
out = ba::copy_until ( from, to, out, is_true ).second; // copy none
res = (res && out == out_data && ba::all_of(out, out + sz, is_zero));
out = ba::copy_until ( from, to, out, is_false ).second; // copy all
res = (res && out == out_data + sz
&& ba::equal( input_iterator<const int *>(out_data), input_iterator<const int *>(out_data + sz),
input_iterator<const int *>(from), input_iterator<const int *>(to)));
return res;
}
void test_sequence1 () {
std::vector<int> v;
@ -179,8 +234,12 @@ void test_sequence1 () {
test_copy_while ( v );
test_copy_until ( v );
BOOST_CXX14_CONSTEXPR bool constexpr_res = constexpr_helper(0, 0);
BOOST_CHECK ( constexpr_res );
BOOST_CXX14_CONSTEXPR bool constexpr_res_if = constexpr_test_copy_if();
BOOST_CHECK ( constexpr_res_if );
BOOST_CXX14_CONSTEXPR bool constexpr_res_while = constexpr_test_copy_while();
BOOST_CHECK ( constexpr_res_while );
BOOST_CXX14_CONSTEXPR bool constexpr_res_until = constexpr_test_copy_until();
BOOST_CHECK ( constexpr_res_until );
std::list<int> l;
for ( int i = 25; i > 15; --i )