@Test(expected = InvalidTypeException.class) public void nullIsNotAllowed() throws PseudoException { NullEvaluator op1 = new NullEvaluator(); IntegerEvaluator op2 = new IntegerEvaluator(0); MultEvaluator evaluator = new MultEvaluator(op1, op2); evaluator.evaluate(scope); fail("Cannot perform arithmetic on Null."); }
@Test(expected = InvalidTypeException.class) public void stringMultipliedByStringIsNotAllowed() throws PseudoException { MultEvaluator evaluator = new MultEvaluator(new StringEvaluator("9"), new StringEvaluator("3")); evaluator.evaluate(scope); fail("A string cannot be used in division."); }
@Test public void integerMultipliedByDoubleIsADouble() throws PseudoException { MultEvaluator evaluator = new MultEvaluator(new IntegerEvaluator(0), new DoubleEvaluator(0.0)); Type ret = evaluator.evaluate(scope); assertEquals("0*0.0 must be double 0.0.", 0.0, (Double) ret.getValue(), 0.01); }
@Test public void doubleMultipliedByIntegerIsADouble() throws PseudoException { MultEvaluator evaluator = new MultEvaluator(new DoubleEvaluator(3.0), new IntegerEvaluator(3)); Type ret = evaluator.evaluate(scope); assertEquals("3.0*3 must be double 9.0.", 9.0, (Double) ret.getValue(), 0.01); }
@Test public void integerMultipliedByIntegerIsAnInteger() throws PseudoException { MultEvaluator evaluator = new MultEvaluator(new IntegerEvaluator(1), new IntegerEvaluator(1)); Type ret = evaluator.evaluate(scope); assertEquals("1*1 must be integer 1.", 1, ret.getValue()); }