package eu.uqasar.model.formula;

/*
 * #%L
 * U-QASAR
 * %%
 * Copyright (C) 2012 - 2015 U-QASAR Consortium
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */


import org.jboss.solder.logging.Logger;
import org.junit.Assert;
import org.junit.Test;

public class FormulaTest {

	private static Logger logger = Logger.getLogger(FormulaTest.class);

	/**
	 * Test evaluation of a valid formula string. 
	 */
	@Test
	public void testEvalFormulaStr() {

		logger.info("Test eval formula String");

		Double expected = 15.0;
		String evalStr = "5*3";
		Object resObject = Formula.evalFormulaStr(evalStr);
		Assert.assertNotNull(resObject);
		Double result = (Double) resObject;
		Assert.assertEquals(expected, result);
	}
	
	/**
	 * Test a null formula 
	 */
	@Test
	public void testNullFormula() {
		logger.info("Test null Formula");
		String formula = null;
		Object resObject = Formula.evalFormula(formula);
		Assert.assertNull(resObject);
	}
	
	/**
	 * Test an invalid formula; should return null value
	 */
	public void testInvalidFormula() {
		logger.info("Test invalid Formula");
		String formula = "ax";
		Object resObject = Formula.evalFormula(formula);
		Assert.assertNull(resObject);
	}
}

@@ -1025,18 +1025,37 @@
 tring%22);
-%0D
 %0A
+%09%09%0D%0A%09%09Double result;
 %0D%0A%09%09Doub
@@ -1191,27 +1191,119 @@
 Object);
-%0D
 %0A%09%09
-Double 
+if (resObject instanceof Integer) %7B%0A%09%09%09result = ((Integer) resObject).doubleValue();%0A%09%09%7D else %7B%0D%0A%09%09%09
 result =
@@ -1322,16 +1322,20 @@
 sObject;
+%0A%09%09%7D
 %0D%0A%09%09Asse

fix failing test case