Skip to content

Commit

Permalink
[poincare] Add parenthesis at serialization with LogicalOperator
Browse files Browse the repository at this point in the history
  • Loading branch information
PiaNumworks authored and GabrielNumworks committed Apr 17, 2024
1 parent edd5ea8 commit 4072bfd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion poincare/src/division.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ bool DivisionNode::childNeedsSystemParenthesesAtSerialization(
return static_cast<const ExpressionNode *>(child)->isOfType(
{Type::Subtraction, Type::Opposite, Type::Multiplication, Type::Division,
Type::Addition, Type::PercentSimple, Type::PercentAddition,
Type::MixedFraction, Type::Comparison});
Type::MixedFraction, Type::Comparison, Type::LogicalOperatorNot,
Type::BinaryLogicalOperator});
}

size_t DivisionNode::serialize(char *buffer, size_t bufferSize,
Expand Down
13 changes: 13 additions & 0 deletions poincare/test/expression_serialization.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <poincare/absolute_value.h>
#include <poincare/addition.h>
#include <poincare/based_integer.h>
#include <poincare/comparison.h>
Expand All @@ -11,6 +12,7 @@
#include <poincare/infinity.h>
#include <poincare/logical_operator.h>
#include <poincare/opposite.h>
#include <poincare/parenthesis.h>
#include <poincare/percent.h>
#include <poincare/power.h>
#include <poincare/rational.h>
Expand Down Expand Up @@ -314,6 +316,17 @@ QUIZ_CASE(poincare_serialization_power) {
BinaryLogicalOperator::Builder(
BasedInteger::Builder(3), BasedInteger::Builder(4),
BinaryLogicalOperatorNode::OperatorType::Or))));
assert_expression_serializes_and_parses_to_itself(
AbsoluteValue::Builder(PercentAddition::Builder(
BasedInteger::Builder(0),
Division::Builder(
BasedInteger::Builder(0),
BinaryLogicalOperator::Builder(
Symbol::Builder("r", 1),
Multiplication::Builder(
Symbol::Builder("o", 1), Symbol::Builder("m0", 2),
Parenthesis::Builder(BasedInteger::Builder(0))),
BinaryLogicalOperatorNode::OperatorType::And)))));
}

QUIZ_CASE(poincare_serialization_derivative) {
Expand Down

0 comments on commit 4072bfd

Please sign in to comment.