Phil Nash | d944e69 | 2011-01-28 18:48:32 +0000 | [diff] [blame] | 1 | /* |
Phil Nash | d944e69 | 2011-01-28 18:48:32 +0000 | [diff] [blame] | 2 | * 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 Nash | d944e69 | 2011-01-28 18:48:32 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
Phil Nash | 46bcd4b | 2012-07-20 18:43:48 +0100 | [diff] [blame] | 9 | // 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 Nash | 823ea3e | 2011-04-26 08:32:40 +0100 | [diff] [blame] | 12 | #include "catch.hpp" |
Phil Nash | d944e69 | 2011-01-28 18:48:32 +0000 | [diff] [blame] | 13 | |
Phil Nash | d06dced | 2012-05-09 08:17:51 +0100 | [diff] [blame] | 14 | inline int multiply( int a, int b ) |
Phil Nash | d944e69 | 2011-01-28 18:48:32 +0000 | [diff] [blame] | 15 | { |
| 16 | return a*b; |
| 17 | } |
| 18 | |
Phil Nash | 337dc25 | 2013-11-19 07:21:03 +0000 | [diff] [blame] | 19 | CATCH_TEST_CASE( "Generators over two ranges", "[generators]" ) |
Phil Nash | d944e69 | 2011-01-28 18:48:32 +0000 | [diff] [blame] | 20 | { |
| 21 | using namespace Catch::Generators; |
| 22 | |
Phil Nash | 46bcd4b | 2012-07-20 18:43:48 +0100 | [diff] [blame] | 23 | int i = CATCH_GENERATE( between( 1, 5 ).then( values( 15, 20, 21 ).then( 36 ) ) ); |
| 24 | int j = CATCH_GENERATE( between( 100, 107 ) ); |
Phil Nash | d944e69 | 2011-01-28 18:48:32 +0000 | [diff] [blame] | 25 | |
Phil Nash | 46bcd4b | 2012-07-20 18:43:48 +0100 | [diff] [blame] | 26 | CATCH_REQUIRE( multiply( i, 2 ) == i*2 ); |
| 27 | CATCH_REQUIRE( multiply( j, 2 ) == j*2 ); |
Phil Nash | d944e69 | 2011-01-28 18:48:32 +0000 | [diff] [blame] | 28 | } |
Phil Nash | 42aef1d | 2013-01-13 21:51:44 +0000 | [diff] [blame] | 29 | |
| 30 | struct IntPair { int first, second; }; |
| 31 | |
Phil Nash | 337dc25 | 2013-11-19 07:21:03 +0000 | [diff] [blame] | 32 | CATCH_TEST_CASE( "Generator over a range of pairs", "[generators]" ) |
Phil Nash | 42aef1d | 2013-01-13 21:51:44 +0000 | [diff] [blame] | 33 | { |
| 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 | } |