// Language Level Converter line number map: dj*->java. Entries: 45 // 1->8 2->10 3->11 4->12 5->13 6->14 7->15 8->16 // 9->17 10->18 11->19 12->20 13->21 14->22 15->23 16->24 // 17->25 18->26 19->27 20->28 21->29 22->30 23->31 24->32 // 25->33 26->34 27->35 28->36 29->37 30->38 31->39 32->40 // 33->41 34->42 35->43 36->44 37->45 38->46 39->47 40->48 // 41->49 42->50 43->51 44->52 45->53 import junit.framework.TestCase; /** The test case class for the ArithExpr composite hierarchy. */ public class ArithExprTest extends TestCase { public final static Double EPSILON = 1.1e-16; public final static Const zero = new Const(0.); public final static Const negSeven = new Const(-7.); public final static Const five = new Const(5.); public final static Const negTen = new Const(-10.); public final static Const ten = new Const(10.); public final static Const twentyFive = new Const(25.); public final static Var x = new Var("x"); public final static Var y = new Var("y"); public final static Var z = new Var("z"); /** Tests the eval() method in the ArithExpr composite. */ public void testExprPrint() { assertEquals("const 0.", "0.0", zero.exprString()); assertEquals("const -7.", "-7.0", negSeven.exprString()); assertEquals("const -10.", "-10.0", negTen.exprString()); assertEquals("5 + 5", "(5.0 + 5.0)", new Sum(five, five).exprString()); assertEquals("5 * 10", "(5.0 * 10.0)", new Prod(five, ten).exprString()); assertEquals("10/5", "(10.0 / 5.0)", new Quot(ten, five).exprString()); assertEquals("10 - 5", "(10.0 - 5.0)", new Diff(ten, five).exprString()); assertEquals("x * x", "(x * x)", new Prod(x, x).exprString()); assertEquals("y/z", "(y / z)", new Quot(y, z).exprString()); } public final static EmptyEnv e = EmptyEnv.ONLY; public final static Env env1 = e.cons("x", -10.).cons("y", 25.).cons("z", -5.); /** Tests the eval() method in the ArithExpr composite. */ public void testEval() { assertEquals("const 0.", 0., zero.eval(e), EPSILON); assertEquals("const 7.", -7., negSeven.eval(e), EPSILON); assertEquals("const -10.", -10., negTen.eval(e), EPSILON); assertEquals("25 + 5", 30., new Sum(twentyFive, five).eval(e), EPSILON); assertEquals("-7 * 10", -70., new Prod(negSeven, ten).eval(e), EPSILON); assertEquals("25/5", 5., new Quot(twentyFive, five).eval(e), EPSILON); assertEquals("25 - 5", 20., new Diff(twentyFive, five).eval(e), EPSILON); assertEquals("x * z", 50., new Prod(negTen, z).eval(env1), EPSILON); assertEquals("y/z", -5., new Quot(y, z).eval(env1), EPSILON); } /** This method is automatically generated by the Language Level Converter. */ public ArithExprTest() { super(); } /** This method is automatically generated by the Language Level Converter. */ public java.lang.String toString() { return getClass().getName() + "(" + ")"; } /** This method is automatically generated by the Language Level Converter. */ public boolean equals(java.lang.Object o) { if (this == o) { return true; } else if ((o == null) || (! o.getClass().equals(getClass()))) { return false; } else { ArithExprTest cast = ((ArithExprTest) o); return true; } } /** This method is automatically generated by the Language Level Converter. */ public int hashCode() { return getClass().hashCode(); } }