Moved failing test to separate file

This commit is contained in:
Bjorn Reese 2017-02-18 19:52:12 +01:00
parent a3382dd5a8
commit a796c200e5
3 changed files with 113 additions and 79 deletions

View File

@ -67,6 +67,7 @@ run lightweight_test_test.cpp : : : <exception-handling>off : lightweight_test_t
run lightweight_test_test2.cpp ;
run lightweight_test_all_eq_test.cpp ;
run lightweight_test_all_with_test.cpp ;
run lightweight_test_all_with_fail.cpp ;
run-fail lightweight_test_fail.cpp ;
run-fail lightweight_test_fail2.cpp ;

View File

@ -0,0 +1,107 @@
//
// Negative est for BOOST_TEST_ALL_WITH
//
// Copyright (c) 2017 Bjorn Reese
//
// 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
//
#include <cmath>
#include <functional>
#include <vector>
#include <boost/core/lightweight_test.hpp>
int fail_vector()
{
int test_cases = 0;
{
std::vector<int> x, y;
x.push_back( 1 );
BOOST_TEST_ALL_WITH( x.begin(), x.end(), y.begin(), y.end(), std::equal_to<int>() );
++test_cases;
}
{
std::vector<int> x, y;
y.push_back( 1 );
BOOST_TEST_ALL_WITH( x.begin(), x.end(), y.begin(), y.end(), std::equal_to<int>() );
++test_cases;
}
{
std::vector<int> x, y;
x.push_back( 1 ); x.push_back( 2 ); x.push_back( 3 ); x.push_back( 4 );
y.push_back( 1 ); y.push_back( 2 ); y.push_back( 3 );
BOOST_TEST_ALL_WITH( x.begin(), x.end(), y.begin(), y.end(), std::equal_to<int>() );
++test_cases;
}
{
std::vector<int> x, y;
x.push_back( 1 ); x.push_back( 2 ); x.push_back( 3 );
y.push_back( 1 ); y.push_back( 2 ); y.push_back( 3 ); y.push_back( 4 );
BOOST_TEST_ALL_WITH( x.begin(), x.end(), y.begin(), y.end(), std::equal_to<int>() );
++test_cases;
}
{
std::vector<int> x, y;
x.push_back( 1 ); x.push_back( 2 ); x.push_back( 3 ); x.push_back( 4 );
y.push_back( 1 ); y.push_back( 3 ); y.push_back( 2 ); y.push_back( 4 );
BOOST_TEST_ALL_WITH( x.begin(), x.end(), y.begin(), y.end(), std::equal_to<int>() );
++test_cases;
}
{
std::vector<int> x, y;
x.push_back( 1 ); x.push_back( 2 ); x.push_back( 3 ); x.push_back( 4 );
y.push_back( 1 ); y.push_back( 3 ); y.push_back( 2 ); y.push_back( 4 );
BOOST_TEST_ALL_WITH( x.begin(), x.end(), y.begin(), y.end(), std::less<int>() );
++test_cases;
}
return test_cases;
}
template <typename T>
struct with_tolerance
{
with_tolerance(T tolerance) : tolerance(tolerance) {}
bool operator()(T lhs, T rhs)
{
return (std::abs(lhs - rhs) <= tolerance);
}
private:
T tolerance;
};
int fail_tolerance_predicate()
{
int test_cases = 0;
{
std::vector<double> x, y;
x.push_back( 1.0 ); x.push_back( 1.0 );
y.push_back( 1.0 - 1e-4 ); y.push_back( 1.0 + 1e-4 );
BOOST_TEST_ALL_WITH( x.begin(), x.end(), y.begin(), y.end(), with_tolerance<double>(1e-5) );
++test_cases;
}
return test_cases;
}
int main()
{
int test_cases = 0;
test_cases += fail_vector();
test_cases += fail_tolerance_predicate();
boost::report_errors();
return boost::detail::test_errors() != test_cases;
}

View File

@ -13,12 +13,8 @@
#include <vector>
#include <boost/core/lightweight_test.hpp>
int test_vector()
void test_vector()
{
int failed_test_cases = 0;
// Successes
{
std::vector<int> x, y;
x.push_back( 1 ); x.push_back( 2 ); x.push_back( 3 ); x.push_back( 4 );
@ -39,56 +35,6 @@ int test_vector()
y.push_back( 2 ); y.push_back( 3 ); y.push_back( 4 ); y.push_back( 5 );
BOOST_TEST_ALL_WITH( x.begin(), x.end(), y.begin(), y.end(), std::less<int>() );
}
// Failures
{
std::vector<int> x, y;
x.push_back( 1 );
BOOST_TEST_ALL_WITH( x.begin(), x.end(), y.begin(), y.end(), std::equal_to<int>() );
++failed_test_cases;
}
{
std::vector<int> x, y;
y.push_back( 1 );
BOOST_TEST_ALL_WITH( x.begin(), x.end(), y.begin(), y.end(), std::equal_to<int>() );
++failed_test_cases;
}
{
std::vector<int> x, y;
x.push_back( 1 ); x.push_back( 2 ); x.push_back( 3 ); x.push_back( 4 );
y.push_back( 1 ); y.push_back( 2 ); y.push_back( 3 );
BOOST_TEST_ALL_WITH( x.begin(), x.end(), y.begin(), y.end(), std::equal_to<int>() );
++failed_test_cases;
}
{
std::vector<int> x, y;
x.push_back( 1 ); x.push_back( 2 ); x.push_back( 3 );
y.push_back( 1 ); y.push_back( 2 ); y.push_back( 3 ); y.push_back( 4 );
BOOST_TEST_ALL_WITH( x.begin(), x.end(), y.begin(), y.end(), std::equal_to<int>() );
++failed_test_cases;
}
{
std::vector<int> x, y;
x.push_back( 1 ); x.push_back( 2 ); x.push_back( 3 ); x.push_back( 4 );
y.push_back( 1 ); y.push_back( 3 ); y.push_back( 2 ); y.push_back( 4 );
BOOST_TEST_ALL_WITH( x.begin(), x.end(), y.begin(), y.end(), std::equal_to<int>() );
++failed_test_cases;
}
{
std::vector<int> x, y;
x.push_back( 1 ); x.push_back( 2 ); x.push_back( 3 ); x.push_back( 4 );
y.push_back( 1 ); y.push_back( 3 ); y.push_back( 2 ); y.push_back( 4 );
BOOST_TEST_ALL_WITH( x.begin(), x.end(), y.begin(), y.end(), std::less<int>() );
++failed_test_cases;
}
return failed_test_cases;
}
template <typename T>
@ -104,12 +50,8 @@ private:
T tolerance;
};
int test_tolerance_predicate()
void test_tolerance_predicate()
{
int failed_test_cases = 0;
// Successes
{
std::vector<double> x, y;
x.push_back( 1.0 ); x.push_back( 2.0 ); x.push_back( 3.0 ); x.push_back( 4.0 );
@ -123,28 +65,12 @@ int test_tolerance_predicate()
y.push_back( 1.0 - 1e-6 ); y.push_back( 1.0 + 1e-6 );
BOOST_TEST_ALL_WITH( x.begin(), x.end(), y.begin(), y.end(), with_tolerance<double>(1e-5) );
}
// Failures
{
std::vector<double> x, y;
x.push_back( 1.0 ); x.push_back( 1.0 );
y.push_back( 1.0 - 1e-4 ); y.push_back( 1.0 + 1e-4 );
BOOST_TEST_ALL_WITH( x.begin(), x.end(), y.begin(), y.end(), with_tolerance<double>(1e-5) );
++failed_test_cases;
}
return failed_test_cases;
}
int main()
{
int failed_test_cases = 0;
test_vector();
test_tolerance_predicate();
failed_test_cases += test_vector();
failed_test_cases += test_tolerance_predicate();
boost::report_errors();
return boost::detail::test_errors() != failed_test_cases;
return boost::report_errors();
}