Skip to content

Commit

Permalink
Modulo_Ordering_test
Browse files Browse the repository at this point in the history
  • Loading branch information
ohhmm committed Nov 22, 2024
1 parent c899602 commit 8fd51d1
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
10 changes: 9 additions & 1 deletion omnn/math/Integer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions omnn/math/test/Modulo_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
7 changes: 7 additions & 0 deletions omnn/math/test/Product_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions omnn/math/test/generic.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once
#include <boost/test/unit_test.hpp>

#include <omnn/math/Product.h>
#include <omnn/math/Sum.h>
#include <omnn/math/Variable.h>

#include <cmath>
Expand Down Expand Up @@ -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

0 comments on commit 8fd51d1

Please sign in to comment.