package testCal;

import cal.ExpressionTree;
import junit.framework.TestCase;

public class ExpressionTreeTest extends TestCase {

    private ExpressionTree expTree;

    public void setUp() throws Exception {
        expTree = new ExpressionTree();
    }

    public void tearDown() throws Exception {
        expTree = null;
    }

    //
    // public void testParseToPostfix() {
    // String expected = "21-342*+-";
    // String result = expTree.parseToPostfix("((2-1)-(3+(4*2)))");
    // assertEquals(expected, result);
    // }


    public void testParseResult() {
        String expected = "-10.0";
        expTree.read("((2-1)-(3+(4*2)))");
        String actual = expTree.execute();
        assertEquals(expected, actual);
    }

}

@@ -532,16 +532,41 @@
   // %7D%0A%0A
+    // nested parentheses
 %0A    pub
@@ -761,11 +761,1631 @@
 ;%0A    %7D%0A
+    // simple calculation%0A    public void testParseResult2() %7B%0A        String expected = %228.0%22;%0A        expTree.read(%22(1+2)*3-1%22);%0A        String actual = expTree.execute();%0A        assertEquals(expected, actual);%0A    %7D%0A    // two parentheses %0A    public void testParseResult3() %7B%0A        String expected = %227.0%22;%0A        expTree.read(%22(1+2)*3-(1*2)%22);%0A        String actual = expTree.execute();%0A        assertEquals(expected, actual);%0A    %7D%0A    %0A    public void testParseResult4() %7B%0A        String expected = %2281.0%22;%0A        expTree.read(%22((1+2)*3)%5E(1*2)%22);%0A        String actual = expTree.execute();%0A        assertEquals(expected, actual);%0A    %7D%0A    //nested parentheses%0A    public void testParseResult5() %7B%0A        String expected = %224.0%22;%0A        expTree.read(%22(1-2)*3-((1*2)-9)%22);%0A        String actual = expTree.execute();%0A        assertEquals(expected, actual);%0A    %7D%0A    // nested parentheses%0A    public void testParseResult6() %7B%0A        String expected = %2210.0%22;%0A        expTree.read(%22(2-1)*3-((1*2)-9)%22);%0A        String actual = expTree.execute();%0A        assertEquals(expected, actual);%0A    %7D%0A    // more complicate case of single level parentheses %0A    public void testParseResult7() %7B%0A        String expected = %2264.0%22;%0A        expTree.read(%22(6+2)*(10*4)/(2*2.5)%22);%0A        String actual = expTree.execute();%0A        assertEquals(expected, actual);%0A    %7D%0A    // nested parentheses with addition only%0A    public void testParseResult8() %7B%0A        String expected = %2227.0%22;%0A        expTree.read(%22((2+3)+5)+((2+8)+(4+3))%22);%0A        String actual = expTree.execute();%0A        assertEquals(expected, actual);%0A    %7D
 %0A%7D%0A

add more test case on expression tree evaluate function