From a6d18cb57dea4a15d445149fdb81833218d83d3d Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Tue, 30 Jun 2015 14:27:25 +0100 Subject: [PATCH] Test modulo operator. --- src/tests/main.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/tests/main.cpp b/src/tests/main.cpp index 0f7c4c93..06f94953 100644 --- a/src/tests/main.cpp +++ b/src/tests/main.cpp @@ -35,6 +35,24 @@ #include +TEST(ModuloOperator, Cpp11Conformance) { + // C++11 defines the modulo operator more strongly + // (only x % 0 is left undefined), whereas C++03 + // only defined the operator for positive first operand. + // Test that the modulo operator has been implemented + // according to C++11. + + EXPECT_EQ(0, 20 % 5); + EXPECT_EQ(0, 20 % -5); + EXPECT_EQ(0, -20 % 5); + EXPECT_EQ(0, -20 % -5); + + EXPECT_EQ(2, 9 % 7); + EXPECT_EQ(2, 9 % -7); + EXPECT_EQ(-2, -9 % 7); + EXPECT_EQ(-2, -9 % -7); +} + int main(int argc, char **argv) { //Disable logging or else stdout will get overrun. boost::log::core::get()->set_logging_enabled(false);