aboutsummaryrefslogtreecommitdiff
path: root/unittest/Catch/projects/SelfTest/GeneratorTests.cpp
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2017-12-22 16:53:56 +0100
committerSzczepan Zalega <szczepan@nitrokey.com>2017-12-22 16:53:56 +0100
commite9fc58cb304323f07aba736fc523903481404cff (patch)
tree59db450412ca101aa9601b3f2174436898f955c1 /unittest/Catch/projects/SelfTest/GeneratorTests.cpp
parent8150ee4edc7e32d5c27cd3e0f68c630d90865638 (diff)
parent48b3d82ffe1ed19db9ba3cf7e6536ecf92e27391 (diff)
downloadlibnitrokey-e9fc58cb304323f07aba736fc523903481404cff.tar.gz
libnitrokey-e9fc58cb304323f07aba736fc523903481404cff.tar.bz2
Merge commit '48b3d82ffe1ed19db9ba3cf7e6536ecf92e27391' as 'unittest/Catch'
Diffstat (limited to 'unittest/Catch/projects/SelfTest/GeneratorTests.cpp')
-rw-r--r--unittest/Catch/projects/SelfTest/GeneratorTests.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/unittest/Catch/projects/SelfTest/GeneratorTests.cpp b/unittest/Catch/projects/SelfTest/GeneratorTests.cpp
new file mode 100644
index 0000000..af08b1d
--- /dev/null
+++ b/unittest/Catch/projects/SelfTest/GeneratorTests.cpp
@@ -0,0 +1,42 @@
+/*
+ * 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)
+ */
+
+// 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
+#include "catch.hpp"
+
+inline int multiply( int a, int b )
+{
+ return a*b;
+}
+
+CATCH_TEST_CASE( "Generators over two ranges", "[generators]" )
+{
+ using namespace Catch::Generators;
+
+ int i = CATCH_GENERATE( between( 1, 5 ).then( values( 15, 20, 21 ).then( 36 ) ) );
+ int j = CATCH_GENERATE( between( 100, 107 ) );
+
+ CATCH_REQUIRE( multiply( i, 2 ) == i*2 );
+ CATCH_REQUIRE( multiply( j, 2 ) == j*2 );
+}
+
+struct IntPair { int first, second; };
+
+CATCH_TEST_CASE( "Generator over a range of pairs", "[generators]" )
+{
+ using namespace Catch::Generators;
+
+ IntPair p[] = { { 0, 1 }, { 2, 3 } };
+
+ IntPair* i = CATCH_GENERATE( between( p, &p[1] ) );
+
+ CATCH_REQUIRE( i->first == i->second-1 );
+
+}