package com.sunxung.factoring.component.util;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

public class FormulaTest {

    public static void testFormula() {
        // 基础数据
        Map<String, BigDecimal> values = new HashMap<String, BigDecimal>();
        values.put("dddd", BigDecimal.valueOf(56d));
        values.put("yszk", BigDecimal.valueOf(-12d));
        // 需要依赖的其他公式
        Map<String, String> formulas = new HashMap<String, String>();
        formulas.put("eeee", "#{dddd}+20");
        // 需要计算的公式
        String expression = "#{eeee}*-12+13-#{dddd}+24";
        String expression2 = "(#{dddd}+20)*#{yszk}+13-#{dddd}+24";
        BigDecimal result = FormulaParser.parse(expression, formulas, values);
        BigDecimal result2 = FormulaParser.parse(expression2, null, values);
        System.out.println(result);
        System.out.println(result2);
        Map<String, BigDecimal> testValues = new HashMap<String, BigDecimal>();
        testValues.put("zichan.hbzj", BigDecimal.valueOf(10d));
        testValues.put("fuzhai.jyxjf", BigDecimal.valueOf(10d));
        testValues.put("zichan.yszk", BigDecimal.valueOf(20d));
        testValues.put("fuzhai.yfxc", BigDecimal.valueOf(10d));
        testValues.put("fuzhai.hej", BigDecimal.valueOf(10d));
        String testExpression = "#{zichan.hbzj}*#{fuzhai.jyxjf}+(#{zichan.yszk}-#{fuzhai.yfxc})/#{fuzhai.hej}";
        BigDecimal testResult = FormulaParser.parse(testExpression, null, testValues);
        System.out.println(testResult);
    }
    /*
     * public static void main(String[] args) { testFormula(); }
     */

    public static void main(String[] args) {
        // 基础数据
        Map<String, BigDecimal> values = new HashMap<String, BigDecimal>();
        values.put("2", BigDecimal.valueOf(56d));
        values.put("24", BigDecimal.valueOf(-12d));
        String expression2 = "(#{2}+20)*#{24}+13-#{2}+24";
        BigDecimal result2 = FormulaParser.parse(expression2, null, values);
        System.out.println(result2);
    }
}
