auto-sync

This commit is contained in:
rusEfi 2017-01-17 19:02:44 -05:00
parent ba2050255c
commit 07ba032b0a
2 changed files with 18 additions and 2 deletions

View File

@ -60,7 +60,7 @@ public class BracerParser {
* correct
* @since 3.0
*/
public void parse(String expression) throws ParseException {
public BracerParser parse(String expression) throws ParseException {
/* cleaning stacks */
stackOperations.clear();
stackRPN.clear();
@ -140,6 +140,7 @@ public class BracerParser {
/* reverse stack */
Collections.reverse(stackRPN);
return this;
}
/**
@ -170,8 +171,16 @@ public class BracerParser {
stackAnswer.push(token);
} else if (isOperator(token)) {
Double a = Double.valueOf(stackAnswer.pop());
Double b = Double.valueOf(stackAnswer.pop());
boolean aBoolean = a.doubleValue() == 1.0;
if (token.equals("!")) {
stackAnswer.push(String.valueOf(aBoolean ? "1" : "0"));
continue;
}
if (stackAnswer.isEmpty())
throw new IllegalStateException("While " + token + " and " + a);
Double b = Double.valueOf(stackAnswer.pop());
boolean bBoolean = b.doubleValue() == 1.0;
switch (token) {
case "+":

View File

@ -109,6 +109,13 @@ public class BracerParserTest {
@Test
public void testBooleanNot2() throws Exception {
assertEquals("0", bracerParser.parse("! false").evaluate());
assertEquals("0", bracerParser.parse("! 0").evaluate());
assertEquals("0", bracerParser.parse("1 & not(false)").evaluate());
assertEquals("0", bracerParser.parse("1 & (!(false))").evaluate());
// assertEquals("0", bracerParser.parse("1 & !(0)").evaluate());
// assertEquals("0", bracerParser.parse("1 & !(false)").evaluate());
bracerParser.parse("1 & not(false)");
assertEquals("0", bracerParser.evaluate());// todo: this does not seem right
assertEquals("1 not 0 &", bracerParser.getRusEfi()); // todo: this does not seem right