Thursday, February 9, 2012

Testing Calculator

(1-2) * 13/16
(1-2) * (13/16
(pow(1,2))*(13/16)

I expect all errors, because my calculator does not presently handle parenthesis. (First iteration did, but I scrapped that because I thought it was necessary to get operation based tree-construction working first...)

Also, I just realized that I am only handling ints (not floats...)

To get any output, I would have to delete the ()s. For this iteration's sake, here are the results:

Please enter an equation:
1-2*13/16
You entered:
1-2*13/16
NOT base case 1-2*13/16
 Reached base case: 1
NOT base case 2*13/16
 Reached base case: 2
NOT base case 13/16
 Reached base case: 13
 Reached base case: 16
0

Another item I failed to include was "pow." (I understood in lab that the equation would be 'flat,' or linear. Misinterp of requirements, apparently.)

It is painstakingly obvious what is not happening....but ...

Examining what IS "happening" 
AKA what I (erroneously?) THINK is happening:


1-2*13/16

     -  
   /   \
1      *
       /   \
     2     "/"
           /    \
         13    16

1-2*13/16 = 1-1.something --> 0 (because ints truncate)

Traversing the tree (printing out each node as I travel left to right):



LEAF:
1
LEAF:
2
LEAF:
13
LEAF:
16
/
*
-


The fact that LEAF appears before each number is comforting, though I would expect the following:
1
2
13
16
/
*
-

...But that's what I'm getting.... OK- logic error traversing the tree. AArgh.

No comments:

Post a Comment