Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/Test/ConditionTests.cpp
diff options
context:
space:
mode:
authorPhil Nash2011-03-15 22:22:19 +0000
committerPhil Nash2011-03-15 22:22:19 +0000
commitf6758c2967bc5c7fcd3333dc08871f0793234355 (patch)
tree64500426875a19ff7e88f91dc0a8f839bb3162d6 /Test/ConditionTests.cpp
parentcc0ed3a988a8aa95a1a4169aaf968bc8f4afb71b (diff)
downloadcatch3-f6758c2967bc5c7fcd3333dc08871f0793234355.tar.gz
Added special case logic for signed/ unsigned comparisons involving negative numbers and added test cases to cover them
Diffstat (limited to 'Test/ConditionTests.cpp')
-rw-r--r--Test/ConditionTests.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/Test/ConditionTests.cpp b/Test/ConditionTests.cpp
index b1010169..727fb9eb 100644
--- a/Test/ConditionTests.cpp
+++ b/Test/ConditionTests.cpp
@@ -180,6 +180,39 @@ TEST_CASE( "./succeeding/conditions/int literals", "Comparisons with int literal
REQUIRE( 62270208023445 > ul );
}
+// Because we have to do some conversions when comparing certain signed/ unsigned types (to avoid
+// spurious warnings when comparing integer literals with unsigned integers), we have a set of tests
+// here to confirm that the behaviour is correct at the boundaries
+TEST_CASE( "./succeeding/conditions/unsigned-negative", "Comparisons between negative signed and unsigned ints, expected to succeed" )
+{
+ using namespace Catch::Generators;
+
+ int negative = GENERATE( values( -1, -2, (std::numeric_limits<int>::min)() ) );
+ unsigned int ui = GENERATE( values( 0u, 1u, 2u, (std::numeric_limits<unsigned int>::max)() ) );
+
+ CHECK( ui > negative );
+ CHECK( negative < ui );
+ CHECK( ui >= negative );
+ CHECK( negative <= ui );
+ CHECK( ui != negative );
+ CHECK( negative != ui );
+}
+
+TEST_CASE( "./failing/conditions/unsigned-negative", "Comparisons between negative signed and unsigned ints, expected to fail" )
+{
+ using namespace Catch::Generators;
+
+ int negative = GENERATE( values( -1, -2, (std::numeric_limits<int>::min)() ) );
+ unsigned int ui = GENERATE( values( 0u, 1u, 2u, (std::numeric_limits<unsigned int>::max)() ) );
+
+ CHECK( ui < negative );
+ CHECK( negative > ui );
+ CHECK( ui <= negative );
+ CHECK( negative >= ui );
+ CHECK( ui == negative );
+ CHECK( negative == ui );
+}
+
// Not (!) tests
// The problem with the ! operator is that it has right-to-left associativity.
// This means we can't isolate it when we decompose. The simple REQUIRE( !false ) form, therefore,