1 21 22 package net.percederberg.grammatica.test; 23 24 import java.util.HashMap ; 25 26 import junit.framework.TestCase; 27 28 34 public class TestArithmeticCalculator extends TestCase { 35 36 39 private static final String VALID_INPUT = 40 "1 + 2*a\n" + 41 " + 345"; 42 43 46 private HashMap variables = new HashMap (); 47 48 53 public TestArithmeticCalculator(String name) { 54 super(name); 55 variables.put("a", new Integer (2)); 56 } 57 58 61 public void testValidExpression() { 62 calculate(VALID_INPUT, 350); 63 } 64 65 73 private void calculate(String expr, int result) { 74 ArithmeticCalculator calc; 75 76 try { 77 calc = new ArithmeticCalculator(variables); 78 assertEquals("expression result", result, calc.calculate(expr)); 79 } catch (Exception e) { 80 fail(e.getMessage()); 81 } 82 } 83 } 84 | Popular Tags |