插件开发工具库,推荐依赖该工具库。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.1 KiB

5 years ago
package com.fanruan.api.cal;
import com.fanruan.api.Prepare;
import com.fanruan.api.err.KitError;
import com.fr.base.ParameterMapNameSpace;
import com.fr.script.Calculator;
import com.fr.stable.script.CalculatorProvider;
import com.fr.stable.script.NameSpace;
import org.junit.Assert;
import org.junit.Test;
import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.*;
/**
* @author richie
* @version 10.0
* Created by richie on 2019-08-15
*/
public class FormulaKitTest extends Prepare {
@Test
public void eval() {
try {
Assert.assertEquals(4, FormulaKit.eval("=(6+6)/3"));
} catch (KitError kitError) {
Assert.fail();
}
}
@Test
public void testEval() {
CalculatorProvider calculator = Calculator.createCalculator();
Map<String, Object> map = new HashMap<>();
map.put("a", 1);
map.put("b", 2);
calculator.pushNameSpace(ParameterMapNameSpace.create(map));
try {
Assert.assertEquals(1, FormulaKit.eval(calculator,"=($a+$b)/3"));
} catch (KitError kitError) {
Assert.fail();
}
}
}