2
0
mirror of https://github.com/boostorg/test.git synced 2026-02-15 13:32:09 +00:00

Changing the examples to use BOOST_TEST

This commit is contained in:
Raffi Enficiaud
2015-05-11 17:16:53 +02:00
parent d9994ba9bb
commit f5b052d93f
9 changed files with 37 additions and 37 deletions

View File

@@ -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));
}
//]

View File

@@ -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
}
//]

View File

@@ -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
}
//]

View File

@@ -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);
}
//]

View File

@@ -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");
}
//]

View File

@@ -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);
}
//]

View File

@@ -1,5 +1,5 @@
//[example_output
>example
> example67
Running 15 test cases...
test 1: 0
test 1: 1