Skip to content

Commit b5824db

Browse files
committed
Less_operator_expression_test
1 parent 7e49d5e commit b5824db

1 file changed

Lines changed: 50 additions & 3 deletions

File tree

omnn/math/test/logic.cpp

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,53 @@ BOOST_AUTO_TEST_CASE(LessOrEqual_operator_test) {
403403
}
404404
}
405405

406+
BOOST_AUTO_TEST_CASE(Less_operator_expression_test) {
407+
auto LessOperatorExpression = X.Less(Y);
408+
std::cout << "X<Y : " << LessOperatorExpression << std::endl;
409+
for (auto x = -1.; x<1.; x+=.1) {
410+
for (auto y = -1.; y<1.; y+=.1) {
411+
auto isLess = x < y;
412+
auto lessOperatorInstantiation = LessOperatorExpression;
413+
Valuable::vars_cont_t evalMap = {{X, x}, {Y, y}};
414+
std::cout << '\n' << x << "<" << y << " = ";
415+
lessOperatorInstantiation.eval(evalMap);
416+
std::cout << " expression that must be equal to zero when true: " << lessOperatorInstantiation
417+
<< std::endl;
418+
419+
lessOperatorInstantiation.optimize();
420+
std::cout << std::endl << "Is " << x << "<" << y << " : " << lessOperatorInstantiation << std::endl;
421+
bool b = {};
422+
auto boolLessOp = lessOperatorInstantiation.ToBool();
423+
BOOST_TEST(boolLessOp == isLess);
424+
boolLessOp.eval(evalMap);
425+
BOOST_TEST(boolLessOp == isLess);
426+
if (boolLessOp == true) {
427+
BOOST_TEST(boolLessOp.IsInt());
428+
BOOST_TEST(lessOperatorInstantiation.IsInt());
429+
b = lessOperatorInstantiation.IsInt() && lessOperatorInstantiation.ca() == 0;
430+
std::cout << std::endl << x << "<" << y << " : " << b << std::endl;
431+
} else if (boolLessOp == false) {
432+
BOOST_TEST(boolLessOp.IsInt());
433+
b = lessOperatorInstantiation == 0;
434+
std::cout << std::endl
435+
<< x << "<" << y << " : " << (b ? "true; " : "false; ")
436+
<< lessOperatorInstantiation << " != 0" << std::endl;
437+
} else {
438+
std::cout << std::endl << x << "<" << y << " : " << boolLessOp << std::endl;
439+
BOOST_TEST(!"boolLessOp must have boolean value");
440+
}
441+
BOOST_TEST(boolLessOp == b);
442+
443+
auto ok = b == isLess;
444+
if (!ok) {
445+
std::cout << "X=" << x << " Y=" << y << ' ' << ok << " bool: " << b << std::endl;
446+
BOOST_TEST(ok);
447+
}
448+
}
449+
}
450+
}
451+
452+
406453
BOOST_AUTO_TEST_CASE(Delta_function_test
407454
, *disabled() // FIXME:
408455
) { // https://en.wikipedia.org/wiki/Dirac_delta_function
@@ -484,10 +531,10 @@ BOOST_AUTO_TEST_CASE(Less_operator_test) {
484531
std::cout << std::endl << x << "<" << y << " : " << b << std::endl;
485532
} else if (boolLessOp == false) {
486533
BOOST_TEST(boolLessOp.IsInt());
487-
b = lessOperatorInstantiation == 0;
534+
b = lessOperatorInstantiation.IsZero();
488535
std::cout << std::endl
489-
<< x << "<" << y << " : " << b << ' ' << lessOperatorInstantiation << " != 0"
490-
<< std::endl;
536+
<< x << "<" << y << " : " << (b ? "true; " : "false; ")
537+
<< lessOperatorInstantiation << " != 0" << std::endl;
491538
} else {
492539
std::cout << std::endl << x << "<" << y << " : " << boolLessOp << std::endl;
493540
BOOST_TEST(!"boolLessOp must have boolean value");

0 commit comments

Comments
 (0)