package org.masking.finexpr;

import java.math.BigDecimal;
import java.math.MathContext;
import java.util.List;

import org.masking.finexpr.expr.Expression;
import org.masking.finexpr.function.Function;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

/**
 * Unit test for simple App.
 */
public class ExpressionTest extends TestCase {
	/**
	 * Create the test case
	 *
	 * @param testName
	 *            name of the test case
	 */
	public ExpressionTest(String testName) {
		super(testName);
	}

	/**
	 * @return the suite of tests being tested
	 */
	public static Test suite() {
		return new TestSuite(ExpressionTest.class);
	}

	/**
	 * Test :-)
	 */
	public void testExpr() {
		Expression e = new Expression("fx(9, 7.3, x)+2^3");
		e.addFunction(new Function("fx", 3){
			@Override
			public BigDecimal apply(List<BigDecimal> args, MathContext mc) {
				return args.get(0).add(args.get(1),mc).subtract(args.get(2),mc);
			}
		});
		e.addVariable("x", new BigDecimal("8.5"));	
		System.out.println(e.calculate());
		assertTrue(true);
	}
}

@@ -759,28 +759,55 @@
 on(%22
-fx(9, 7.3, x)+2%5E3%22);
+add(x,y) + a%5Eb%22);%0A%09%09%0A%09%09// define function %22add%22
 %0A%09%09e
@@ -837,14 +837,15 @@
 on(%22
-fx%22, 3
+add%22, 2
 )%7B%0A%09
@@ -970,146 +970,494 @@
 ,mc)
-.subtract(args.get(2),mc);%0A%09%09%09%7D%0A%09%09%7D);%0A%09%09e.addVariable(%22x%22, new BigDecimal(%228.5%22));%09%0A%09%09System.out.println(e.calculate());%0A%09%09assertTrue(true
+;%0A%09%09%09%7D%0A%09%09%7D);%0A%09%09%0A%09%09/*%0A%09%09 *  set variables, %0A%09%09 *  in this case:%0A%09%09 *  the expression %0A%09%09 *  = add(8.5,5.77) + 5%5E3 %0A%09%09 *  = 8.5+5.77 + 5%5E3 %0A%09%09 *  = 14.27 + 125 %0A%09%09 *  = 139.27%0A%09%09 */%0A%09%09e.addVariable(%22x%22, new BigDecimal(%228.5%22));%09%0A%09%09e.addVariable(%22y%22, new BigDecimal(%225.77%22));%09%0A%09%09e.addVariable(%22a%22, new BigDecimal(%225%22));%09%0A%09%09e.addVariable(%22b%22, new BigDecimal(%223%22));%09%0A%09%09%0A%09%09BigDecimal result = e.calculate();%0A%09%09System.out.println(result);%0A%09%09%0A%09%09assertTrue(result.equals(new BigDecimal(%22139.27%22))
 );%0A%09

add test