mirror of
https://github.com/boostorg/test.git
synced 2026-01-23 18:12:12 +00:00
Changing the examples to use BOOST_TEST
This commit is contained in:
@@ -6,24 +6,24 @@
|
||||
// See http://www.boost.org/libs/test for the library home page.
|
||||
|
||||
//[example_code
|
||||
#define BOOST_TEST_MAIN
|
||||
#define BOOST_TEST_MODULE example59
|
||||
#include <boost/test/included/unit_test.hpp>
|
||||
#include <boost/test/data/test_case.hpp>
|
||||
#include <boost/test/data/monomorphic.hpp>
|
||||
|
||||
namespace bdata = boost::unit_test::data;
|
||||
|
||||
BOOST_DATA_TEST_CASE( test_case_snippet_1, bdata::xrange(5) )
|
||||
BOOST_DATA_TEST_CASE( test1, bdata::xrange(5) )
|
||||
{
|
||||
std::cout << "test 1 " << sample << std::endl;
|
||||
BOOST_CHECK(sample <= 4 && sample >= 0);
|
||||
BOOST_TEST((sample <= 4 && sample >= 0));
|
||||
}
|
||||
|
||||
BOOST_DATA_TEST_CASE(
|
||||
test_case_snippet_2,
|
||||
test2,
|
||||
bdata::xrange<int>( (bdata::begin=1, bdata::end=10, bdata::step=3)) )
|
||||
{
|
||||
std::cout << "test 2 " << sample << std::endl;
|
||||
BOOST_CHECK(sample <= 4 && sample >= 0);
|
||||
BOOST_TEST((sample <= 4 && sample >= 0));
|
||||
}
|
||||
//]
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
// See http://www.boost.org/libs/test for the library home page.
|
||||
|
||||
//[example_code
|
||||
#define BOOST_TEST_MAIN
|
||||
#define BOOST_TEST_MODULE example63
|
||||
#include <boost/test/included/unit_test.hpp>
|
||||
#include <boost/test/data/test_case.hpp>
|
||||
#include <boost/test/data/monomorphic.hpp>
|
||||
@@ -19,8 +19,9 @@ BOOST_DATA_TEST_CASE(
|
||||
bdata::random(1, 17) ^ bdata::xrange(7),
|
||||
random_sample, index )
|
||||
{
|
||||
std::cout << "test 1 " << random_sample << std::endl;
|
||||
BOOST_CHECK(random_sample <= 17 && random_sample >= 1);
|
||||
std::cout << "test 1 " << random_sample
|
||||
<< "," << index << std::endl;
|
||||
BOOST_TEST((random_sample <= 17 && random_sample >= 1));
|
||||
}
|
||||
|
||||
BOOST_DATA_TEST_CASE(
|
||||
@@ -29,7 +30,8 @@ BOOST_DATA_TEST_CASE(
|
||||
^ bdata::xrange(7),
|
||||
random_sample, index )
|
||||
{
|
||||
std::cout << "test 2 " << random_sample << std::endl;
|
||||
std::cout << "test 2 " << random_sample
|
||||
<< "," << index << std::endl;
|
||||
BOOST_CHECK(random_sample < 1.7); // 30% chance of failure
|
||||
}
|
||||
//]
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
// See http://www.boost.org/libs/test for the library home page.
|
||||
|
||||
//[example_code
|
||||
#define BOOST_TEST_MAIN
|
||||
#define BOOST_TEST_MODULE example64
|
||||
#include <boost/test/included/unit_test.hpp>
|
||||
#include <boost/test/data/test_case.hpp>
|
||||
#include <boost/test/data/monomorphic.hpp>
|
||||
@@ -15,16 +15,16 @@ namespace bdata = boost::unit_test::data;
|
||||
|
||||
|
||||
BOOST_DATA_TEST_CASE(
|
||||
test_case_snippet_1,
|
||||
test1,
|
||||
bdata::xrange(2) * bdata::xrange(3),
|
||||
xr1, xr2)
|
||||
{
|
||||
std::cout << "test 1: " << xr1 << ", " << xr2 << std::endl;
|
||||
BOOST_CHECK(xr1 <= 2 && xr2 <= 3);
|
||||
BOOST_TEST((xr1 <= 2 && xr2 <= 3));
|
||||
}
|
||||
|
||||
BOOST_DATA_TEST_CASE(
|
||||
test_case_snippet_2,
|
||||
test2,
|
||||
bdata::xrange(3)
|
||||
*
|
||||
( bdata::random(
|
||||
@@ -37,6 +37,6 @@ BOOST_DATA_TEST_CASE(
|
||||
<< xr << " / "
|
||||
<< random_sample << ", " << index
|
||||
<< std::endl;
|
||||
BOOST_CHECK(random_sample < 1.7); // 30% chance of failure
|
||||
BOOST_TEST(random_sample < 1.7); // 30% chance of failure
|
||||
}
|
||||
//]
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
// See http://www.boost.org/libs/test for the library home page.
|
||||
|
||||
//[example_code
|
||||
#define BOOST_TEST_MAIN
|
||||
#define BOOST_TEST_MODULE example65
|
||||
#include <boost/test/included/unit_test.hpp>
|
||||
#include <boost/test/data/test_case.hpp>
|
||||
#include <boost/test/data/monomorphic.hpp>
|
||||
@@ -15,24 +15,24 @@ namespace bdata = boost::unit_test::data;
|
||||
|
||||
|
||||
BOOST_DATA_TEST_CASE(
|
||||
test_case_snippet_1,
|
||||
test1,
|
||||
bdata::make(2),
|
||||
singleton)
|
||||
{
|
||||
std::cout
|
||||
<< "test 1: "
|
||||
<< singleton << std::endl;
|
||||
BOOST_CHECK(singleton == 2);
|
||||
BOOST_TEST(singleton == 2);
|
||||
}
|
||||
|
||||
BOOST_DATA_TEST_CASE(
|
||||
test_case_snippet_2,
|
||||
test2,
|
||||
bdata::xrange(3) ^ bdata::make(2),
|
||||
xr, singleton)
|
||||
{
|
||||
std::cout
|
||||
<< "test 2: "
|
||||
<< xr << ", " << singleton << std::endl;
|
||||
BOOST_CHECK(singleton == 2);
|
||||
BOOST_TEST(singleton == 2);
|
||||
}
|
||||
//]
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
// See http://www.boost.org/libs/test for the library home page.
|
||||
|
||||
//[example_code
|
||||
#define BOOST_TEST_MAIN
|
||||
#define BOOST_TEST_MODULE example66
|
||||
#include <boost/test/included/unit_test.hpp>
|
||||
#include <boost/test/data/test_case.hpp>
|
||||
#include <boost/test/data/monomorphic.hpp>
|
||||
@@ -16,7 +16,7 @@ namespace bdata = boost::unit_test::data;
|
||||
const char* arr[] = {"cat", "dog"};
|
||||
|
||||
BOOST_DATA_TEST_CASE(
|
||||
test_case_snippet_1,
|
||||
test1,
|
||||
bdata::xrange(2) ^ bdata::make(arr),
|
||||
xr, array_element)
|
||||
{
|
||||
@@ -24,6 +24,6 @@ BOOST_DATA_TEST_CASE(
|
||||
<< xr << ", "
|
||||
<< array_element
|
||||
<< std::endl;
|
||||
BOOST_CHECK(array_element != std::string("mammoth"));
|
||||
BOOST_TEST(array_element != "mammoth");
|
||||
}
|
||||
//]
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
// See http://www.boost.org/libs/test for the library home page.
|
||||
|
||||
//[example_code
|
||||
#define BOOST_TEST_MAIN
|
||||
#define BOOST_TEST_MODULE example67
|
||||
#include <boost/test/included/unit_test.hpp>
|
||||
#include <boost/test/data/test_case.hpp>
|
||||
#include <boost/test/data/monomorphic.hpp>
|
||||
@@ -28,14 +28,14 @@ std::vector<float> fibonacci() {
|
||||
}
|
||||
|
||||
BOOST_DATA_TEST_CASE(
|
||||
test_case_snippet_1,
|
||||
test1,
|
||||
bdata::make(fibonacci()),
|
||||
array_element)
|
||||
{
|
||||
std::cout << "test 1: "
|
||||
<< array_element
|
||||
<< std::endl;
|
||||
BOOST_CHECK(array_element <= 13);
|
||||
BOOST_TEST(array_element <= 13);
|
||||
}
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ typedef std::pair<const std::string, float> pair_map_t;
|
||||
BOOST_TEST_DONT_PRINT_LOG_VALUE( pair_map_t );
|
||||
|
||||
BOOST_DATA_TEST_CASE(
|
||||
test_case_snippet_2,
|
||||
test2,
|
||||
bdata::make(vect_2_str(fibonacci())),
|
||||
array_element)
|
||||
{
|
||||
@@ -64,6 +64,6 @@ BOOST_DATA_TEST_CASE(
|
||||
<< array_element.first << "\", "
|
||||
<< array_element.second
|
||||
<< std::endl;
|
||||
BOOST_CHECK(array_element.second <= 13);
|
||||
BOOST_TEST(array_element.second <= 13);
|
||||
}
|
||||
//]
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//[example_output
|
||||
>example
|
||||
> example67
|
||||
Running 15 test cases...
|
||||
test 1: 0
|
||||
test 1: 1
|
||||
|
||||
@@ -11,26 +11,25 @@
|
||||
namespace data=boost::unit_test::data;
|
||||
|
||||
|
||||
#if 0
|
||||
//[snippet_dataset1_1
|
||||
BOOST_DATA_TEST_CASE( test_case_arity1_implicit, data::xrange(5) )
|
||||
{
|
||||
BOOST_CHECK(sample <= 4 && sample >= 0);
|
||||
BOOST_TEST((sample <= 4 && sample >= 0));
|
||||
}
|
||||
//]
|
||||
|
||||
//[snippet_dataset1_2
|
||||
BOOST_DATA_TEST_CASE( test_case_arity1, data::xrange(5), my_var )
|
||||
{
|
||||
BOOST_CHECK(my_var <= 4 && my_var >= 0);
|
||||
BOOST_TEST((my_var <= 4 && my_var >= 0));
|
||||
}
|
||||
//]
|
||||
|
||||
//[snippet_dataset1_3
|
||||
BOOST_DATA_TEST_CASE( test_case_arity2, data::xrange(2) ^ data::xrange(5), apples, potatoes)
|
||||
{
|
||||
BOOST_CHECK(apples <= 1 && apples >= 0);
|
||||
BOOST_CHECK(potatoes <= 4 && potatoes >= 0);
|
||||
BOOST_TEST((apples <= 1 && apples >= 0));
|
||||
BOOST_TEST((potatoes <= 4 && potatoes >= 0));
|
||||
}
|
||||
//]
|
||||
|
||||
@@ -55,8 +54,6 @@ BOOST_DATA_TEST_CASE( test_case_3, data::make(v), var1)
|
||||
}
|
||||
//]
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
@@ -77,7 +74,7 @@ const std::vector<int> v = generate_vector();
|
||||
BOOST_DATA_TEST_CASE( test_case_1, data::make(v), var1)
|
||||
{
|
||||
std::cout << var1 << std::endl;
|
||||
BOOST_CHECK(true);
|
||||
BOOST_TEST(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -96,5 +93,5 @@ const std::map<int, int> m = generate_map();
|
||||
BOOST_DATA_TEST_CASE( test_case_2, data::make(m), var1)
|
||||
{
|
||||
std::cout << var1.first << " -- " << var1.second << std::endl;
|
||||
BOOST_CHECK(true);
|
||||
BOOST_TEST(true);
|
||||
}
|
||||
|
||||
@@ -152,6 +152,7 @@ test-suite "unit_test_framework_test"
|
||||
|
||||
|
||||
# examples in datasets
|
||||
[ test-btl-lib-c11 run : example67 : : : ../doc/examples/example67.cpp ]
|
||||
[ test-btl-lib-c11 run-fail : example68 : : : ../doc/examples/example68.cpp ]
|
||||
|
||||
;
|
||||
|
||||
Reference in New Issue
Block a user