Skip to content

Commit

Permalink
Remove ExpressionElement#simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
coderbot16 committed Dec 22, 2021
1 parent 4e5d704 commit c3aa594
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 31 deletions.
6 changes: 0 additions & 6 deletions src/main/java/kroppeb/stareval/element/ExpressionElement.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
package kroppeb.stareval.element;

public interface ExpressionElement extends Element {
@Override
String toString();

default ExpressionElement simplify() {
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,4 @@ public BinaryExpressionElement(BinaryOp op, ExpressionElement left, ExpressionEl
public String toString() {
return "BinaryExpr{ {" + this.left + "} " + this.op + " {" + this.right + "} }";
}

@Override
public ExpressionElement simplify() {
this.left = this.left.simplify();
this.right = this.right.simplify();
return this;
}
}
9 changes: 0 additions & 9 deletions src/main/java/kroppeb/stareval/element/tree/FunctionCall.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,4 @@ public FunctionCall(String id, List<ExpressionElement> args) {
public String toString() {
return "FunctionCall{" + this.id + " {" + this.args + "} }";
}

@Override
public ExpressionElement simplify() {
for (int i = 0; i < this.args.size(); i++) {
this.args.set(i, this.args.get(i).simplify());
}

return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,4 @@ public UnaryExpressionElement(UnaryOp op, ExpressionElement inner) {
public String toString() {
return "UnaryExpr{" + this.op + " {" + this.inner + "} }";
}

@Override
public ExpressionElement simplify() {
this.inner = this.inner.simplify();
return this;
}
}
7 changes: 4 additions & 3 deletions src/test/java/kroppeb/stareval/parser/ParserTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package kroppeb.stareval.parser;

import kroppeb.stareval.element.Element;
import kroppeb.stareval.exception.ParseException;
import kroppeb.stareval.element.ExpressionElement;
import org.junit.jupiter.params.ParameterizedTest;
Expand Down Expand Up @@ -37,8 +38,8 @@ void checkIfInvalidExpressionsDontParse(String input) {
@ParameterizedTest
@CsvFileSource(resources = "/fullyEquivalent.csv", delimiter = ';')
void checkOrderOfOperationsParse(String input1, String input2) throws ParseException {
ExpressionElement exp1 = parse(input1);
ExpressionElement exp2 = parse(input2);
assertEquals(exp1.simplify().toString(), exp2.simplify().toString());
Element exp1 = parse(input1);
Element exp2 = parse(input2);
assertEquals(exp1.toString(), exp2.toString());
}
}

0 comments on commit c3aa594

Please sign in to comment.