Package org.orangegears.parser

Examples of org.orangegears.parser.ExpressionTree


import junit.framework.TestCase;

public class ExpressionTreeTest extends TestCase {
    public void testGetTree() throws Exception{
        String data = "0;";
        ExpressionTree eTree = null;
       
        eTree = new ExpressionTree(data);
        assertEquals("Value", eTree.getTree().getText(), "0");
       
        data = "1 + 2;";
        eTree = new ExpressionTree(data);
        assertEquals("Plus1", eTree.getTree().getText(), "+");
        assertEquals("Plus2", eTree.getTree().getChild(0).getText(), "1");
        assertEquals("Plus3", eTree.getTree().getChild(1).getText(), "2");
       
        data = "3 - 4;";
        eTree = new ExpressionTree(data);
        assertEquals("Minus1", eTree.getTree().getText(), "-");
        assertEquals("Minus2", eTree.getTree().getChild(0).getText(), "3");
        assertEquals("Minus3", eTree.getTree().getChild(1).getText(), "4");
       
        data = "5 * 6;";
        eTree = new ExpressionTree(data);
        assertEquals("Mul1", eTree.getTree().getText(), "*");
        assertEquals("Mul2", eTree.getTree().getChild(0).getText(), "5");
        assertEquals("Mul3", eTree.getTree().getChild(1).getText(), "6");
       
        data = "7 / 8;";
        eTree = new ExpressionTree(data);
        assertEquals("Div1", eTree.getTree().getText(), "/");
        assertEquals("Div2", eTree.getTree().getChild(0).getText(), "7");
        assertEquals("Div3", eTree.getTree().getChild(1).getText(), "8");
       
        data = "1 + 2 * 3 / 4 - 5;";
        eTree = new ExpressionTree(data);
        assertEquals("Op1", eTree.getTree().getText(), "-");
        assertEquals("Op2", eTree.getTree().getChild(0).getText(), "+");
        assertEquals("Op3", eTree.getTree().getChild(1).getText(), "5");
        assertEquals("Op4", eTree.getTree().getChild(0).getChild(0).getText(), "1");
        assertEquals("Op5", eTree.getTree().getChild(0).getChild(1).getText(), "/");
        assertEquals("Op6", eTree.getTree().getChild(0).getChild(1).getChild(0).getText(), "*");
        assertEquals("Op7", eTree.getTree().getChild(0).getChild(1).getChild(1).getText(), "4");
        assertEquals("Op8", eTree.getTree().getChild(0).getChild(1).getChild(0).getChild(0).getText(), "2");
        assertEquals("Op9", eTree.getTree().getChild(0).getChild(1).getChild(0).getChild(1).getText(), "3");
       
        data = "(1 + 2) * 3;";
        eTree = new ExpressionTree(data);
        assertEquals("Par1.1", eTree.getTree().getText(), "*");
        assertEquals("Par1.2", eTree.getTree().getChild(0).getText(), "+");
        assertEquals("Par1.3", eTree.getTree().getChild(1).getText(), "3");
        assertEquals("Par1.4", eTree.getTree().getChild(0).getChild(0).getText(), "1");
        assertEquals("Par1.5", eTree.getTree().getChild(0).getChild(1).getText(), "2");
       
        data = "2 * (4 / 3);";
        eTree = new ExpressionTree(data);
        assertEquals("Par2.1", eTree.getTree().getText(), "*");
        assertEquals("Par2.2", eTree.getTree().getChild(0).getText(), "2");
        assertEquals("Par2.3", eTree.getTree().getChild(1).getText(), "/");
        assertEquals("Par2.4", eTree.getTree().getChild(1).getChild(0).getText(), "4");
        assertEquals("Par2.5", eTree.getTree().getChild(1).getChild(1).getText(), "3");
       
        data = "#9;";
        eTree = new ExpressionTree(data);
        assertEquals("Var1", eTree.getTree().getText(), "#9");
       
        data = "#test;";
        eTree = new ExpressionTree(data);
        assertEquals("Var2", eTree.getTree().getText(), "#test");
       
        data = "func(3);";
        eTree = new ExpressionTree(data);
        assertEquals("func1.1", eTree.getTree().getText(), "func");
        assertEquals("func1.2", eTree.getTree().getChild(0).getText(), "3");
       
        data = "qwert(#56);";
        eTree = new ExpressionTree(data);
        assertEquals("func2.1", eTree.getTree().getText(), "qwert");
        assertEquals("func2.2", eTree.getTree().getChild(0).getText(), "#56");
       
        data = "asdf(ghjk());";
        eTree = new ExpressionTree(data);
        assertEquals("func3.1", eTree.getTree().getText(), "asdf");
        assertEquals("func3.2", eTree.getTree().getChild(0).getText(), "ghjk");
       
        data = "d111(67 / #gl);";
        eTree = new ExpressionTree(data);
        assertEquals("func3.1", eTree.getTree().getText(), "d111");
        assertEquals("func3.2", eTree.getTree().getChild(0).getText(), "/");
        assertEquals("func3.2", eTree.getTree().getChild(0).getChild(0).getText(), "67");
        assertEquals("func3.2", eTree.getTree().getChild(0).getChild(1).getText(), "#gl");
       
        data = "12 * ( func(345-#yes/func2(#44)) - #NO);";
        eTree = new ExpressionTree(data);
        assertEquals("Comb1", eTree.getTree().getText(), "*");
        assertEquals("Comb2", eTree.getTree().getChild(0).getText(), "12");
        assertEquals("Comb3", eTree.getTree().getChild(1).getText(), "-");
        assertEquals("Comb4", eTree.getTree().getChild(1).getChild(0).getText(), "func");
        assertEquals("Comb5", eTree.getTree().getChild(1).getChild(1).getText(), "#NO");
        assertEquals("Comb6", eTree.getTree().getChild(1).getChild(0).getChild(0).getText(), "-");
        assertEquals("Comb7", eTree.getTree().getChild(1).getChild(0).getChild(0).getChild(0).getText(), "345");
        assertEquals("Comb8", eTree.getTree().getChild(1).getChild(0).getChild(0).getChild(1).getText(), "/");
        assertEquals("Comb9", eTree.getTree().getChild(1).getChild(0).getChild(0).getChild(1).getChild(0).getText(), "#yes");
        assertEquals("Comb10", eTree.getTree().getChild(1).getChild(0).getChild(0).getChild(1).getChild(1).getText(), "func2");
        assertEquals("Comb11", eTree.getTree().getChild(1).getChild(0).getChild(0).getChild(1).getChild(1).getChild(0).getText(), "#44");
    }
View Full Code Here

TOP

Related Classes of org.orangegears.parser.ExpressionTree

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.