private static void testValidExpression(double expected, String expression) { try { double result = CalculationEngineFactory.defaultEngine().calculate(expression); assertEquals(expected, result); } catch (CalculationException e) { Assert.fail("Exception happened " + e); } }
private static void testInvalidExpression(String expression) { try { CalculationEngineFactory.defaultEngine().calculate(expression); Assert.fail("Successfully evaluate " + expression); } catch (CalculationException e) { Log.d("Test", "Successfully fail"); } }
@Test public void testDivisionByZero3() { try { double result = CalculationEngineFactory.defaultEngine().calculate("(10-10)/(10-10)"); Assert.assertTrue(Double.isNaN(result)); } catch (CalculationException e) { Log.d("Test", "Valid Failure"); } }
@Test public void testDivisionByZero2() { try { double result = CalculationEngineFactory.defaultEngine().calculate("1/(10-10)"); Assert.assertEquals(Double.POSITIVE_INFINITY, result); } catch (CalculationException e) { Log.d("Test", "Valid Failure"); } }