1 8 9 15 package tests.jfun.parsec; 16 17 import jfun.parsec.Parser; 18 import junit.framework.TestCase; 19 20 public class CalculatorTestCase extends TestCase { 21 public void test1(){ 22 final Parser p = new Calculator().getParser(); 23 final String src = "1+1*2-10 2"; 24 final Object obj = p.parse(src); 25 assertEquals(obj, new Double (-17)); 26 } 27 public void test1a(){ 28 final Parser p = new Calculator().getParser(); 29 final String src = "1+1 2-10"; 30 final Object obj = p.parse(src); 31 assertEquals(obj, new Double (-7)); 32 } 33 public void testUnaryOperator(){ 34 final Parser p = new Calculator().getParser(); 35 final String src = "-1+1*2-10 2"; 36 final Object obj = p.parse(src); 37 assertEquals(obj, new Double (-19)); 38 } 39 40 public void test2(){ 41 final Parser p = new Calculator().getParser(); 42 final String src = "/*this is beginning**/(1+1+ 2.1)+3*(((2)-10))//this is end"; 43 final Object obj = p.parse(src); 44 assertEquals(obj, new Double (-19.9)); 45 } 46 } 47 | Popular Tags |