1 /***
2 * ArithmeticOperatorTest.java
3 *
4 * $Author: mballesteros $
5 * $Date: 2003/11/28 19:18:03 $
6 * $Revision: 1.1 $
7 */
8 package net.sf.jec;
9
10 import java.util.HashMap;
11
12 import net.sf.jec.ArithmeticOperator;
13 import net.sf.jec.ConstantOperator;
14 import net.sf.jec.EvaluationException;
15
16 import junit.framework.TestCase;
17
18 /***
19 * @author mballesteros
20 */
21 public class ArithmeticOperatorTest extends TestCase {
22
23
24
25 /***
26 * Constructor for ArithmeticOperatorTest.
27 * @param arg0
28 */
29 public ArithmeticOperatorTest(String arg0) {
30 super(arg0);
31 }
32
33 private HashMap ctx;
34
35 /*
36 * @see TestCase#setUp()
37 */
38 protected void setUp() throws Exception {
39 ctx = new HashMap();
40 super.setUp();
41 }
42
43 public void testApply() throws EvaluationException {
44
45 ConstantOperator d166 = new ConstantOperator(new Double(166.386));
46 ConstantOperator i10 = new ConstantOperator(new Integer(10));
47 ConstantOperator f166 = new ConstantOperator(new Float(166.386));
48 ConstantOperator aaa = new ConstantOperator("aaa");
49 ConstantOperator bbb = new ConstantOperator("bbb");
50
51 ArithmeticOperator aop;
52
53 // Probando '+'
54 aop = new ArithmeticOperator("+", d166, i10, false);
55 assertEquals(aop.apply(ctx, ctx), new Double(166.386+10));
56 aop = new ArithmeticOperator("+", d166, f166, false);
57 assertEquals(aop.apply(ctx, ctx), new Double(166.386+166.386));
58 aop = new ArithmeticOperator("+", aaa, bbb, false);
59 assertEquals(aop.apply(ctx, ctx), "aaabbb");
60
61 // Probando '-'
62 aop = new ArithmeticOperator("-", d166, i10, false);
63 assertEquals(aop.apply(ctx, ctx), new Double(166.386-10));
64 aop = new ArithmeticOperator("-", d166, f166, false);
65 assertEquals(aop.apply(ctx, ctx), new Double(166.386-166.386));
66
67 // Probando '*'
68 aop = new ArithmeticOperator("*", d166, i10, false);
69 assertEquals(aop.apply(ctx, ctx), new Double(166.386*10));
70 aop = new ArithmeticOperator("*", d166, f166, false);
71 assertEquals(aop.apply(ctx, ctx), new Double(166.386*166.386));
72
73 // Probando '/'
74 aop = new ArithmeticOperator("/", d166, i10, false);
75 assertEquals(aop.apply(ctx, ctx), new Double(166.386/10));
76 aop = new ArithmeticOperator("/", d166, f166, false);
77 assertEquals(aop.apply(ctx, ctx), new Double(166.386/166.386));
78
79 // Probando '%'
80 aop = new ArithmeticOperator("%", i10, i10, false);
81 assertEquals(aop.apply(ctx, ctx), new Integer(10%10));
82 }
83
84 }
This page was automatically generated by Maven