Skip to content

Commit

Permalink
Less_operator_expression_test
Browse files Browse the repository at this point in the history
  • Loading branch information
ohhmm committed Feb 13, 2025
1 parent 476faef commit 57b26b6
Showing 1 changed file with 50 additions and 3 deletions.
53 changes: 50 additions & 3 deletions omnn/math/test/logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,53 @@ BOOST_AUTO_TEST_CASE(LessOrEqual_operator_test) {
}
}

BOOST_AUTO_TEST_CASE(Less_operator_expression_test) {
auto LessOperatorExpression = X.Less(Y);
std::cout << "X<Y : " << LessOperatorExpression << std::endl;
for (auto x = -1.; x<1.; x+=.1) {
for (auto y = -1.; y<1.; y+=.1) {
auto isLess = x < y;
auto lessOperatorInstantiation = LessOperatorExpression;
Valuable::vars_cont_t evalMap = {{X, x}, {Y, y}};
std::cout << '\n' << x << "<" << y << " = ";
lessOperatorInstantiation.eval(evalMap);
std::cout << " expression that must be equal to zero when true: " << lessOperatorInstantiation
<< std::endl;

lessOperatorInstantiation.optimize();
std::cout << std::endl << "Is " << x << "<" << y << " : " << lessOperatorInstantiation << std::endl;
bool b = {};
auto boolLessOp = lessOperatorInstantiation.ToBool();
BOOST_TEST(boolLessOp == isLess);
boolLessOp.eval(evalMap);
BOOST_TEST(boolLessOp == isLess);
if (boolLessOp == true) {
BOOST_TEST(boolLessOp.IsInt());
BOOST_TEST(lessOperatorInstantiation.IsInt());
b = lessOperatorInstantiation.IsInt() && lessOperatorInstantiation.ca() == 0;
std::cout << std::endl << x << "<" << y << " : " << b << std::endl;
} else if (boolLessOp == false) {
BOOST_TEST(boolLessOp.IsInt());
b = lessOperatorInstantiation == 0;
std::cout << std::endl
<< x << "<" << y << " : " << (b ? "true; " : "false; ")
<< lessOperatorInstantiation << " != 0" << std::endl;
} else {
std::cout << std::endl << x << "<" << y << " : " << boolLessOp << std::endl;
BOOST_TEST(!"boolLessOp must have boolean value");
}
BOOST_TEST(boolLessOp == b);

auto ok = b == isLess;
if (!ok) {
std::cout << "X=" << x << " Y=" << y << ' ' << ok << " bool: " << b << std::endl;
BOOST_TEST(ok);
}
}
}
}


BOOST_AUTO_TEST_CASE(Delta_function_test
, *disabled() // FIXME:
) { // https://en.wikipedia.org/wiki/Dirac_delta_function
Expand Down Expand Up @@ -484,10 +531,10 @@ BOOST_AUTO_TEST_CASE(Less_operator_test) {
std::cout << std::endl << x << "<" << y << " : " << b << std::endl;
} else if (boolLessOp == false) {
BOOST_TEST(boolLessOp.IsInt());
b = lessOperatorInstantiation == 0;
b = lessOperatorInstantiation.IsZero();
std::cout << std::endl
<< x << "<" << y << " : " << b << ' ' << lessOperatorInstantiation << " != 0"
<< std::endl;
<< x << "<" << y << " : " << (b ? "true; " : "false; ")
<< lessOperatorInstantiation << " != 0" << std::endl;
} else {
std::cout << std::endl << x << "<" << y << " : " << boolLessOp << std::endl;
BOOST_TEST(!"boolLessOp must have boolean value");
Expand Down

0 comments on commit 57b26b6

Please sign in to comment.