From 9adc5a97efc4af8dc9564f1c0b95fc2f28c3ad3f Mon Sep 17 00:00:00 2001 From: fintarin Date: Mon, 19 Feb 2024 11:17:44 +0300 Subject: [PATCH] Fix comparisons with Undefined --- .../expressions/binary/CompExpression.cpp | 9 +++++--- .../simplify/SimplifyInfinityTests.cpp | 21 +++++++++---------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/fintamath/expressions/binary/CompExpression.cpp b/src/fintamath/expressions/binary/CompExpression.cpp index 802857234..31845dac9 100644 --- a/src/fintamath/expressions/binary/CompExpression.cpp +++ b/src/fintamath/expressions/binary/CompExpression.cpp @@ -120,10 +120,13 @@ std::shared_ptr CompExpression::getOppositeFunction(const IFunction & } ArgumentPtr CompExpression::constSimplify(const IFunction &func, const ArgumentPtr &lhs, const ArgumentPtr &rhs) { + if (is(lhs) || is(rhs)) { + // TODO: return LogicUndefined + return makeExpr(func, Undefined(), Undefined()); + } + if ((is(lhs) && containsInfinity(rhs)) || - (is(rhs) && containsInfinity(lhs)) || - is(lhs) || - is(rhs)) { + (is(rhs) && containsInfinity(lhs))) { return {}; } diff --git a/tests/src/overall/simplify/SimplifyInfinityTests.cpp b/tests/src/overall/simplify/SimplifyInfinityTests.cpp index 5be465fb9..139f7b26c 100644 --- a/tests/src/overall/simplify/SimplifyInfinityTests.cpp +++ b/tests/src/overall/simplify/SimplifyInfinityTests.cpp @@ -687,25 +687,24 @@ TEST(SimplifyInfinityTests, simplifyTest) { EXPECT_EQ(Expression("sin(Undefined)").toString(), "Undefined"); - // TODO: support LogicUndefined EXPECT_EQ(Expression("Undefined = Undefined").toString(), - "Undefined = 0"); + "Undefined = Undefined"); EXPECT_EQ(Expression("0/0 = 0/0").toString(), - "Undefined = 0"); + "Undefined = Undefined"); EXPECT_EQ(Expression("(sin(x)^2 + cos(x)^2 - 1)/0 = 0/(sin(x)^2 + cos(x)^2 - 1)").toString(), - "Undefined = 0"); + "Undefined = Undefined"); EXPECT_EQ(Expression("Inf - Inf = 0").toString(), - "Undefined = 0"); + "Undefined = Undefined"); EXPECT_EQ(Expression("Inf - Inf = 0 | a").toString(), - "a | Undefined = 0"); + "a | Undefined = Undefined"); EXPECT_EQ(Expression("Undefined < Undefined").toString(), - "Undefined < 0"); + "Undefined < Undefined"); EXPECT_EQ(Expression("0/0 < 0/0").toString(), - "Undefined < 0"); + "Undefined < Undefined"); EXPECT_EQ(Expression("(sin(x)^2 + cos(x)^2 - 1)/0 < 0/(sin(x)^2 + cos(x)^2 - 1)").toString(), - "Undefined < 0"); + "Undefined < Undefined"); EXPECT_EQ(Expression("Inf - Inf < 0").toString(), - "Undefined < 0"); + "Undefined < Undefined"); EXPECT_EQ(Expression("Inf - Inf < 0 | a").toString(), - "a | Undefined < 0"); + "a | Undefined < Undefined"); }