blob: a961b698ef1ad51929d019f210e91395d1e15243 [file] [log] [blame]
Phil Nashd944e692011-01-28 18:48:32 +00001/*
Phil Nashd944e692011-01-28 18:48:32 +00002 * Created by Phil on 28/01/2011.
3 * Copyright 2011 Two Blue Cubes Ltd. All rights reserved.
4 *
5 * Distributed under the Boost Software License, Version 1.0. (See accompanying
6 * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Phil Nashd944e692011-01-28 18:48:32 +00007 */
8
Phil Nash46bcd4b2012-07-20 18:43:48 +01009// This define means we have to prefix all the CATCH macros with CATCH_
10// We're using it here to test it out
11#define CATCH_CONFIG_PREFIX_ALL
Phil Nash823ea3e2011-04-26 08:32:40 +010012#include "catch.hpp"
Phil Nashd944e692011-01-28 18:48:32 +000013
Phil Nashd06dced2012-05-09 08:17:51 +010014inline int multiply( int a, int b )
Phil Nashd944e692011-01-28 18:48:32 +000015{
16 return a*b;
17}
18
Phil Nash337dc252013-11-19 07:21:03 +000019CATCH_TEST_CASE( "Generators over two ranges", "[generators]" )
Phil Nashd944e692011-01-28 18:48:32 +000020{
21 using namespace Catch::Generators;
22
Phil Nash46bcd4b2012-07-20 18:43:48 +010023 int i = CATCH_GENERATE( between( 1, 5 ).then( values( 15, 20, 21 ).then( 36 ) ) );
24 int j = CATCH_GENERATE( between( 100, 107 ) );
Phil Nashd944e692011-01-28 18:48:32 +000025
Phil Nash46bcd4b2012-07-20 18:43:48 +010026 CATCH_REQUIRE( multiply( i, 2 ) == i*2 );
27 CATCH_REQUIRE( multiply( j, 2 ) == j*2 );
Phil Nashd944e692011-01-28 18:48:32 +000028}
Phil Nash42aef1d2013-01-13 21:51:44 +000029
30struct IntPair { int first, second; };
31
Phil Nash337dc252013-11-19 07:21:03 +000032CATCH_TEST_CASE( "Generator over a range of pairs", "[generators]" )
Phil Nash42aef1d2013-01-13 21:51:44 +000033{
34 using namespace Catch::Generators;
35
36 IntPair p[] = { { 0, 1 }, { 2, 3 } };
37
38 IntPair* i = CATCH_GENERATE( between( p, &p[1] ) );
39
40 CATCH_REQUIRE( i->first == i->second-1 );
41
42}