early-access version 3088

This commit is contained in:
pineappleEA
2022-11-05 15:35:56 +01:00
parent 4e4fc25ce3
commit b601909c6d
35519 changed files with 5996896 additions and 860 deletions

View File

@@ -0,0 +1,707 @@
// (C) Copyright Gennadiy Rozental 2011-2015.
// 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)
// See http://www.boost.org/libs/test for the library home page.
//
// File : $RCSfile$
//
// Version : $Revision: 62023 $
//
// Description : unit test for new assertion construction based on input expression
// ***************************************************************************
// Boost.Test
#define BOOST_TEST_MODULE Boost.Test assertion consruction test
#include <boost/test/unit_test.hpp>
#include <boost/test/tools/assertion.hpp>
#include <boost/test/utils/is_forward_iterable.hpp>
#include <boost/noncopyable.hpp>
#include <map>
#include <set>
namespace utf = boost::unit_test;
//____________________________________________________________________________//
#define EXPR_TYPE( expr ) ( assertion::seed() ->* expr )
#if !defined(BOOST_TEST_FWD_ITERABLE_CXX03)
// some broken compilers do not implement properly decltype on expressions
// partial implementation of is_forward_iterable when decltype not available
struct not_fwd_iterable_1 {
typedef int const_iterator;
typedef int value_type;
bool size();
};
struct not_fwd_iterable_2 {
typedef int const_iterator;
typedef int value_type;
bool begin();
};
struct not_fwd_iterable_3 {
typedef int value_type;
bool begin();
bool size();
};
// this one does not have const_iterator, but should be forward iterable
struct fwd_iterable_4 {
typedef int value_type;
struct iterator {
typedef unsigned int value_type;
};
iterator begin();
iterator end();
bool size();
};
struct fwd_iterable_custom {
typedef std::vector<int>::const_iterator custom_iterator; // named "exotic" on purpose
custom_iterator begin() const { return values.begin(); }
custom_iterator end() const { return values.end(); }
#if !defined(BOOST_MSVC) || (BOOST_MSVC_FULL_VER > 180040629)
#define MY_TEST_HAS_INIT_LIST
fwd_iterable_custom(std::initializer_list<int> ilist) : values{ilist}
{}
#else
fwd_iterable_custom(int v1, int v2, int v3) {
values.push_back(v1);
values.push_back(v2);
values.push_back(v3);
}
#endif
private:
std::vector<int> values;
};
BOOST_AUTO_TEST_CASE( test_forward_iterable_concept )
{
{
typedef std::vector<int> type;
BOOST_CHECK_MESSAGE(utf::ut_detail::has_member_size<type>::value, "has_member_size failed");
BOOST_CHECK_MESSAGE(utf::ut_detail::has_member_begin<type>::value, "has_member_begin failed");
BOOST_CHECK_MESSAGE(utf::ut_detail::has_member_end<type>::value, "has_member_end failed");
BOOST_CHECK_MESSAGE(utf::is_forward_iterable< type >::value, "is_forward_iterable failed");
BOOST_CHECK_MESSAGE(utf::is_container_forward_iterable< type >::value, "is_container_forward_iterable failed");
}
{
// should also work for references, but from is_forward_iterable
typedef std::vector<int>& type;
BOOST_CHECK_MESSAGE(utf::is_forward_iterable< type >::value, "is_forward_iterable failed");
BOOST_CHECK_MESSAGE(utf::is_container_forward_iterable< type >::value, "is_container_forward_iterable failed");
}
{
typedef std::list<int> type;
BOOST_CHECK_MESSAGE(utf::ut_detail::has_member_size<type>::value, "has_member_size failed");
BOOST_CHECK_MESSAGE(utf::ut_detail::has_member_begin<type>::value, "has_member_begin failed");
BOOST_CHECK_MESSAGE(utf::ut_detail::has_member_end<type>::value, "has_member_end failed");
BOOST_CHECK_MESSAGE(utf::is_forward_iterable< type >::value, "is_forward_iterable failed");
BOOST_CHECK_MESSAGE(utf::is_container_forward_iterable< type >::value, "is_container_forward_iterable failed");
}
{
typedef std::map<int, int> type;
BOOST_CHECK_MESSAGE(utf::ut_detail::has_member_size<type>::value, "has_member_size failed");
BOOST_CHECK_MESSAGE(utf::ut_detail::has_member_begin<type>::value, "has_member_begin failed");
BOOST_CHECK_MESSAGE(utf::ut_detail::has_member_end<type>::value, "has_member_end failed");
BOOST_CHECK_MESSAGE(utf::is_forward_iterable< type >::value, "is_forward_iterable failed");
BOOST_CHECK_MESSAGE(utf::is_container_forward_iterable< type >::value, "is_container_forward_iterable failed");
}
{
typedef std::set<int> type;
BOOST_CHECK_MESSAGE(utf::ut_detail::has_member_size<type>::value, "has_member_size failed");
BOOST_CHECK_MESSAGE(utf::ut_detail::has_member_begin<type>::value, "has_member_begin failed");
BOOST_CHECK_MESSAGE(utf::ut_detail::has_member_end<type>::value, "has_member_end failed");
BOOST_CHECK_MESSAGE(utf::is_forward_iterable< type >::value, "is_forward_iterable failed");
BOOST_CHECK_MESSAGE(utf::is_container_forward_iterable< type >::value, "is_container_forward_iterable failed");
}
{
typedef float type;
BOOST_CHECK_MESSAGE(!utf::ut_detail::has_member_size<type>::value, "has_member_size failed");
BOOST_CHECK_MESSAGE(!utf::ut_detail::has_member_begin<type>::value, "has_member_begin failed");
BOOST_CHECK_MESSAGE(!utf::is_forward_iterable< type >::value, "is_forward_iterable failed");
BOOST_CHECK_MESSAGE(!utf::is_container_forward_iterable< type >::value, "is_container_forward_iterable failed");
}
{
typedef not_fwd_iterable_1 type;
BOOST_CHECK_MESSAGE(utf::ut_detail::has_member_size<type>::value, "has_member_size failed");
BOOST_CHECK_MESSAGE(!utf::ut_detail::has_member_begin<type>::value, "has_member_begin failed");
BOOST_CHECK_MESSAGE(!utf::ut_detail::has_member_end<type>::value, "has_member_end failed");
BOOST_CHECK_MESSAGE(!utf::is_forward_iterable< type >::value, "is_forward_iterable failed");
BOOST_CHECK_MESSAGE(!utf::is_container_forward_iterable< type >::value, "is_container_forward_iterable failed");
}
{
typedef not_fwd_iterable_2 type;
BOOST_CHECK_MESSAGE(!utf::ut_detail::has_member_size<type>::value, "has_member_size failed");
BOOST_CHECK_MESSAGE(utf::ut_detail::has_member_begin<type>::value, "has_member_begin failed");
BOOST_CHECK_MESSAGE(!utf::ut_detail::has_member_end<type>::value, "has_member_end failed");
BOOST_CHECK_MESSAGE(!utf::is_forward_iterable< type >::value, "is_forward_iterable failed");
BOOST_CHECK_MESSAGE(!utf::is_container_forward_iterable< type >::value, "is_container_forward_iterable failed");
}
{
typedef not_fwd_iterable_3 type;
BOOST_CHECK_MESSAGE(utf::ut_detail::has_member_size<type>::value, "has_member_size failed");
BOOST_CHECK_MESSAGE(utf::ut_detail::has_member_begin<type>::value, "has_member_begin failed");
BOOST_CHECK_MESSAGE(!utf::ut_detail::has_member_end<type>::value, "has_member_end failed");
BOOST_CHECK_MESSAGE(!utf::is_forward_iterable< type >::value, "is_forward_iterable failed");
BOOST_CHECK_MESSAGE(!utf::is_container_forward_iterable< type >::value, "is_container_forward_iterable failed");
}
{
typedef fwd_iterable_4 type;
BOOST_CHECK_MESSAGE(utf::ut_detail::has_member_size<type>::value, "has_member_size failed");
BOOST_CHECK_MESSAGE(utf::ut_detail::has_member_begin<type>::value, "has_member_begin failed");
BOOST_CHECK_MESSAGE(utf::ut_detail::has_member_end<type>::value, "has_member_end failed");
BOOST_CHECK_MESSAGE(utf::is_forward_iterable< type >::value, "is_forward_iterable failed");
BOOST_CHECK_MESSAGE(!utf::is_container_forward_iterable< type >::value, "is_container_forward_iterable failed");
}
{
// for this one we should be able to get the size
typedef fwd_iterable_custom type;
BOOST_CHECK_MESSAGE(!utf::ut_detail::has_member_size<type>::value, "has_member_size failed");
BOOST_CHECK_MESSAGE(utf::ut_detail::has_member_begin<type>::value, "has_member_begin failed");
BOOST_CHECK_MESSAGE(utf::ut_detail::has_member_end<type>::value, "has_member_end failed");
BOOST_CHECK_MESSAGE(utf::is_forward_iterable< type >::value, "is_forward_iterable failed");
BOOST_CHECK_MESSAGE(!utf::is_container_forward_iterable< type >::value, "is_container_forward_iterable failed");
#ifdef MY_TEST_HAS_INIT_LIST
fwd_iterable_custom a{3,4,5};
#else
fwd_iterable_custom a(3,4,5);
#endif
BOOST_TEST( utf::bt_iterator_traits<fwd_iterable_custom>::size(a) == 3 );
}
{
typedef char type;
BOOST_CHECK_MESSAGE(!utf::ut_detail::has_member_size<type>::value, "has_member_size failed");
BOOST_CHECK_MESSAGE(!utf::ut_detail::has_member_begin<type>::value, "has_member_begin failed");
BOOST_CHECK_MESSAGE(!utf::ut_detail::has_member_end<type>::value, "has_member_end failed");
BOOST_CHECK_MESSAGE(!utf::is_forward_iterable< type >::value, "is_forward_iterable failed");
BOOST_CHECK_MESSAGE(!utf::is_container_forward_iterable< type >::value, "is_container_forward_iterable failed");
}
{
// C-tables are in the forward_iterable concept, but are not containers
typedef int type[10];
BOOST_CHECK_MESSAGE(!utf::ut_detail::has_member_size<type>::value, "has_member_size failed");
BOOST_CHECK_MESSAGE(utf::ut_detail::has_member_begin<type>::value, "has_member_begin failed");
BOOST_CHECK_MESSAGE(utf::ut_detail::has_member_end<type>::value, "has_member_end failed");
BOOST_CHECK_MESSAGE(utf::is_forward_iterable< type >::value, "is_forward_iterable failed");
BOOST_CHECK_MESSAGE(!utf::is_container_forward_iterable< type >::value, "is_container_forward_iterable failed");
}
{
// basic_cstring should be forward iterable and container
typedef boost::unit_test::basic_cstring<char> type;
BOOST_CHECK_MESSAGE(utf::ut_detail::has_member_size<type>::value, "has_member_size failed");
BOOST_CHECK_MESSAGE(utf::ut_detail::has_member_begin<type>::value, "has_member_begin failed");
BOOST_CHECK_MESSAGE(utf::ut_detail::has_member_end<type>::value, "has_member_end failed");
BOOST_CHECK_MESSAGE(utf::is_forward_iterable< type >::value, "is_forward_iterable failed");
BOOST_CHECK_MESSAGE(utf::is_container_forward_iterable< type >::value, "is_container_forward_iterable failed");
typedef boost::unit_test::basic_cstring<const char> type2;
BOOST_CHECK_MESSAGE(utf::ut_detail::has_member_size<type2>::value, "has_member_size failed");
BOOST_CHECK_MESSAGE(utf::ut_detail::has_member_begin<type2>::value, "has_member_begin failed");
BOOST_CHECK_MESSAGE(utf::ut_detail::has_member_end<type2>::value, "has_member_end failed");
BOOST_CHECK_MESSAGE(utf::is_forward_iterable< type2 >::value, "is_forward_iterable failed");
BOOST_CHECK_MESSAGE(utf::is_container_forward_iterable< type2 >::value, "is_container_forward_iterable failed");
}
}
//is_container_forward_iterable_impl
#endif
BOOST_AUTO_TEST_CASE( test_basic_value_expression_construction )
{
using namespace boost::test_tools;
{
predicate_result const& res = EXPR_TYPE( 1 ).evaluate();
BOOST_TEST( res );
BOOST_TEST( res.message().is_empty() );
}
{
predicate_result const& res = EXPR_TYPE( 0 ).evaluate();
BOOST_TEST( !res );
BOOST_TEST( res.message() == " ['0' evaluates to false]" );
}
{
predicate_result const& res = EXPR_TYPE( true ).evaluate();
BOOST_TEST( res );
BOOST_TEST( res.message().is_empty() );
}
{
predicate_result const& res = EXPR_TYPE( 1.5 ).evaluate();
BOOST_TEST( res );
}
{
predicate_result const& res = EXPR_TYPE( "abc" ).evaluate();
BOOST_TEST( res );
}
{
predicate_result const& res = EXPR_TYPE( 1>2 ).evaluate();
BOOST_TEST( !res );
BOOST_TEST( res.message() == " [1 <= 2]" );
}
}
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test_comparison_expression )
{
using namespace boost::test_tools;
{
predicate_result const& res = EXPR_TYPE( 1>2 ).evaluate();
BOOST_TEST( !res );
BOOST_TEST( res.message() == " [1 <= 2]" );
}
{
predicate_result const& res = EXPR_TYPE( 100 < 50 ).evaluate();
BOOST_TEST( !res );
BOOST_TEST( res.message() == " [100 >= 50]" );
}
{
predicate_result const& res = EXPR_TYPE( 5 <= 4 ).evaluate();
BOOST_TEST( !res );
BOOST_TEST( res.message() == " [5 > 4]" );
}
{
predicate_result const& res = EXPR_TYPE( 10>=20 ).evaluate();
BOOST_TEST( !res );
BOOST_TEST( res.message() == " [10 < 20]" );
}
{
int i = 10;
predicate_result const& res = EXPR_TYPE( i != 10 ).evaluate();
BOOST_TEST( !res );
BOOST_TEST( res.message() == " [10 == 10]" );
}
{
int i = 5;
predicate_result const& res = EXPR_TYPE( i == 3 ).evaluate();
BOOST_TEST( !res );
BOOST_TEST( res.message() == " [5 != 3]" );
}
}
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test_arithmetic_ops )
{
using namespace boost::test_tools;
{
int i = 3;
int j = 5;
predicate_result const& res = EXPR_TYPE( i+j !=8 ).evaluate();
BOOST_TEST( !res );
BOOST_TEST( res.message() == " [3 + 5 == 8]" );
}
{
int i = 3;
int j = 5;
predicate_result const& res = EXPR_TYPE( 2*i-j > 1 ).evaluate();
BOOST_TEST( !res );
BOOST_TEST( res.message() == " [2 * 3 - 5 <= 1]" );
}
{
int j = 5;
predicate_result const& res = EXPR_TYPE( 2<<j < 30 ).evaluate();
BOOST_TEST( !res );
BOOST_TEST( res.message() == " [2 << 5 >= 30]" );
}
{
int i = 2;
int j = 5;
predicate_result const& res = EXPR_TYPE( i&j ).evaluate();
BOOST_TEST( !res );
BOOST_TEST( res.message() == " [2 & 5]" );
}
{
int i = 3;
int j = 5;
predicate_result const& res = EXPR_TYPE( i^j^6 ).evaluate();
BOOST_TEST( !res );
BOOST_TEST( res.message() == " [3 ^ 5 ^ 6]" );
}
// do not support
// EXPR_TYPE( 99/2 == 48 || 101/2 > 50 );
// EXPR_TYPE( a ? 100 < 50 : 25*2 == 50 );
// EXPR_TYPE( true,false );
}
//____________________________________________________________________________//
struct Testee {
static int s_copy_counter;
Testee() : m_value( false ) {}
Testee( Testee const& ) : m_value(false) { s_copy_counter++; }
Testee( Testee&& ) : m_value(false) {}
Testee( Testee const&& ) : m_value(false) {}
bool foo() { return m_value; }
operator bool() const { return m_value; }
friend std::ostream& operator<<( std::ostream& ostr, Testee const& ) { return ostr << "Testee"; }
bool m_value;
};
int Testee::s_copy_counter = 0;
Testee get_obj() { return Testee(); }
Testee const get_const_obj() { return Testee(); }
class NC : boost::noncopyable {
public:
NC() {}
bool operator==(NC const&) const { return false; }
friend std::ostream& operator<<(std::ostream& ostr, NC const&)
{
return ostr << "NC";
}
};
BOOST_AUTO_TEST_CASE( test_objects )
{
using namespace boost::test_tools;
int expected_copy_count = 0;
{
Testee obj;
Testee::s_copy_counter = 0;
predicate_result const& res = EXPR_TYPE( obj ).evaluate();
BOOST_TEST( !res );
BOOST_TEST( res.message() == " ['Testee' evaluates to false]" );
BOOST_TEST( Testee::s_copy_counter == expected_copy_count );
}
{
Testee const obj;
Testee::s_copy_counter = 0;
predicate_result const& res = EXPR_TYPE( obj ).evaluate();
BOOST_TEST( !res );
BOOST_TEST( res.message() == " ['Testee' evaluates to false]" );
BOOST_TEST( Testee::s_copy_counter == expected_copy_count );
}
{
Testee::s_copy_counter = 0;
predicate_result const& res = EXPR_TYPE( get_obj() ).evaluate();
BOOST_TEST( !res );
BOOST_TEST( res.message() == " ['Testee' evaluates to false]" );
BOOST_TEST( Testee::s_copy_counter == expected_copy_count );
}
{
Testee::s_copy_counter = 0;
predicate_result const& res = EXPR_TYPE( get_const_obj() ).evaluate();
BOOST_TEST( !res );
BOOST_TEST( res.message() == " ['Testee' evaluates to false]" );
BOOST_TEST( Testee::s_copy_counter == expected_copy_count );
}
{
Testee::s_copy_counter = 0;
Testee t1;
Testee t2;
predicate_result const& res = EXPR_TYPE( t1 != t2 ).evaluate();
BOOST_TEST( !res );
BOOST_TEST( res.message() == " [Testee == Testee]" );
BOOST_TEST( Testee::s_copy_counter == 0 );
}
{
NC nc1;
NC nc2;
predicate_result const& res = EXPR_TYPE( nc1 == nc2 ).evaluate();
BOOST_TEST( !res );
BOOST_TEST( res.message() == " [NC != NC]" );
}
}
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test_pointers )
{
using namespace boost::test_tools;
{
Testee* ptr = 0;
predicate_result const& res = EXPR_TYPE( ptr ).evaluate();
BOOST_TEST( !res );
}
{
Testee obj1;
Testee obj2;
predicate_result const& res = EXPR_TYPE( &obj1 == &obj2 ).evaluate();
BOOST_TEST( !res );
}
{
Testee obj;
Testee* ptr =&obj;
predicate_result const& res = EXPR_TYPE( *ptr ).evaluate();
BOOST_TEST( !res );
BOOST_TEST( res.message() == " ['Testee' evaluates to false]" );
}
{
Testee obj;
Testee* ptr =&obj;
bool Testee::* mem_ptr =&Testee::m_value;
predicate_result const& res = EXPR_TYPE( ptr->*mem_ptr ).evaluate();
BOOST_TEST( !res );
}
// do not support
// Testee obj;
// bool Testee::* mem_ptr =&Testee::m_value;
// EXPR_TYPE( obj.*mem_ptr );
}
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test_mutating_ops )
{
using namespace boost::test_tools;
{
int j = 5;
predicate_result const& res = EXPR_TYPE( j = 0 ).evaluate();
BOOST_TEST( !res );
BOOST_TEST( res.message() == " ['0' evaluates to false]" );
BOOST_TEST( j == 0 );
}
{
int j = 5;
predicate_result const& res = EXPR_TYPE( j -= 5 ).evaluate();
BOOST_TEST( !res );
BOOST_TEST( res.message() == " ['0' evaluates to false]" );
BOOST_TEST( j == 0 );
}
{
int j = 5;
predicate_result const& res = EXPR_TYPE( j *= 0 ).evaluate();
BOOST_TEST( !res );
BOOST_TEST( res.message() == " ['0' evaluates to false]" );
BOOST_TEST( j == 0 );
}
{
int j = 5;
predicate_result const& res = EXPR_TYPE( j /= 10 ).evaluate();
BOOST_TEST( !res );
BOOST_TEST( res.message() == " ['0' evaluates to false]" );
BOOST_TEST( j == 0 );
}
{
int j = 4;
predicate_result const& res = EXPR_TYPE( j %= 2 ).evaluate();
BOOST_TEST( !res );
BOOST_TEST( res.message() == " ['0' evaluates to false]" );
BOOST_TEST( j == 0 );
}
{
int j = 5;
predicate_result const& res = EXPR_TYPE( j ^= j ).evaluate();
BOOST_TEST( !res );
BOOST_TEST( res.message() == " ['0' evaluates to false]" );
BOOST_TEST( j == 0 );
}
}
BOOST_AUTO_TEST_CASE( test_specialized_comparator_string )
{
using namespace boost::test_tools;
{
std::string s("abc");
predicate_result const& res = EXPR_TYPE( s == "a" ).evaluate();
BOOST_TEST( !res );
BOOST_TEST( res.message() == " [abc != a]" );
BOOST_TEST( s == "abc" );
}
{
predicate_result const& res = EXPR_TYPE( std::string("abc") == "a" ).evaluate();
BOOST_TEST( !res );
BOOST_TEST( res.message() == " [abc != a]" );
}
{
predicate_result const& res = EXPR_TYPE( "abc" == std::string("a") ).evaluate();
BOOST_TEST( !res );
BOOST_TEST( res.message() == " [abc != a]" );
}
{
predicate_result const& res = EXPR_TYPE( std::string("abc") == std::string("a") ).evaluate();
BOOST_TEST( !res );
BOOST_TEST( res.message() == " [abc != a]" );
}
}
BOOST_AUTO_TEST_CASE( test_comparison_with_arrays )
{
using namespace boost::test_tools;
{
char c_string_array[] = "abc";
predicate_result const& res = EXPR_TYPE( c_string_array == "a" ).evaluate();
BOOST_TEST( !res );
BOOST_TEST( res.message() == " [abc != a]" );
BOOST_TEST( c_string_array == "abc" );
}
{
char c_string_array[] = "abc";
predicate_result const& res = EXPR_TYPE( "a" == c_string_array ).evaluate();
BOOST_TEST( !res );
BOOST_TEST( res.message() == " [a != abc]" );
BOOST_TEST( "abc" == c_string_array );
}
{
char const c_string_array[] = "abc";
predicate_result const& res = EXPR_TYPE( c_string_array == "a" ).evaluate();
BOOST_TEST( !res );
BOOST_TEST( res.message() == " [abc != a]" );
BOOST_TEST( c_string_array == "abc" );
}
{
char const c_string_array[] = "abc";
predicate_result const& res = EXPR_TYPE( "a" == c_string_array ).evaluate();
BOOST_TEST( !res );
BOOST_TEST( res.message() == " [a != abc]" );
BOOST_TEST( "abc" == c_string_array );
}
{
long int c_long_array[] = {3,4,7};
std::vector<long int> v_long_array(c_long_array, c_long_array + sizeof(c_long_array)/sizeof(c_long_array[0]));
std::swap(v_long_array[1], v_long_array[2]);
predicate_result const& res = EXPR_TYPE( c_long_array == v_long_array ).evaluate();
BOOST_TEST( !res );
BOOST_TEST( res.message() == ": \n - mismatch at position 1: [4 == 7] is false\n - mismatch at position 2: [7 == 4] is false" );
std::swap(v_long_array[1], v_long_array[2]);
BOOST_TEST( c_long_array == v_long_array );
}
{
long int c_long_array[] = {3,4,7};
std::vector<long int> v_long_array(c_long_array, c_long_array + sizeof(c_long_array)/sizeof(c_long_array[0]));
std::swap(v_long_array[1], v_long_array[2]);
predicate_result const& res = EXPR_TYPE( v_long_array == c_long_array ).evaluate();
BOOST_TEST( !res );
BOOST_TEST( res.message() == ": \n - mismatch at position 1: [7 == 4] is false\n - mismatch at position 2: [4 == 7] is false" );
std::swap(v_long_array[1], v_long_array[2]);
BOOST_TEST( c_long_array == v_long_array );
}
{
long int const c_long_array[] = {3,4,7};
std::vector<long int> v_long_array(c_long_array, c_long_array + sizeof(c_long_array)/sizeof(c_long_array[0]));
std::swap(v_long_array[1], v_long_array[2]);
predicate_result const& res = EXPR_TYPE( c_long_array == v_long_array ).evaluate();
BOOST_TEST( !res );
BOOST_TEST( res.message() == ": \n - mismatch at position 1: [4 == 7] is false\n - mismatch at position 2: [7 == 4] is false" );
std::swap(v_long_array[1], v_long_array[2]);
BOOST_TEST( c_long_array == v_long_array );
}
{
long int const c_long_array[] = {3,4,7};
std::vector<long int> v_long_array(c_long_array, c_long_array + sizeof(c_long_array)/sizeof(c_long_array[0]));
std::swap(v_long_array[1], v_long_array[2]);
predicate_result const& res = EXPR_TYPE( v_long_array == c_long_array ).evaluate();
BOOST_TEST( !res );
BOOST_TEST( res.message() == ": \n - mismatch at position 1: [7 == 4] is false\n - mismatch at position 2: [4 == 7] is false" );
std::swap(v_long_array[1], v_long_array[2]);
BOOST_TEST( c_long_array == v_long_array );
}
}
// EOF

View File

@@ -0,0 +1,214 @@
// (C) Copyright Gennadiy Rozental 2001-2015.
// 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)
// See http://www.boost.org/libs/test for the library home page.
//
// File : $RCSfile$
//
// Version : $Revision$
//
// Description : unit test for string comparison specializations
// *****************************************************************************
#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>
#include <boost/test/utils/is_cstring.hpp>
BOOST_AUTO_TEST_CASE( check_is_cstring_concept )
{
namespace bp = boost::unit_test;
BOOST_TEST((bp::is_cstring<char const*>::value));
BOOST_TEST((bp::is_cstring<char const []>::value));
BOOST_TEST((bp::is_cstring<char []>::value));
BOOST_TEST((bp::is_cstring<char *>::value));
BOOST_TEST((!bp::is_cstring<std::string>::value));
BOOST_TEST((!bp::is_cstring< bp::basic_cstring<char> >::value));
BOOST_TEST((!bp::is_cstring< std::vector<char> >::value));
}
#if defined(BOOST_TEST_STRING_VIEW)
BOOST_AUTO_TEST_CASE( check_is_cstring_concept_string_view )
{
namespace bp = boost::unit_test;
BOOST_TEST((!bp::is_cstring< std::string_view >::value));
}
#endif
BOOST_AUTO_TEST_CASE( check_is_cstring_comparable_concept )
{
namespace bp = boost::unit_test;
BOOST_TEST((bp::is_cstring_comparable<char const*>::value));
BOOST_TEST((bp::is_cstring_comparable<char const []>::value));
BOOST_TEST((bp::is_cstring_comparable<char []>::value));
BOOST_TEST((bp::is_cstring_comparable<char *>::value));
BOOST_TEST((bp::is_cstring_comparable<std::string>::value));
BOOST_TEST((bp::is_cstring_comparable< bp::basic_cstring<char> >::value));
BOOST_TEST((!bp::is_cstring_comparable< std::vector<char> >::value));
}
#if defined(BOOST_TEST_STRING_VIEW)
BOOST_AUTO_TEST_CASE( check_is_cstring_comparable_concept_string_view )
{
namespace bp = boost::unit_test;
BOOST_TEST((bp::is_cstring_comparable< std::string_view >::value));
}
#endif
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( check_string_compare )
{
char const* buf_ptr_cch = "0abc";
char const buf_array_cch[] = "1abc";
char buf_array_ch[] = "2abc";
char* buf_ptr_ch = buf_array_ch + 1;
std::string buf_str = "3abc";
buf_ptr_cch++;
buf_str = buf_str.substr(1);
BOOST_TEST((void*)buf_ptr_cch != (void*)(buf_array_cch + 1));
BOOST_TEST((void*)buf_ptr_cch != (void*)(buf_array_ch + 1));
BOOST_TEST((void*)(buf_array_cch +1) != (void*)(buf_array_ch + 1));
BOOST_TEST(buf_ptr_cch == buf_ptr_cch);
#ifndef BOOST_TEST_MACRO_LIMITED_SUPPORT
BOOST_TEST(buf_ptr_cch == (buf_array_cch + 1));
BOOST_TEST(buf_ptr_cch == (buf_array_ch + 1));
BOOST_TEST(buf_ptr_cch == buf_ptr_ch);
BOOST_TEST(buf_ptr_cch == buf_str);
#endif
#ifndef BOOST_TEST_MACRO_LIMITED_SUPPORT
BOOST_TEST((buf_array_cch + 1) == buf_ptr_cch);
BOOST_TEST((buf_array_cch + 1) == (buf_array_cch + 1));
BOOST_TEST((buf_array_cch + 1) == buf_ptr_ch);
BOOST_TEST((buf_array_cch + 1) == (buf_array_ch + 1));
BOOST_TEST((buf_array_cch + 1) == buf_str);
#endif
BOOST_TEST(buf_ptr_ch == buf_ptr_ch);
#ifndef BOOST_TEST_MACRO_LIMITED_SUPPORT
BOOST_TEST(buf_ptr_ch == buf_ptr_cch);
BOOST_TEST(buf_ptr_ch == (buf_array_cch + 1));
BOOST_TEST(buf_ptr_ch == (buf_array_ch + 1));
BOOST_TEST(buf_ptr_ch == buf_str);
#endif
#ifndef BOOST_TEST_MACRO_LIMITED_SUPPORT
BOOST_TEST((buf_array_ch + 1) == buf_ptr_cch);
BOOST_TEST((buf_array_ch + 1) == (buf_array_cch + 1));
BOOST_TEST((buf_array_ch + 1) == buf_ptr_ch);
BOOST_TEST((buf_array_ch + 1) == (buf_array_ch + 1));
BOOST_TEST((buf_array_ch + 1) == buf_str);
#endif
BOOST_TEST(buf_str == buf_ptr_cch);
BOOST_TEST(buf_str == (buf_array_cch + 1));
BOOST_TEST(buf_str == buf_ptr_ch);
BOOST_TEST(buf_str == (buf_array_ch + 1));
BOOST_TEST(buf_str == buf_str);
BOOST_TEST(buf_ptr_cch == buf_str);
//BOOST_TEST((buf_array_cch + 1) == buf_str); // does not compile
BOOST_TEST(buf_ptr_ch == buf_str);
//BOOST_TEST((buf_array_ch + 1) == buf_str); // does not compile
BOOST_TEST(buf_str == buf_str);
#ifndef BOOST_TEST_MACRO_LIMITED_SUPPORT
BOOST_TEST( buf_ptr_cch == buf_ptr_cch, boost::test_tools::per_element() );
BOOST_TEST( buf_ptr_cch <= "abd" , boost::test_tools::per_element() );
BOOST_TEST( buf_ptr_cch >= "aba" , boost::test_tools::per_element() );
BOOST_TEST( buf_str == buf_ptr_cch , boost::test_tools::per_element() );
BOOST_TEST( buf_str <= "abd" , boost::test_tools::per_element() );
BOOST_TEST( buf_str >= "aba" , boost::test_tools::per_element() );
BOOST_TEST( buf_ptr_cch <= buf_ptr_cch, boost::test_tools::lexicographic() );
BOOST_TEST( buf_ptr_cch >= buf_ptr_cch, boost::test_tools::lexicographic() );
BOOST_TEST( buf_ptr_cch <= "abc" , boost::test_tools::lexicographic() );
BOOST_TEST( buf_ptr_cch < "abd" , boost::test_tools::lexicographic() );
BOOST_TEST( buf_ptr_cch < "abcd" , boost::test_tools::lexicographic() );
BOOST_TEST( buf_ptr_cch >= "abc" , boost::test_tools::lexicographic() );
BOOST_TEST( buf_ptr_cch > "aba" , boost::test_tools::lexicographic() );
BOOST_TEST( buf_ptr_cch > "abad" , boost::test_tools::lexicographic() );
BOOST_TEST( buf_str <= buf_ptr_cch , boost::test_tools::lexicographic() );
BOOST_TEST( buf_str >= buf_ptr_cch , boost::test_tools::lexicographic() );
BOOST_TEST( buf_str <= "abc" , boost::test_tools::lexicographic() );
BOOST_TEST( buf_str < "abd" , boost::test_tools::lexicographic() );
BOOST_TEST( buf_str > "aba" , boost::test_tools::lexicographic() );
#endif
}
#if defined(BOOST_TEST_STRING_VIEW)
BOOST_AUTO_TEST_CASE( check_string_view_compare )
{
namespace bp = boost::unit_test;
using namespace std::literals;
std::string str = "str";
std::string_view sv = "sv";
BOOST_TEST((!bp::is_cstring< decltype(sv) >::value));
BOOST_TEST_CHECK(str == str);
BOOST_TEST_CHECK(sv == sv);
BOOST_TEST_CHECK(str != sv);
BOOST_TEST_CHECK(sv != str);
// comparisons based on size
BOOST_TEST_CHECK(str >= sv);
BOOST_TEST_CHECK(sv <= str);
BOOST_TEST_CHECK(str > sv);
BOOST_TEST_CHECK(sv < str);
BOOST_TEST_CHECK(str <= sv, boost::test_tools::lexicographic());
BOOST_TEST_CHECK(sv >= str, boost::test_tools::lexicographic());
BOOST_TEST_CHECK(str < sv, boost::test_tools::lexicographic());
BOOST_TEST_CHECK(sv > str, boost::test_tools::lexicographic());
std::string_view s1 = "this_is_string_view"sv;
BOOST_TEST(s1 == s1);
BOOST_TEST(s1 <= s1);
BOOST_TEST(s1 >= s1);
BOOST_TEST(s1 == "this_is_string_view"s);
BOOST_TEST(s1 <= "this_is_string_view2"sv);
// lexicographic compare
BOOST_TEST_CHECK("str" <= sv, boost::test_tools::lexicographic());
BOOST_TEST_CHECK(sv >= "str", boost::test_tools::lexicographic());
BOOST_TEST_CHECK("str" < sv, boost::test_tools::lexicographic());
BOOST_TEST_CHECK(sv > "str", boost::test_tools::lexicographic());
BOOST_TEST_CHECK("str"sv <= sv, boost::test_tools::lexicographic());
BOOST_TEST_CHECK(sv >= "str"sv, boost::test_tools::lexicographic());
BOOST_TEST_CHECK("str"sv < sv, boost::test_tools::lexicographic());
BOOST_TEST_CHECK(sv > "str"sv, boost::test_tools::lexicographic());
// per element, left-right operand
BOOST_TEST( "sv" <= sv , boost::test_tools::per_element() );
BOOST_TEST( "sv" >= sv , boost::test_tools::per_element() );
BOOST_TEST( "sv" == sv , boost::test_tools::per_element() );
BOOST_TEST( sv <= "sv" , boost::test_tools::per_element() );
BOOST_TEST( sv >= "sv" , boost::test_tools::per_element() );
BOOST_TEST( sv == "sv" , boost::test_tools::per_element() );
BOOST_TEST( "rv" <= sv , boost::test_tools::per_element() );
BOOST_TEST( "tv" >= sv , boost::test_tools::per_element() );
BOOST_TEST( "tw" != sv , boost::test_tools::per_element() );
BOOST_TEST( sv <= "tv" , boost::test_tools::per_element() );
BOOST_TEST( sv >= "rv" , boost::test_tools::per_element() );
BOOST_TEST( sv != "ru" , boost::test_tools::per_element() );
}
#endif
// EOF

View File

@@ -0,0 +1,193 @@
// (C) Copyright Gennadiy Rozental 2015.
// 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)
// See http://www.boost.org/libs/test for the library home page.
//
/// @file
/// @brief tests collection comparison implementation
// ***************************************************************************
// Boost.Test
#define BOOST_TEST_MODULE Test collection`s comparisons
#include <boost/test/unit_test.hpp>
namespace tt = boost::test_tools;
namespace ut = boost::unit_test;
BOOST_TEST_SPECIALIZED_COLLECTION_COMPARE(std::vector<int>)
#define VALIDATE_OP( op ) \
{ \
BOOST_TEST_INFO( "validating operator " #op ); \
bool expected = (c1 op c2); \
auto const& res = (tt::assertion::seed()->* c1 op c2).evaluate(); \
BOOST_TEST( expected == !!res ); \
} \
/**/
template<typename Col>
void
validate_comparisons(Col const& c1, Col const& c2 )
{
VALIDATE_OP( == )
VALIDATE_OP( != )
VALIDATE_OP( < )
VALIDATE_OP( > )
VALIDATE_OP( <= )
VALIDATE_OP( >= )
}
BOOST_AUTO_TEST_CASE( test_against_overloaded_comp_op )
{
std::vector<int> a{1, 2, 3};
std::vector<int> b{1, 3, 2};
std::vector<int> c{1, 2, 3};
std::vector<int> d{1, 2, 3, 4};
BOOST_TEST_CONTEXT( "validating comparisons of a and b" )
validate_comparisons(a, b);
BOOST_TEST_CONTEXT( "validating comparisons of a and c" )
validate_comparisons(a, c);
BOOST_TEST_CONTEXT( "validating comparisons of a and d" )
validate_comparisons(a, d);
}
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test_per_element_eq, * ut::expected_failures(2) )
{
std::vector<int> a{1, 2, 3};
std::vector<int> b{1, 3, 2};
BOOST_TEST( a == b, tt::per_element() );
}
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test_per_element_ne, * ut::expected_failures(1) )
{
std::vector<int> a{1, 2, 3};
std::vector<int> b{1, 3, 2};
BOOST_TEST( a != b, tt::per_element() );
}
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test_per_element_lt, * ut::expected_failures(2) )
{
std::vector<int> a{1, 2, 3};
std::vector<int> b{1, 3, 2};
BOOST_TEST( a < b, tt::per_element() );
}
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test_per_element_ge, * ut::expected_failures(1) )
{
std::vector<int> a{1, 2, 3};
std::vector<int> b{1, 3, 2};
BOOST_TEST( b >= a, tt::per_element() );
}
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test_lexicographic_lt )
{
std::vector<int> a{1, 2, 3};
std::vector<int> b{1, 3, 2};
BOOST_TEST( a < b, tt::lexicographic() );
}
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test_lexicographic_le )
{
std::vector<int> a{1, 2, 3};
std::vector<int> b{1, 3, 2};
BOOST_TEST( a <= b, tt::lexicographic() );
}
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test_lexicographic_gt )
{
std::vector<int> a{1, 2, 3};
std::vector<int> b{1, 3, 2};
BOOST_TEST( b > a, tt::lexicographic() );
}
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test_lexicographic_ge )
{
std::vector<int> a{1, 2, 3};
std::vector<int> b{1, 3, 2};
BOOST_TEST( b >= a, tt::lexicographic() );
}
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test_collection_of_collection_comp )
{
BOOST_TEST( std::string("abc") == std::string("abc") );
}
//____________________________________________________________________________//
// this one does not have const_iterator nor a size, but should be forward iterable
// and possible to use in the collection comparison
struct fwd_iterable_custom {
typedef std::vector<int>::const_iterator custom_iterator; // named "exotic" on purpose
custom_iterator begin() const { return values.begin(); }
custom_iterator end() const { return values.end(); }
#if !defined(BOOST_MSVC) || (BOOST_MSVC_FULL_VER > 180040629)
#define MY_TEST_HAS_INIT_LIST
// this does not work on VC++ 2013 update 5
fwd_iterable_custom(std::initializer_list<int> ilist) : values{ilist}
{}
#else
fwd_iterable_custom(int v1, int v2, int v3) {
values.push_back(v1);
values.push_back(v2);
values.push_back(v3);
}
#endif
private:
std::vector<int> values;
};
BOOST_AUTO_TEST_CASE( test_collection_requirement_type )
{
#ifdef MY_TEST_HAS_INIT_LIST
fwd_iterable_custom a{3,4,5};
fwd_iterable_custom b{3,4,6};
fwd_iterable_custom c{3,4,5};
#else
fwd_iterable_custom a(3,4,5);
fwd_iterable_custom b(3,4,6);
fwd_iterable_custom c(3,4,5);
#endif
BOOST_TEST( a == a, tt::per_element() );
//BOOST_TEST( a != b, tt::per_element() );
BOOST_TEST( a == c, tt::per_element() );
BOOST_TEST( a < b, tt::lexicographic() );
BOOST_TEST( a <= c, tt::lexicographic() );
BOOST_TEST( b > c, tt::lexicographic() );
BOOST_TEST( a <= b, tt::per_element() );
BOOST_TEST( a <= c, tt::per_element() );
}
// EOF

View File

@@ -0,0 +1,55 @@
// (C) Copyright Marek Kurdej 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)
// See http://www.boost.org/libs/test for the library home page.
//
//! @file
//! BOOST_TEST_DONT_PRINT_LOG_VALUE unit test
// *****************************************************************************
#define BOOST_TEST_MODULE BOOST_TEST_DONT_PRINT_LOG_VALUE unit test
#include <boost/test/unit_test.hpp>
#include <boost/test/data/test_case.hpp>
#include <boost/test/data/monomorphic.hpp>
#include <vector>
struct dummy_class {
operator bool() const { return true; }
bool operator==(dummy_class const&) const { return true; }
bool operator!=(dummy_class const&) const { return false; }
};
BOOST_TEST_DONT_PRINT_LOG_VALUE(dummy_class)
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE(single_object)
{
dummy_class actual, expected;
BOOST_TEST(actual == expected);
}
//____________________________________________________________________________//
// this one tests for contexts printing in dataset tests
std::vector<dummy_class> generate_vector()
{
std::vector<dummy_class> out;
out.push_back(dummy_class());
out.push_back(dummy_class());
out.push_back(dummy_class());
return out;
}
//____________________________________________________________________________//
BOOST_DATA_TEST_CASE( test_data_case, boost::unit_test::data::make(generate_vector()))
{
BOOST_TEST(sample);
}
// EOF

View File

@@ -0,0 +1,309 @@
// (C) Copyright Gennadiy Rozental 2001-2015.
// 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)
// See http://www.boost.org/libs/test for the library home page.
//
// File : $RCSfile$
//
// Version : $Revision$
//
// Description : tests floating point comparison algorithms
// ***************************************************************************
// Boost.Test
#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>
// Boost
#include <boost/mpl/list.hpp>
#include <boost/bind/bind.hpp>
// STL
#include <functional>
using namespace boost;
using namespace boost::unit_test;
using namespace boost::test_tools;
namespace tt=boost::test_tools;
bool not_func( bool argb ) { return !argb; }
//____________________________________________________________________________//
typedef boost::mpl::list<float,double,long double> test_types;
BOOST_AUTO_TEST_CASE_TEMPLATE( test_fp_comparizon_with_percent_tolerance, FPT, test_types )
{
#define CHECK_CLOSE( first, second, e ) \
fp1 = static_cast<FPT>(first); \
fp2 = static_cast<FPT>(second); \
epsilon = static_cast<FPT>(e); \
\
BOOST_TEST( fp1 == fp2, epsilon% tt::tolerance() ) \
/**/
#define CHECK_NOT_CLOSE( first, second, e ) \
fp1 = static_cast<FPT>(first); \
fp2 = static_cast<FPT>(second); \
epsilon = static_cast<FPT>(e); \
\
BOOST_TEST( fp1 != fp2, epsilon% tt::tolerance() ) \
/**/
FPT fp1, fp2, epsilon;
CHECK_CLOSE( 1, 1, 0 );
CHECK_CLOSE( 0, 1e-20, 1e-5 );
CHECK_CLOSE( 0, 1e-30, 1e-5 );
CHECK_CLOSE( 0, -1e-10, 0.1 );
CHECK_NOT_CLOSE( 0.123456, 0.123457, 1e-4 );
CHECK_CLOSE( 0.123456, 0.123457, 1e-3 );
CHECK_NOT_CLOSE( 0.123456, -0.123457, 1e-3 );
CHECK_CLOSE( 1.23456e28, 1.23457e28, 1e-3 );
CHECK_CLOSE( 1.23456e-10, 1.23457e-10, 1e-3 );
CHECK_NOT_CLOSE( 1.111e-10, 1.112e-10, 0.0899 );
CHECK_CLOSE( 1.112e-10, 1.111e-10, 0.1 );
CHECK_CLOSE( 1, 1.0001, 1.1e-2 );
CHECK_CLOSE( 1.0002, 1.0001, 1.1e-2 );
CHECK_NOT_CLOSE( 1, 1.0002, 1.1e-2 );
#undef CHECK_CLOSE
#undef CHECK_NOT_CLOSE
}
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE_TEMPLATE( test_fp_comparizon_with_fraction_tolerance, FPT, test_types )
{
#define CHECK_CLOSE( first, second, e ) \
fp1 = static_cast<FPT>(first); \
fp2 = static_cast<FPT>(second); \
epsilon = static_cast<FPT>(e); \
\
BOOST_TEST( fp1 == fp2, tt::tolerance(epsilon) ); \
/**/
#define CHECK_NOT_CLOSE( first, second, e ) \
fp1 = static_cast<FPT>(first); \
fp2 = static_cast<FPT>(second); \
epsilon = static_cast<FPT>(e); \
\
BOOST_TEST( fp1 != fp2, tt::tolerance(epsilon) ); \
/**/
FPT fp1, fp2, epsilon;
CHECK_CLOSE( 1, 1, 0 );
CHECK_CLOSE( 0, 1e-20, 1e-5 );
CHECK_CLOSE( 0, 1e-30, 1e-5 );
CHECK_CLOSE( 0, -1e-10, 0.1 );
CHECK_NOT_CLOSE( 0.123456, 0.123457, 1e-6 );
CHECK_CLOSE( 0.123456, 0.123457, 1e-3 );
CHECK_NOT_CLOSE( 0.123456, -0.123457, 1e-3 );
CHECK_CLOSE( 1.23456e28, 1.23457e28, 1e-3 );
CHECK_CLOSE( 1.23456e-10, 1.23457e-10, 1e-3 );
CHECK_NOT_CLOSE( 1.111e-10, 1.112e-10, 0.000899 );
CHECK_CLOSE( 1.112e-10, 1.111e-10, 0.1 );
CHECK_CLOSE( 1, 1.0001, 1.1e-2 );
CHECK_CLOSE( 1.0002, 1.0001, 1.1e-2 );
CHECK_NOT_CLOSE( 1, 1.0002, 1.1e-4 );
#undef CHECK_CLOSE
#undef CHECK_NOT_CLOSE
}
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test_type_mismatch )
{
BOOST_CHECK_CLOSE_FRACTION( 2., 2.1, 0.06 );
BOOST_CHECK_CLOSE( 2.1, 2., 6. );
BOOST_CHECK_CLOSE( 2.1, 2.f, 6. );
}
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test_strong_weak, * expected_failures( 4 ) )
{
BOOST_TEST(1./3 == 1./2, tt::tolerance(1.));
BOOST_TEST(1./3 == 1./2, tt::tolerance(0.4)); // will fail 1/2 > 0.4
BOOST_TEST(1./3 == 1./2, tt::tolerance(1./3)); // will fail; both 1/3 and 1/2 > 1/3
BOOST_TEST(1./3 != 1./2, tt::tolerance(1.)); // will fail; both 1/3 and 1/2 < 1
BOOST_TEST(1./3 != 1./2, tt::tolerance(0.4)); // will fail 1/3 < 0.4
BOOST_TEST(1./3 != 1./2, tt::tolerance(1./3));
}
BOOST_AUTO_TEST_CASE(test_strict_order_operations_ne,
* boost::unit_test::tolerance(0.01)
* expected_failures( 1 ) )
{
double x = 10.00;
double y = 10.01; // diff within tolerance
BOOST_TEST(x == y);
BOOST_TEST(x != y); // fails
BOOST_TEST(x <= y);
BOOST_TEST(x >= y);
}
BOOST_AUTO_TEST_CASE(test_strict_order_operations_lt,
* boost::unit_test::tolerance(0.01)
* expected_failures( 3 ) )
{
double x = 10.00;
double y = 10.01; // diff within tolerance
BOOST_TEST(x == y);
BOOST_TEST(x != y); // fails
BOOST_TEST(x <= y);
BOOST_TEST(y <= x);
BOOST_TEST(x < y); // fails y ~= x
BOOST_TEST(y < x); // fails, y > x
}
BOOST_AUTO_TEST_CASE(test_strict_order_operations_lt_0,
* boost::unit_test::tolerance(0.02)
* expected_failures( 3 ) )
{
double x = 0.00;
double y = 0.01;
BOOST_TEST(x == y);
BOOST_TEST(x != y); // fails
BOOST_TEST(x <= y);
BOOST_TEST(y <= x);
BOOST_TEST(x < y); // fails, too close to 0
BOOST_TEST(y < x); // fails, y > x
}
BOOST_AUTO_TEST_CASE(test_strict_order_operations_le,
* boost::unit_test::tolerance(0.01)
* expected_failures( 1 ) )
{
double x = 10.01;
double y = 10.00; // diff within tolerance
BOOST_TEST(x == y);
BOOST_TEST(x != y); // fails
BOOST_TEST(x <= y);
}
BOOST_AUTO_TEST_CASE(test_strict_order_operations_gt,
* boost::unit_test::tolerance(0.01)
* expected_failures( 3 ) )
{
double x = 10.00;
double y = 10.01; // diff within tolerance
BOOST_TEST(x == y);
BOOST_TEST(x != y); // fails
BOOST_TEST(x > y); // fails
BOOST_TEST(y > x); // fails
}
BOOST_AUTO_TEST_CASE(test_strict_order_operations_ge,
* boost::unit_test::tolerance(0.01)
* expected_failures( 1 ) )
{
double x = 10.00;
double y = 10.01; // diff within tolerance
BOOST_TEST(x == y);
BOOST_TEST(x != y); // fails
BOOST_TEST(x >= y);
BOOST_TEST(y >= x);
}
BOOST_AUTO_TEST_CASE(test_strict_order_operations_gt_0,
* boost::unit_test::tolerance(0.02)
* expected_failures( 3 ) )
{
double x = 0.00;
double y = 0.01;
BOOST_TEST(x == y);
BOOST_TEST(x != y); // fails
BOOST_TEST(x >= y);
BOOST_TEST(y >= x);
BOOST_TEST(x <= y);
BOOST_TEST(y <= x);
BOOST_TEST(x > y); // fails, too close to 0
BOOST_TEST(y > x); // fails, too close to 0
}
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test_CHECK_SMALL )
{
BOOST_CHECK_SMALL( 1e-6, 1e-5 );
BOOST_CHECK_SMALL( -1e-6, 1e-5 );
BOOST_TEST( 1e-6 != 0., 1e-7 );
}
//____________________________________________________________________________//
namespace fpc = boost::math::fpc;
BOOST_AUTO_TEST_CASE( test_close_at_tolerance )
{
double fp1 = 1.00000001;
double fp2 = 1.00000002;
double epsilon = 1e-6;
::fpc::close_at_tolerance<double> pred( ::fpc::percent_tolerance( epsilon ), ::fpc::FPC_WEAK );
BOOST_CHECK_PREDICATE( pred, (fp1)(fp2) );
#ifndef BOOST_TEST_NO_OLD_TOOLS
BOOST_TEST( !check_is_close( fp1, fp2, ::fpc::percent_tolerance( epsilon ) ) );
#endif
fp1 = 1.23456e-10;
fp2 = 1.23457e-10;
epsilon = 8.1e-4;
BOOST_CHECK_PREDICATE( ::fpc::close_at_tolerance<double>( ::fpc::percent_tolerance( epsilon ), ::fpc::FPC_WEAK ), (fp1)(fp2) );
BOOST_TEST( !::fpc::close_at_tolerance<double>( ::fpc::percent_tolerance( epsilon ) )(fp1, fp2) );
}
BOOST_AUTO_TEST_CASE( test_comparison_if_one_is_FPV, * boost::unit_test::tolerance(1E-6) )
{
BOOST_TEST(1.000001 == 1);
BOOST_TEST(1 == 1.000001);
BOOST_TEST(0.000001 == 0);
BOOST_TEST(0 == 0.000001);
}
BOOST_AUTO_TEST_CASE( test_comparison_if_one_is_FPV_2 )
{
BOOST_TEST(1.000001 == 1, tt::tolerance(1E-6));
BOOST_TEST(1 == 1.000001, tt::tolerance(1E-6));
BOOST_TEST(0.000001 == 0, tt::tolerance(1E-6));
BOOST_TEST(0 == 0.000001, tt::tolerance(1E-6));
}
BOOST_AUTO_TEST_CASE( test_check_close )
{
// GH-162 BOOST_CHECK_CLOSE(0, smallnumber) fails
BOOST_CHECK_SMALL(-4.37113883e-08, 1.);
// does not compile with the old tools disabled
// never compiled with the old tools
//BOOST_CHECK_SMALL(-4.37113883e-08, 1);
}
// EOF

View File

@@ -0,0 +1,170 @@
// Use, modification and distribution are subject to 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)
// Copyright Paul A. Bristow 2013
// Copyright Christopher Kormanyos 2013.
// Copyright John Maddock 2013.
#ifdef _MSC_VER
# pragma warning (disable : 4512)
# pragma warning (disable : 4996)
#endif
#define BOOST_TEST_MAIN
#define BOOST_LIB_DIAGNOSTIC "on"// Show library file details.
//[expression_template_1
#include <limits>
#include <iostream>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/test/tools/floating_point_comparison.hpp> // Extra test tool for FP comparison.
#include <boost/test/unit_test.hpp>
typedef boost::multiprecision::number<
boost::multiprecision::cpp_dec_float<50>,
boost::multiprecision::et_off> cpp_dec_float_50_noet;
typedef boost::multiprecision::number<
boost::multiprecision::cpp_dec_float<50>,
boost::multiprecision::et_on> cpp_dec_float_50_et;
// there is no need for this anymore, however this could be defined by
// the user in order to support additional types for floating point
// comparison.
#if 0
namespace boost { namespace math { namespace fpc {
template <class A, boost::multiprecision::expression_template_option B>
struct tolerance_based< boost::multiprecision::number<
A,
B > > : boost::mpl::true_ {};
template <class tag, class Arg1, class Arg2, class Arg3, class Arg4>
struct tolerance_based<
boost::multiprecision::detail::expression<
tag, Arg1, Arg2, Arg3, Arg4> > : boost::mpl::true_ {};
} } }
#endif
/*`To define a 50 decimal digit type using `cpp_dec_float`,
you must pass two template parameters to `boost::multiprecision::number`.
It may be more legible to use a two-staged type definition such as this:
``
typedef boost::multiprecision::cpp_dec_float<50> mp_backend;
typedef boost::multiprecision::number<mp_backend, boost::multiprecision::et_off> cpp_dec_float_50_noet;
``
Here, we first define `mp_backend` as `cpp_dec_float` with 50 digits.
The second step passes this backend to `boost::multiprecision::number`
with `boost::multiprecision::et_off`, an enumerated type.
typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<50>, boost::multiprecision::et_off>
cpp_dec_float_50_noet;
You can reduce typing with a `using` directive `using namespace boost::multiprecision;`
if desired, as shown below.
*/
using namespace boost::multiprecision;
#if 0
BOOST_AUTO_TEST_CASE(multiprecision_types_are_arithmetic)
{
typedef number<cpp_dec_float<50>, et_off> cpp_dec_float_50_noet;
BOOST_TEST((std::numeric_limits<cpp_dec_float_50_noet>::is_specialized));
}
#endif
/*`Now `cpp_dec_float_50_noet` or `cpp_dec_float_50_et`
can be used as a direct replacement for built-in types like `double` etc.
*/
BOOST_AUTO_TEST_CASE(cpp_float_test_check_close_noet)
{ // No expression templates/
typedef number<cpp_dec_float<50>, et_off> cpp_dec_float_50_noet;
std::cout.precision(std::numeric_limits<cpp_dec_float_50_noet>::digits10); // All significant digits.
std::cout << std::showpoint << std::endl; // Show trailing zeros.
cpp_dec_float_50_noet a ("1.0");
cpp_dec_float_50_noet b ("1.0");
b += std::numeric_limits<cpp_dec_float_50_noet>::epsilon(); // Increment least significant decimal digit.
cpp_dec_float_50_noet eps = std::numeric_limits<cpp_dec_float_50_noet>::epsilon();
std::cout <<"a = " << a << ",\nb = " << b << ",\neps = " << eps << std::endl;
BOOST_CHECK_CLOSE(a, b, eps * 100); // Expected to pass (because tolerance is as percent).
BOOST_CHECK_CLOSE_FRACTION(a, b, eps); // Expected to pass (because tolerance is as fraction).
#ifndef BOOST_TEST_MACRO_LIMITED_SUPPORT
namespace tt = boost::test_tools;
BOOST_TEST( a == b, tt::tolerance( tt::fpc::percent_tolerance( eps * 100 ) ) );
BOOST_TEST( a == b, tt::tolerance( eps ) );
#endif
//] [/expression_template_1]git
} // BOOST_AUTO_TEST_CASE(cpp_float_test_check_close)
BOOST_AUTO_TEST_CASE(cpp_float_test_check_close_et)
{ // Using expression templates.
typedef number<cpp_dec_float<50>, et_on> cpp_dec_float_50_et;
std::cout.precision(std::numeric_limits<cpp_dec_float_50_et>::digits10); // All significant digits.
std::cout << std::showpoint << std::endl; // Show trailing zeros.
cpp_dec_float_50_et a("1.0");
cpp_dec_float_50_et b("1.0");
b += std::numeric_limits<cpp_dec_float_50_et>::epsilon(); // Increment least significant decimal digit.
cpp_dec_float_50_et eps = std::numeric_limits<cpp_dec_float_50_et>::epsilon();
std::cout << "a = " << a << ",\nb = " << b << ",\neps = " << eps << std::endl;
BOOST_CHECK_CLOSE(a, b, eps * 100); // Expected to pass (because tolerance is as percent).
BOOST_CHECK_CLOSE_FRACTION(a, b, eps); // Expected to pass (because tolerance is as fraction).
#ifndef BOOST_TEST_MACRO_LIMITED_SUPPORT
namespace tt = boost::test_tools;
BOOST_TEST( a == b, tt::tolerance( tt::fpc::percent_tolerance<cpp_dec_float_50_et>( eps * 100 ) ) );
BOOST_TEST( a == b, tt::tolerance( eps ) );
#endif
/*`Using `cpp_dec_float_50` with the default expression template use switched on,
the compiler error message for `BOOST_CHECK_CLOSE_FRACTION(a, b, eps); would be:
*/
// failure floating_point_comparison.hpp(59): error C2440: 'static_cast' :
// cannot convert from 'int' to 'boost::multiprecision::detail::expression<tag,Arg1,Arg2,Arg3,Arg4>'
//] [/expression_template_1]
} // BOOST_AUTO_TEST_CASE(cpp_float_test_check_close)
/*
Output:
Description: Autorun "J:\Cpp\big_number\Debug\test_cpp_float_close_fraction.exe"
Running 1 test case...
a = 1.0000000000000000000000000000000000000000000000000,
b = 1.0000000000000000000000000000000000000000000000001,
eps = 1.0000000000000000000000000000000000000000000000000e-49
*** No errors detected
*/

View File

@@ -0,0 +1,42 @@
// (C) Copyright Raffi Enficiaud 2019
// 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)
// See http://www.boost.org/libs/test for the library home page.
#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>
// https://github.com/boostorg/test/issues/209
// no floating point comparison for abstract types.
struct abstract
{
virtual ~abstract() = 0;
bool operator==(const abstract &) const { return true; }
};
std::ostream &operator<<(std::ostream &ostr, const abstract &) {
return ostr << "compared";
}
// the test is checking the compilation of the following snippet
void foo(abstract &a)
{
// pre-C++11 compilers use a copy of the arguments in the
// expansion of the BOOST_TEST macro
#if !defined(BOOST_TEST_MACRO_LIMITED_SUPPORT)
BOOST_TEST(a == a);
BOOST_TEST_CHECK(a == a);
BOOST_TEST_REQUIRE(a == a);
BOOST_TEST_WARN(a == a);
#endif
BOOST_CHECK_EQUAL(a, a);
}
// we need at least one test
BOOST_AUTO_TEST_CASE(dummy)
{
const int x = 1;
BOOST_TEST(x == 1);
}

View File

@@ -0,0 +1,198 @@
// (C) Copyright Raffi Enficiaud 2017.
// 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)
// See ticket #13011
#define BOOST_TEST_MODULE fp_check_relational_op
#include <boost/test/unit_test.hpp>
namespace utf = boost::unit_test;
namespace tt = boost::test_tools;
//
// with zeros
//
BOOST_AUTO_TEST_CASE(EQ_zero_on_left, * utf::expected_failures(2))
{
BOOST_TEST(0.0 == 1.0);
BOOST_TEST(0.0 == 1.0, tt::tolerance(0.001));
}
BOOST_AUTO_TEST_CASE(NE_zero_on_left)
{
BOOST_TEST(0.0 != 1.0);
BOOST_TEST(0.0 != 1.0, tt::tolerance(0.001));
}
BOOST_AUTO_TEST_CASE(EQ_zero_on_right, * utf::expected_failures(2))
{
BOOST_TEST(1.0 == 0.0);
BOOST_TEST(1.0 == 0.0, tt::tolerance(0.001));
}
BOOST_AUTO_TEST_CASE(NE_zero_on_right)
{
BOOST_TEST(1.0 != 0.0);
BOOST_TEST(1.0 != 0.0, tt::tolerance(0.001));
}
BOOST_AUTO_TEST_CASE(EQ_zero_on_left_right)
{
BOOST_TEST(0.0 == 0.0);
BOOST_TEST(0.0 == 0.0, tt::tolerance(0.001));
}
BOOST_AUTO_TEST_CASE(NE_zero_on_left_right, * utf::expected_failures(2))
{
BOOST_TEST(0.0 != 0.0);
BOOST_TEST(0.0 != 0.0, tt::tolerance(0.001));
}
BOOST_AUTO_TEST_CASE(LT_zero_on_left)
{
BOOST_TEST(0.0 < 1.0);
BOOST_TEST(0.0 < 1.0, tt::tolerance(0.001));
}
BOOST_AUTO_TEST_CASE(GT_zero_on_left, * utf::expected_failures(2) )
{
BOOST_TEST(0.0 > 1.0);
BOOST_TEST(0.0 > 1.0, tt::tolerance(0.001));
}
BOOST_AUTO_TEST_CASE(GT_zero_on_right)
{
BOOST_TEST(1.0 > 0.0);
BOOST_TEST(1.0 > 0.0, tt::tolerance(0.001));
}
BOOST_AUTO_TEST_CASE(LT_zero_on_right, * utf::expected_failures(2) )
{
BOOST_TEST(1.0 < 0.0);
BOOST_TEST(1.0 < 0.0, tt::tolerance(0.001));
}
// with equality
BOOST_AUTO_TEST_CASE(LE_zero_on_left)
{
BOOST_TEST(0.0 <= 1.0);
BOOST_TEST(0.0 <= 1.0, tt::tolerance(0.001));
}
BOOST_AUTO_TEST_CASE(GE_zero_on_left, * utf::expected_failures(2) )
{
BOOST_TEST(0.0 >= 1.0);
BOOST_TEST(0.0 >= 1.0, tt::tolerance(0.001));
}
BOOST_AUTO_TEST_CASE(GE_zero_on_right)
{
BOOST_TEST(1.0 >= 0.0);
BOOST_TEST(1.0 >= 0.0, tt::tolerance(0.001));
}
BOOST_AUTO_TEST_CASE(LE_zero_on_right, * utf::expected_failures(2) )
{
BOOST_TEST(1.0 <= 0.0);
BOOST_TEST(1.0 <= 0.0, tt::tolerance(0.001));
}
//
// with numbers
//
BOOST_AUTO_TEST_CASE(LT_smaller_on_left)
{
BOOST_TEST(1.0 < 2.0);
BOOST_TEST(1.0 < 2.0, tt::tolerance(0.001));
}
BOOST_AUTO_TEST_CASE(GT_smaller_on_left, * utf::expected_failures(2) )
{
BOOST_TEST(1.0 > 2.0);
BOOST_TEST(1.0 > 2.0, tt::tolerance(0.001));
}
BOOST_AUTO_TEST_CASE(GT_smaller_on_right)
{
BOOST_TEST(2.0 > 1.0);
BOOST_TEST(2.0 > 1.0, tt::tolerance(0.001));
}
BOOST_AUTO_TEST_CASE(LT_smaller_on_right, * utf::expected_failures(2) )
{
BOOST_TEST(2.0 < 1.0);
BOOST_TEST(2.0 < 1.0, tt::tolerance(0.001));
}
// with equality
BOOST_AUTO_TEST_CASE(LE_smaller_on_left)
{
BOOST_TEST(1.0 <= 2.0);
BOOST_TEST(1.0 <= 2.0, tt::tolerance(0.001));
}
BOOST_AUTO_TEST_CASE(GE_smaller_on_left, * utf::expected_failures(2) )
{
BOOST_TEST(1.0 >= 2.0);
BOOST_TEST(1.0 >= 2.0, tt::tolerance(0.001));
}
BOOST_AUTO_TEST_CASE(GE_smaller_on_right)
{
BOOST_TEST(2.0 >= 1.0);
BOOST_TEST(2.0 >= 1.0, tt::tolerance(0.001));
}
BOOST_AUTO_TEST_CASE(LE_smaller_on_right, * utf::expected_failures(2) )
{
BOOST_TEST(2.0 <= 1.0);
BOOST_TEST(2.0 <= 1.0, tt::tolerance(0.001));
}
// infinity
BOOST_AUTO_TEST_CASE(infinity_comparison)
{
//BOOST_TEST(2.0 <= 1.0);
BOOST_TEST(0 < std::numeric_limits<float>::infinity());
BOOST_TEST(std::numeric_limits<float>::infinity() == std::numeric_limits<float>::infinity());
BOOST_TEST(std::numeric_limits<float>::infinity() >= std::numeric_limits<float>::infinity());
//BOOST_TEST(2.0 <= 1.0);
float a = std::numeric_limits<float>::infinity();
BOOST_TEST(a == std::numeric_limits<float>::infinity());
BOOST_TEST(std::numeric_limits<float>::infinity() == a);
float b = a;
BOOST_TEST(b == a);
BOOST_TEST(a == b);
}
BOOST_AUTO_TEST_CASE(infinity_comparison_with_tolerance,
*utf::tolerance<float>(boost::math::fpc::percent_tolerance<float>(0.01))
) {
BOOST_TEST(0 < std::numeric_limits<float>::infinity());
BOOST_TEST(std::numeric_limits<float>::infinity() == std::numeric_limits<float>::infinity());
BOOST_TEST(std::numeric_limits<float>::infinity() >= std::numeric_limits<float>::infinity());
float a = std::numeric_limits<float>::infinity();
BOOST_TEST(a == std::numeric_limits<float>::infinity());
BOOST_TEST(std::numeric_limits<float>::infinity() == a);
float b = a;
BOOST_TEST(b == a);
BOOST_TEST(a == b);
BOOST_TEST((b == a));
BOOST_TEST((a == b));
BOOST_TEST(-a <= b);
BOOST_TEST(-a < b);
BOOST_TEST(a == b, tt::tolerance(0.f));
BOOST_TEST(a == b, tt::tolerance(10.f));
BOOST_TEST(a == b, tt::tolerance(1E10f));
}

View File

@@ -0,0 +1,21 @@
// (C) Copyright Raffi Enficiaud 2017.
// 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)
// See http://www.boost.org/libs/test for the library home page.
#define BOOST_TEST_MODULE nullptr_support
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_CASE(test1)
{
int *p = nullptr;
BOOST_TEST(p == nullptr);
}
BOOST_AUTO_TEST_CASE(test2)
{
int *p = nullptr;
BOOST_CHECK_EQUAL(p, nullptr);
}

View File

@@ -0,0 +1,191 @@
// (C) Copyright Gennadiy Rozental 2001-2015.
// 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)
// See http://www.boost.org/libs/test for the library home page.
//
// File : $RCSfile$
//
// Version : $Revision$
//
// Description : tests output_test_stream test tool functionality
// ***************************************************************************
// Boost.Test
#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>
#include <boost/test/tools/output_test_stream.hpp>
using boost::test_tools::output_test_stream;
// STL
#include <iomanip>
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test_constructor )
{
{
output_test_stream output;
BOOST_TEST( !output.match_pattern() );
BOOST_TEST( output.is_empty() );
}
{
output_test_stream output( (char const*)0 );
BOOST_TEST( !output.match_pattern() );
BOOST_TEST( output.is_empty() );
}
{
output_test_stream output( "" );
BOOST_TEST( !output.match_pattern() );
BOOST_TEST( output.is_empty() );
}
{
output_test_stream output( "%&^$%&$%" );
BOOST_TEST( !output.match_pattern() );
BOOST_TEST( output.is_empty() );
}
{
output_test_stream output( "pattern.temp" );
BOOST_TEST( !output.match_pattern() );
BOOST_TEST( output.is_empty() );
}
{
output_test_stream output( "pattern.temp2", false );
BOOST_TEST( output.match_pattern() );
BOOST_TEST( output.is_empty() );
}
{
output_test_stream output( "pattern.temp2" );
BOOST_TEST( output.match_pattern() );
BOOST_TEST( output.is_empty() );
}
}
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test_is_empty )
{
output_test_stream output;
BOOST_TEST( output.is_empty() );
output << 12345;
BOOST_TEST( !output.is_empty() );
BOOST_TEST( output.is_empty() );
output << "";
BOOST_TEST( output.is_empty() );
output << '\0';
BOOST_TEST( !output.is_empty( false ) );
BOOST_TEST( !output.is_empty() );
}
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test_check_length )
{
output_test_stream output;
BOOST_TEST( output.check_length( 0 ) );
output << "";
BOOST_TEST( output.check_length( 0 ) );
output << '\0';
BOOST_TEST( output.check_length( 1 ) );
output << 1220;
BOOST_TEST( output.check_length( 4 ) );
output << "Text message";
BOOST_TEST( output.check_length( 12, false ) );
BOOST_TEST( output.check_length( 12 ) );
output.width( 20 );
output << "Text message";
BOOST_TEST( output.check_length( 20 ) );
}
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test_is_equal )
{
output_test_stream output;
BOOST_TEST( output.is_equal( "" ) );
output << 1;
BOOST_TEST( output.is_equal( "1" ) );
output << "";
BOOST_TEST( output.is_equal( "" ) );
output << '\0';
BOOST_TEST( output.is_equal( boost::unit_test::const_string( "", 1 ) ) );
output << std::setw( 10 ) << "qwerty" << '\n';
BOOST_TEST( output.is_equal( " qwerty\n" ) );
std::string s( "test string" );
output << s << std::endl;
BOOST_TEST( output.is_equal( "test string\n", false ) );
output << s << std::endl;
BOOST_TEST( output.is_equal( "test string\ntest string\n" ) );
char const* literal_string = "asdfghjkl";
std::string substr1( literal_string, 5 );
std::string substr2( literal_string+5, 4 );
output << substr1;
BOOST_TEST( output.is_equal( boost::unit_test::const_string( literal_string, 5 ), false ) );
output << substr2;
BOOST_TEST( output.is_equal( boost::unit_test::const_string( literal_string, 9 ) ) );
}
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test_match_pattern )
{
for( int i1 = 0; i1 < 2; i1++ ) {
output_test_stream output( "pattern.test", i1 == 1 );
output << "text1\n";
BOOST_TEST( output.match_pattern() );
output << "text2\n";
BOOST_TEST( output.match_pattern() );
output << "text3\n";
BOOST_TEST( output.match_pattern() );
}
{
output_test_stream output( "pattern.test" );
output << "text4\n";
BOOST_TEST( !output.match_pattern() );
output << "text2\n";
BOOST_TEST( output.match_pattern() );
output << "text3\n";
BOOST_TEST( output.match_pattern() );
}
{
output_test_stream output( "pattern.test" );
output << "text\n";
BOOST_TEST( !output.match_pattern() );
output << "text2\n";
BOOST_TEST( !output.match_pattern() );
output << "text3\n";
BOOST_TEST( !output.match_pattern() );
}
for( int i2 = 0; i2 < 2; i2++ ) {
output_test_stream output( "pattern.test", i2 == 1, false );
output << "text\rmore text\n";
BOOST_TEST( output.match_pattern() );
}
}
// EOF

View File

@@ -0,0 +1,30 @@
// (C) Copyright Tony Lewis 2016.
// 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)
// See http://www.boost.org/libs/test for the library home page.
//
// Description : checks that datasets over tuples are supported
// see issue https://svn.boost.org/trac/boost/ticket/12241
// ***************************************************************************
#define BOOST_TEST_MODULE boost_test_tuple_prob
#include <boost/test/unit_test.hpp>
#include <boost/test/data/test_case.hpp>
#include <boost/test/data/monomorphic.hpp>
#include <tuple>
#include <vector>
#include <iostream>
const std::vector< std::tuple<int, int>> values = {
std::tuple<int, int>{ 1, 11 },
std::tuple<int, int>{ 2, 12 },
std::tuple<int, int>{ 3, 13 },
};
BOOST_DATA_TEST_CASE( test1, boost::unit_test::data::make( values ), var1, var2 ) {
std::cout << var1 << ", " << var2 << "\n";
}

View File

@@ -0,0 +1,68 @@
// (C) Copyright Raffi Enficiaud 2017.
// 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)
// See http://www.boost.org/libs/test for the library home page.
// checks issue https://svn.boost.org/trac/boost/ticket/5563 in particular
// the ability of the framework to detect new fixture signatures.
#define BOOST_TEST_MODULE test_fixture_detect_setup_teardown_cpp11
#include <boost/test/unit_test.hpp>
#include <iostream>
#include <boost/test/unit_test_suite.hpp>
#include <boost/test/framework.hpp>
using namespace boost::unit_test;
class fixture_without {
public:
fixture_without() {}
~fixture_without() {}
};
class fixture_with {
public:
fixture_with() {}
void setup() {}
void teardown() {}
~fixture_with() {}
};
class fixture_with_child : public fixture_with {
public:
fixture_with_child() {}
~fixture_with_child() {}
};
BOOST_AUTO_TEST_CASE( fixture_setup_teardown_detect )
{
BOOST_CHECK(!impl_fixture::has_setup<fixture_without>::value);
BOOST_CHECK(!impl_fixture::has_setup<fixture_without>::value);
fixture_without obj;
setup_conditional(obj);
teardown_conditional(obj);
}
BOOST_AUTO_TEST_CASE( fixture_setup_teardown_detect_both )
{
BOOST_CHECK(impl_fixture::has_setup<fixture_with>::value);
BOOST_CHECK(impl_fixture::has_setup<fixture_with>::value);
fixture_with obj;
setup_conditional(obj);
teardown_conditional(obj);
}
BOOST_AUTO_TEST_CASE( fixture_setup_teardown_detect_both_from_child )
{
// should detect this with the C++11/declspec approach
BOOST_CHECK(impl_fixture::has_setup<fixture_with_child>::value);
BOOST_CHECK(impl_fixture::has_setup<fixture_with_child>::value);
fixture_with_child obj;
setup_conditional(obj);
teardown_conditional(obj);
}

View File

@@ -0,0 +1,132 @@
// (C) Copyright Raffi Enficiaud 2017.
// 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)
// See http://www.boost.org/libs/test for the library home page.
// checks issue https://svn.boost.org/trac/boost/ticket/5563 in particular
// the ability of the framework to detect new fixture signatures.
#define BOOST_TEST_MODULE test_fixture_detect_setup_teardown
#include <boost/test/unit_test.hpp>
#include <iostream>
#include <boost/test/unit_test_suite.hpp>
#include <boost/test/framework.hpp>
using namespace boost::unit_test;
class fixture_without {
public:
fixture_without() {}
~fixture_without() {}
};
class fixture_with {
public:
fixture_with() {}
void setup() {}
void teardown() {}
~fixture_with() {}
};
class fixture_with_child : public fixture_with {
public:
fixture_with_child() {}
~fixture_with_child() {}
};
BOOST_AUTO_TEST_CASE( fixture_setup_teardown_detect )
{
BOOST_CHECK(!impl_fixture::has_setup<fixture_without>::value);
BOOST_CHECK(!impl_fixture::has_setup<fixture_without>::value);
fixture_without obj;
setup_conditional(obj);
teardown_conditional(obj);
}
BOOST_AUTO_TEST_CASE( fixture_setup_teardown_detect_both )
{
BOOST_CHECK(impl_fixture::has_setup<fixture_with>::value);
BOOST_CHECK(impl_fixture::has_setup<fixture_with>::value);
fixture_with obj;
setup_conditional(obj);
teardown_conditional(obj);
}
#if defined(BOOST_NO_CXX11_DECLTYPE) || defined(BOOST_NO_CXX11_TRAILING_RESULT_TYPES)
BOOST_AUTO_TEST_CASE( fixture_setup_teardown_detect_both_from_child )
{
// cannot detect this with the C++03 approach
BOOST_CHECK(!impl_fixture::has_setup<fixture_with_child>::value);
BOOST_CHECK(!impl_fixture::has_setup<fixture_with_child>::value);
fixture_with_child obj;
setup_conditional(obj);
teardown_conditional(obj);
}
#endif
int check_gf_1 = 0;
struct global_fixture_1 {
global_fixture_1() {
check_gf_1 = 2;
}
void setup() {
check_gf_1 += 40;
}
void teardown() {
check_gf_1 -= 40;
}
~global_fixture_1() {
if(check_gf_1 != 0) {
// exits with errors
std::exit(1);
}
}
};
BOOST_TEST_GLOBAL_FIXTURE(global_fixture_1);
BOOST_AUTO_TEST_CASE( check_global_fixture_entered )
{
BOOST_CHECK(check_gf_1 == 42);
check_gf_1 -= 2;
}
int check_gf_2 = 0;
namespace random_namespace {
struct global_fixture_2 {
global_fixture_2() {
check_gf_2 = 2;
}
void setup() {
check_gf_2 += 40;
}
void teardown() {
check_gf_2 -= 40;
}
~global_fixture_2() {
if(check_gf_2 != 0) {
// exits with errors
std::exit(1);
}
}
};
}
namespace random_namespace {
BOOST_TEST_GLOBAL_FIXTURE(global_fixture_2);
}
BOOST_AUTO_TEST_CASE( check_global_fixture_in_namespace_entered )
{
BOOST_CHECK(check_gf_2 == 42);
check_gf_2 -= 2;
}

View File

@@ -0,0 +1,19 @@
// (C) Copyright Raffi Enficiaud, 2019
// 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)
// See http://www.boost.org/libs/test for the library home page.
#define BOOST_TEST_MODULE timeout-error
#include <boost/test/unit_test.hpp>
#include <chrono>
#include <thread>
namespace utf = boost::unit_test;
BOOST_AUTO_TEST_CASE(test_fail, * utf::timeout(1))
{
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
BOOST_TEST(true);
}

View File

@@ -0,0 +1,42 @@
// (C) Copyright Raffi Enficiaud, 2019
// 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)
// See http://www.boost.org/libs/test for the library home page.
#define BOOST_TEST_MODULE timeout-error-suite
#include <boost/test/unit_test.hpp>
#include <boost/test/data/test_case.hpp>
#include <chrono>
#include <thread>
namespace utf = boost::unit_test;
// each of the test case of the data set has a timeout of 1 sec
// some of them will fail
BOOST_TEST_DECORATOR(* utf::timeout(1))
BOOST_DATA_TEST_CASE(test_success, utf::data::make({0,1,2,3}))
{
std::this_thread::sleep_for(std::chrono::milliseconds(100*5*sample));
BOOST_TEST(sample >= 0);
}
// the full test suite has a timeout of 1s, some of the data test
// cases will not be executed
BOOST_TEST_DECORATOR(* utf::timeout(1))
BOOST_AUTO_TEST_SUITE(test_suite_timeout)
BOOST_DATA_TEST_CASE(test_success, utf::data::make({0,1,2,3,4,5,6,7,8}))
{
std::this_thread::sleep_for(std::chrono::milliseconds(300));
BOOST_TEST((sample >= 0 && sample < 5));
}
BOOST_AUTO_TEST_CASE(failure_should_not_be_executed)
{
BOOST_TEST(false);
}
BOOST_AUTO_TEST_SUITE_END()

View File

@@ -0,0 +1,33 @@
// (C) Copyright Raffi Enficiaud, 2019
// 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)
// See http://www.boost.org/libs/test for the library home page.
#define BOOST_TEST_MODULE timeout-error-suite
#include <boost/test/unit_test.hpp>
#include <boost/test/data/test_case.hpp>
#include <chrono>
#include <thread>
namespace utf = boost::unit_test;
// each of the test case of the data set has a timeout of 1 sec
BOOST_TEST_DECORATOR(* utf::timeout(1))
BOOST_DATA_TEST_CASE(test_success, utf::data::make({0,1,2,3}))
{
std::this_thread::sleep_for(std::chrono::milliseconds(100));
BOOST_TEST(sample >= 0);
}
// the full test suite has a timeout of 1s
BOOST_TEST_DECORATOR(* utf::timeout(1))
BOOST_AUTO_TEST_SUITE(test_suite_success)
BOOST_DATA_TEST_CASE(test_success, utf::data::make({0,1,2,3,4,5,6}))
{
std::this_thread::sleep_for(std::chrono::milliseconds(100));
BOOST_TEST(sample >= 0);
}
BOOST_AUTO_TEST_SUITE_END()

View File

@@ -0,0 +1,25 @@
// (C) Copyright Raffi Enficiaud, 2019
// 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)
// See http://www.boost.org/libs/test for the library home page.
#define BOOST_TEST_MODULE timeout-error
#include <boost/test/unit_test.hpp>
#include <chrono>
#include <thread>
namespace utf = boost::unit_test;
BOOST_AUTO_TEST_CASE(test1, * utf::timeout(1))
{
std::this_thread::sleep_for(std::chrono::milliseconds(100));
BOOST_TEST(true);
}
BOOST_AUTO_TEST_CASE(test2, * utf::timeout(3))
{
std::this_thread::sleep_for(std::chrono::milliseconds(10));
BOOST_TEST(true);
}

View File

@@ -0,0 +1,46 @@
// (C) Copyright Raffi Enficiaud 2017.
// 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)
// See http://www.boost.org/libs/test for the library home page.
//
//! @file
//! checking the preconditions and dependencies
// *****************************************************************************
#define BOOST_TEST_MODULE test_preconditions
#include <boost/test/unit_test.hpp>
bool returning_false() {
return false;
}
BOOST_AUTO_TEST_CASE(not_running,
*boost::unit_test::precondition([](boost::unit_test::test_unit_id){
return returning_false();
}
))
{
BOOST_TEST(true);
}
BOOST_AUTO_TEST_CASE(success)
{
BOOST_TEST(true);
}
BOOST_AUTO_TEST_SUITE(s1)
BOOST_AUTO_TEST_CASE(test1)
{
BOOST_TEST(true);
}
BOOST_AUTO_TEST_CASE(test2, * boost::unit_test::depends_on("not_running") )
{
BOOST_TEST(false);
}
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(test5, * boost::unit_test::depends_on("s1"))
{
BOOST_TEST(true);
}

View File

@@ -0,0 +1,43 @@
// (C) Copyright Gennadiy Rozental 2015.
// 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)
// See http://www.boost.org/libs/test for the library home page.
//
// File : $RCSfile$
//
// Version : $Revision$
//
// Description : testing BOOST_TEST_UNDER_DEBUGGER compilation and operation
// ***************************************************************************
// Boost.Test
#define BOOST_TEST_TOOLS_DEBUGGABLE
#define BOOST_TEST_MODULE tools under debugger test
#include <boost/test/unit_test.hpp>
//____________________________________________________________________________//
static int
foo( int arg )
{
if( arg == 0 )
throw std::runtime_error("Oops");
return arg * arg;
}
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test )
{
int i = 2;
BOOST_TEST( foo(i)+1 == 5 );
BOOST_TEST( foo(i)+1 == 5, "My message" );
BOOST_CHECK_THROW( foo(0), std::runtime_error );
}
// EOF

View File

@@ -0,0 +1,58 @@
// (C) Copyright Gennadiy Rozental 2015.
// 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)
// See http://www.boost.org/libs/test for the library home page.
//
// File : $RCSfile$
//
// Version : $Revision$
//
// Description : testing BOOST_TEST_UNDER_DEBUGGER compilation and operation
// ***************************************************************************
// Boost.Test
#define BOOST_TEST_TOOLS_UNDER_DEBUGGER
#define BOOST_TEST_MODULE tools under debugger test
#include <boost/test/unit_test.hpp>
// STL
#include <exception>
//____________________________________________________________________________//
static int
foo( int arg )
{
if( arg == 0 )
throw std::runtime_error("Oops");
return arg * arg;
}
//____________________________________________________________________________//
#ifndef BOOST_TEST_MACRO_LIMITED_SUPPORT
BOOST_AUTO_TEST_CASE( test )
{
int i = 2;
BOOST_TEST( foo(i)+1 == 5 );
BOOST_TEST( foo(i)+1 == 5, "My message" );
BOOST_CHECK_THROW( foo(0), std::runtime_error );
}
#endif
BOOST_AUTO_TEST_CASE( test2 )
{
int i = 2;
BOOST_CHECK( foo(i)+1 == 5 );
BOOST_CHECK_MESSAGE( foo(i)+1 == 5, "My message" );
BOOST_CHECK_THROW( foo(0), std::runtime_error );
}
// EOF

View File

@@ -0,0 +1,58 @@
// (C) Copyright Raffi Enficiaud 2017.
// 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)
// See http://www.boost.org/libs/test for the library home page.
//
//! @file
//! Customization point for printing user defined types
// *****************************************************************************
#define BOOST_TEST_MODULE user type logger customization points
#include <boost/test/unit_test.hpp>
namespace printing_test {
struct user_defined_type {
int value;
user_defined_type(int value_) : value(value_)
{}
bool operator==(int right) const {
return right == value;
}
};
std::ostream& boost_test_print_type(std::ostream& ostr, user_defined_type const& right) {
ostr << "** value of my type is " << right.value << " **";
return ostr;
}
}
//using namespace printing_test;
BOOST_AUTO_TEST_CASE(test1)
{
//using printing_test::user_defined_type;
printing_test::user_defined_type t(10);
BOOST_CHECK_EQUAL(t, 10);
#ifndef BOOST_TEST_MACRO_LIMITED_SUPPORT
BOOST_TEST(t == 10);
#endif
BOOST_TEST_MESSAGE("Printing t: " << t);
}
// on unary expressions as well
struct s {
operator bool() const { return true; }
};
std::ostream &boost_test_print_type(std::ostream &o, const s &) {
return o << "printed-s";
}
BOOST_AUTO_TEST_CASE( test_logs )
{
BOOST_TEST(s());
BOOST_TEST_MESSAGE("Printing s(): " << s());
}

View File

@@ -0,0 +1,32 @@
// (C) Copyright Raffi Enficiaud 2015
// 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)
//
// See http://www.boost.org/libs/test for the library home page.
//
// Tests some compilation troubleshooting issues with the windows headers (eg min/max macros)
// ***************************************************************************
#define BOOST_TEST_MODULE test_windows_headers
#include <boost/config.hpp>
#ifdef BOOST_WINDOWS
#include <windows.h>
#endif
#include <boost/test/unit_test.hpp>
#include <boost/test/tools/floating_point_comparison.hpp> // Extra test tool for FP comparison.
BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES( test, 2 )
BOOST_AUTO_TEST_CASE( test )
{
// produces an error
BOOST_TEST(1 == 0);
// this is added in order to compile floating point relative code as well
// which might have trouble compiling if system headers are included (as for
// boost.thread, eg. for std::min).
BOOST_CHECK_CLOSE(1.1, 1.2, 1e-5);
}