diff --git a/omnn/math/Integer.cpp b/omnn/math/Integer.cpp index af906081d..e6d83cdf5 100644 --- a/omnn/math/Integer.cpp +++ b/omnn/math/Integer.cpp @@ -605,7 +605,15 @@ namespace math { bool Integer::IsComesBefore(const Valuable& v) const { - return v.IsInt() ? *this > v : v.FindVa() != nullptr; + if (v.IsProduct()) { + return Product{*this}.IsComesBefore(v); + } else if (v.IsProduct()) { + return Product{*this}.IsComesBefore(v); + } else if(v.IsInt()){ + return *this > v; + } else { + return v.FindVa() != nullptr; + } } Valuable Integer::InCommonWith(const Valuable& v) const diff --git a/omnn/math/test/Modulo_test.cpp b/omnn/math/test/Modulo_test.cpp index 1046c09f2..c4d6a2852 100644 --- a/omnn/math/test/Modulo_test.cpp +++ b/omnn/math/test/Modulo_test.cpp @@ -78,3 +78,9 @@ BOOST_AUTO_TEST_CASE(Modulo_IntOperatorLess_test) { } } } + +BOOST_AUTO_TEST_CASE(Modulo_Ordering_test) { + auto _1 = "(1 % ((Y ^ 4)))"_v; + auto _2 = "((-4 * (Y ^ 3)) % ((Y ^ 4)))"_v; + InequalOrderCheck(_1, _2); +} diff --git a/omnn/math/test/Product_test.cpp b/omnn/math/test/Product_test.cpp index 8c8b6ca87..e9f14fae3 100644 --- a/omnn/math/test/Product_test.cpp +++ b/omnn/math/test/Product_test.cpp @@ -6,6 +6,8 @@ #include "Fraction.h" #include "Variable.h" +#include "generic.hpp" + using namespace std; using namespace omnn::math; using namespace boost::unit_test; @@ -47,6 +49,7 @@ BOOST_AUTO_TEST_CASE(Product_optimize_off_comparision_test) { auto _1 = "-2*(1^5)"_v; auto _2 = "(1 ^ 6)"_v; + InequalOrderCheck(_1, _2); auto after = _1.IsComesBefore(_2); BOOST_TEST(after); auto before = _2.IsComesBefore(_1); @@ -57,6 +60,10 @@ BOOST_AUTO_TEST_CASE(Product_optimize_off_comparision_test) { BOOST_TEST(less); Sum sum = {std::move(_1), std::move(_2)}; + + _1 = 1; + _2 = "(-4 * (Y ^ 3))"_v; + InequalOrderCheck(_1, _2); } BOOST_AUTO_TEST_CASE(Product_tests) diff --git a/omnn/math/test/generic.hpp b/omnn/math/test/generic.hpp index a03ad0f92..54c959caa 100644 --- a/omnn/math/test/generic.hpp +++ b/omnn/math/test/generic.hpp @@ -1,6 +1,8 @@ #pragma once #include +#include +#include #include #include @@ -119,5 +121,15 @@ void TestBooleanExpression(const Valuable& expressionX, auto function) { } } +void InequalOrderCheck(const Valuable& _1, const Valuable& _2) +{ + BOOST_TEST(_1 != _2); + auto before = _1.IsComesBefore(_2); + auto after = _2.IsComesBefore(_1); + BOOST_TEST(before != after); + Product{_1, _2}; + Sum{_1, _2}; +} + } // namespace