2011-01-28 19:48:32 +01:00
|
|
|
/*
|
|
|
|
* Created by Phil on 28/01/2011.
|
|
|
|
* Copyright 2011 Two Blue Cubes Ltd. All rights reserved.
|
|
|
|
*
|
|
|
|
* 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)
|
|
|
|
*/
|
|
|
|
|
2012-07-20 19:43:48 +02:00
|
|
|
// This define means we have to prefix all the CATCH macros with CATCH_
|
|
|
|
// We're using it here to test it out
|
|
|
|
#define CATCH_CONFIG_PREFIX_ALL
|
2011-04-26 09:32:40 +02:00
|
|
|
#include "catch.hpp"
|
2011-01-28 19:48:32 +01:00
|
|
|
|
2012-05-09 09:17:51 +02:00
|
|
|
inline int multiply( int a, int b )
|
2011-01-28 19:48:32 +01:00
|
|
|
{
|
|
|
|
return a*b;
|
|
|
|
}
|
|
|
|
|
2013-11-19 08:21:03 +01:00
|
|
|
CATCH_TEST_CASE( "Generators over two ranges", "[generators]" )
|
2011-01-28 19:48:32 +01:00
|
|
|
{
|
|
|
|
using namespace Catch::Generators;
|
2015-11-04 19:01:28 +01:00
|
|
|
|
2012-07-20 19:43:48 +02:00
|
|
|
int i = CATCH_GENERATE( between( 1, 5 ).then( values( 15, 20, 21 ).then( 36 ) ) );
|
|
|
|
int j = CATCH_GENERATE( between( 100, 107 ) );
|
2015-11-04 19:01:28 +01:00
|
|
|
|
2012-07-20 19:43:48 +02:00
|
|
|
CATCH_REQUIRE( multiply( i, 2 ) == i*2 );
|
|
|
|
CATCH_REQUIRE( multiply( j, 2 ) == j*2 );
|
2011-01-28 19:48:32 +01:00
|
|
|
}
|
2013-01-13 22:51:44 +01:00
|
|
|
|
|
|
|
struct IntPair { int first, second; };
|
|
|
|
|
2013-11-19 08:21:03 +01:00
|
|
|
CATCH_TEST_CASE( "Generator over a range of pairs", "[generators]" )
|
2013-01-13 22:51:44 +01:00
|
|
|
{
|
|
|
|
using namespace Catch::Generators;
|
2015-11-04 19:01:28 +01:00
|
|
|
|
2013-01-13 22:51:44 +01:00
|
|
|
IntPair p[] = { { 0, 1 }, { 2, 3 } };
|
2015-11-04 19:01:28 +01:00
|
|
|
|
2013-01-13 22:51:44 +01:00
|
|
|
IntPair* i = CATCH_GENERATE( between( p, &p[1] ) );
|
2015-11-04 19:01:28 +01:00
|
|
|
|
2013-01-13 22:51:44 +01:00
|
|
|
CATCH_REQUIRE( i->first == i->second-1 );
|
2015-11-04 19:01:28 +01:00
|
|
|
|
2013-01-13 22:51:44 +01:00
|
|
|
}
|