Skip to content

Commit 5a3b59a

Browse files
committed
Implement '<' and enable Less_operator_test
1 parent 721fcdb commit 5a3b59a

2 files changed

Lines changed: 58 additions & 8 deletions

File tree

omnn/math/Product.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,11 +1145,11 @@ namespace math {
11451145
} else if (Has(v)) {
11461146
isLess = *this / v < constants::one;
11471147
} else {
1148-
auto bigger = rt::find_if(members,
1148+
auto bigger = rt::find_if(members,
11491149
[&](auto& item) {
11501150
return v.operator<(item);
11511151
});
1152-
auto found = bigger != members.end();
1152+
auto found = bigger != members.end();
11531153
if (found) {
11541154
auto rest = *this / *bigger;
11551155
if (rest >= constants::one) {

omnn/math/test/logic.cpp

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,56 @@ BOOST_AUTO_TEST_CASE(LessOrEqual_operator_test) {
238238
}
239239
}
240240

241+
BOOST_AUTO_TEST_CASE(Less_operator_test
242+
, *disabled() // FIXME:
243+
) {
244+
DECL_VARS(X, Y);
245+
auto LE = X.Less(Y);
246+
std::cout << "X<Y : " << LE << std::endl;
247+
for (auto x = 10; x--> -10;) {
248+
for (auto y = 10; y--> -10;) {
249+
auto isLess = x < y;
250+
auto lessOperatorInstantiation = LE;
251+
Valuable::vars_cont_t evalMap = {{X, x}, {Y, y}};
252+
std::cout << '\n' << x << "<" << y << " = ";
253+
lessOperatorInstantiation.eval(evalMap);
254+
std::cout << " expression that must be equal to zero when true: " << lessOperatorInstantiation
255+
<< std::endl;
256+
257+
lessOperatorInstantiation.optimize();
258+
std::cout << std::endl << "Is " << x << "<" << y << " : " << lessOperatorInstantiation << std::endl;
259+
bool b = {};
260+
auto boolLessOp = lessOperatorInstantiation.ToBool();
261+
BOOST_TEST(boolLessOp == isLess);
262+
boolLessOp.eval(evalMap);
263+
BOOST_TEST(boolLessOp == isLess);
264+
if (boolLessOp == true) {
265+
BOOST_TEST(boolLessOp.IsInt());
266+
BOOST_TEST(lessOperatorInstantiation.IsInt());
267+
b = lessOperatorInstantiation.IsInt() && lessOperatorInstantiation.ca() == 0;
268+
std::cout << std::endl << x << "<" << y << " : " << b << std::endl;
269+
} else if (boolLessOp == false) {
270+
BOOST_TEST(boolLessOrEqualOp.IsInt());
271+
b = lessOperatorInstantiation == 0;
272+
std::cout << std::endl
273+
<< x << "<" << y << " : " << (b ? "true; " : "false; ")
274+
<< lessOperatorInstantiation << " != 0" << std::endl;
275+
} else {
276+
std::cout << std::endl << x << "<" << y << " : " << boolLessOp << std::endl;
277+
BOOST_TEST(!"boolLessOp must have boolean value");
278+
}
279+
BOOST_TEST(boolLessOrEqualOp == b);
280+
281+
auto ok = b == isLess;
282+
if (!ok) {
283+
std::cout << "X=" << x << " Y=" << y << ' ' << ok << " bool: " << b << std::endl;
284+
BOOST_TEST(ok);
285+
}
286+
}
287+
}
288+
}
289+
290+
241291
BOOST_AUTO_TEST_CASE(Delta_function_test
242292
, *disabled() // FIXME:
243293
) { // https://en.wikipedia.org/wiki/Dirac_delta_function
@@ -294,9 +344,9 @@ BOOST_AUTO_TEST_CASE(ifz_tests) {
294344
}
295345
}
296346

297-
BOOST_AUTO_TEST_CASE(Less_operator_test
298-
, *disabled() // FIXME:
299-
) {
347+
BOOST_AUTO_TEST_CASE(Less_cmp_test
348+
, *disabled() // FIXME:
349+
){
300350
DECL_VARS(X, Y);
301351
auto Less = X.Less(Y);
302352
std::cout << "X<Y : " << Less << std::endl;
@@ -322,10 +372,10 @@ BOOST_AUTO_TEST_CASE(Less_operator_test
322372
std::cout << std::endl << x << "<" << y << " : " << b << std::endl;
323373
} else if (boolLessOp == false) {
324374
BOOST_TEST(boolLessOp.IsInt());
325-
b = lessOperatorInstantiation == 0;
375+
b = lessOperatorInstantiation.IsZero();
326376
std::cout << std::endl
327-
<< x << "<" << y << " : " << b << ' ' << lessOperatorInstantiation << " != 0"
328-
<< std::endl;
377+
<< x << "<" << y << " : " << (b ? "true; " : "false; ")
378+
<< lessOperatorInstantiation << " != 0" << std::endl;
329379
} else {
330380
std::cout << std::endl << x << "<" << y << " : " << boolLessOp << std::endl;
331381
BOOST_TEST(!"boolLessOp must have boolean value");

0 commit comments

Comments
 (0)