From a796c200e52f24c63b04e4a63b98a77b6d97fab0 Mon Sep 17 00:00:00 2001 From: Bjorn Reese Date: Sat, 18 Feb 2017 19:52:12 +0100 Subject: [PATCH] Moved failing test to separate file --- test/Jamfile.v2 | 1 + test/lightweight_test_all_with_fail.cpp | 107 ++++++++++++++++++++++++ test/lightweight_test_all_with_test.cpp | 84 ++----------------- 3 files changed, 113 insertions(+), 79 deletions(-) create mode 100644 test/lightweight_test_all_with_fail.cpp diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index d675eae..1490cf2 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -67,6 +67,7 @@ run lightweight_test_test.cpp : : : 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 ; diff --git a/test/lightweight_test_all_with_fail.cpp b/test/lightweight_test_all_with_fail.cpp new file mode 100644 index 0000000..b51d64d --- /dev/null +++ b/test/lightweight_test_all_with_fail.cpp @@ -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 +#include +#include +#include + +int fail_vector() +{ + int test_cases = 0; + + { + std::vector x, y; + x.push_back( 1 ); + BOOST_TEST_ALL_WITH( x.begin(), x.end(), y.begin(), y.end(), std::equal_to() ); + ++test_cases; + } + + { + std::vector x, y; + y.push_back( 1 ); + BOOST_TEST_ALL_WITH( x.begin(), x.end(), y.begin(), y.end(), std::equal_to() ); + ++test_cases; + } + + { + std::vector 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() ); + ++test_cases; + } + + { + std::vector 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() ); + ++test_cases; + } + + { + std::vector 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() ); + ++test_cases; + } + + { + std::vector 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() ); + ++test_cases; + } + + return test_cases; +} + +template +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 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(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; +} diff --git a/test/lightweight_test_all_with_test.cpp b/test/lightweight_test_all_with_test.cpp index add725e..bc078a4 100644 --- a/test/lightweight_test_all_with_test.cpp +++ b/test/lightweight_test_all_with_test.cpp @@ -13,12 +13,8 @@ #include #include -int test_vector() +void test_vector() { - int failed_test_cases = 0; - - // Successes - { std::vector 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() ); } - - // Failures - - { - std::vector x, y; - x.push_back( 1 ); - BOOST_TEST_ALL_WITH( x.begin(), x.end(), y.begin(), y.end(), std::equal_to() ); - ++failed_test_cases; - } - - { - std::vector x, y; - y.push_back( 1 ); - BOOST_TEST_ALL_WITH( x.begin(), x.end(), y.begin(), y.end(), std::equal_to() ); - ++failed_test_cases; - } - - { - std::vector 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() ); - ++failed_test_cases; - } - - { - std::vector 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() ); - ++failed_test_cases; - } - - { - std::vector 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() ); - ++failed_test_cases; - } - - { - std::vector 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() ); - ++failed_test_cases; - } - - return failed_test_cases; } template @@ -104,12 +50,8 @@ private: T tolerance; }; -int test_tolerance_predicate() +void test_tolerance_predicate() { - int failed_test_cases = 0; - - // Successes - { std::vector 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(1e-5) ); } - - // Failures - - { - std::vector 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(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(); }