diff --git a/safe_numerics/include/safe_range.hpp b/safe_numerics/include/safe_range.hpp index 6684e81..c163c5a 100644 --- a/safe_numerics/include/safe_range.hpp +++ b/safe_numerics/include/safe_range.hpp @@ -508,7 +508,7 @@ typename boost::enable_if< bool >::type operator<(const T & lhs, const safe_range_base & rhs) { - return rhs >= lhs; + return rhs > lhs; } template typename boost::enable_if< @@ -516,7 +516,7 @@ typename boost::enable_if< bool >::type inline operator>(const T & lhs, const safe_range_base & rhs) { - return rhs <= lhs; + return rhs < lhs; } template typename boost::enable_if< @@ -540,7 +540,7 @@ typename boost::enable_if< bool >::type inline operator>=(const T & lhs, const safe_range_base & rhs) { - return rhs < lhs; + return rhs <= lhs; } template typename boost::enable_if< @@ -548,7 +548,7 @@ typename boost::enable_if< bool >::type inline operator<=(const T & lhs, const safe_range_base & rhs) { - return rhs > lhs; + return rhs >= lhs; } // addition diff --git a/safe_numerics/test/test_compare.cpp b/safe_numerics/test/test_compare.cpp new file mode 100644 index 0000000..16ddea2 --- /dev/null +++ b/safe_numerics/test/test_compare.cpp @@ -0,0 +1,46 @@ +// Copyright (c) 2013 Ruslan Baratov +// +// 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) + +#include "../include/safe_integer.hpp" +#include + +template +void test_equal(T test_val) { + namespace num = boost::numeric; + num::safe x = test_val; + num::safe y = test_val; + assert(x == y); + assert(x >= y); + assert(x <= y); + assert(!(x < y)); + assert(!(x > y)); +} + +template +void test_non_equal(T test_val) { + namespace num = boost::numeric; + num::safe x(test_val); + num::safe y(test_val + 1); + assert(x != y); + assert(!(x >= y)); + assert(x <= y); + assert(x < y); + assert(!(x > y)); +} + +int main() { + test_equal(0); + test_equal(3); + test_equal(14); + + test_equal(3); + + test_equal(45); + + test_non_equal(342); + test_non_equal(33); + test_non_equal(-988); +}