achart engine added + fixes

This commit is contained in:
serso 2011-11-19 21:45:19 +04:00
parent 734d4c7216
commit 4800223057
4 changed files with 21 additions and 11 deletions

View File

@ -65,6 +65,15 @@
</exclusions> </exclusions>
</dependency> </dependency>
<dependency>
<groupId>achartengine</groupId>
<artifactId>achartengine</artifactId>
<version>0.7.0</version>
<scope>system</scope>
<systemPath>${additionalLibs}/achartengine-0.7.0.jar</systemPath>
</dependency>
<dependency> <dependency>
<groupId>com.intellij</groupId> <groupId>com.intellij</groupId>
<artifactId>annotations</artifactId> <artifactId>annotations</artifactId>

View File

@ -188,6 +188,9 @@ public enum CalculatorEngine {
} catch (ArithmeticException e) { } catch (ArithmeticException e) {
//System.out.println(e.getMessage()); //System.out.println(e.getMessage());
exception.setObject(new ParseException(e.getMessage(), e)); exception.setObject(new ParseException(e.getMessage(), e));
} catch (StackOverflowError e) {
//System.out.println(StringUtils.fromStackTrace(e.getStackTrace()));
exception.setObject(new ParseException(e.getMessage(), e));
} catch (jscl.text.ParseException e) { } catch (jscl.text.ParseException e) {
//System.out.println(e.getMessage()); //System.out.println(e.getMessage());
exception.setObject(new ParseException(e.getMessage(), e)); exception.setObject(new ParseException(e.getMessage(), e));

Binary file not shown.

View File

@ -157,12 +157,7 @@ public class CalculatorEngineTest {
Assert.assertEquals("3.957", cm.evaluate(JsclOperation.numeric, "ln(8)lg(8)+ln(8)").getResult()); Assert.assertEquals("3.957", cm.evaluate(JsclOperation.numeric, "ln(8)lg(8)+ln(8)").getResult());
Assert.assertEquals("0", cm.evaluate(JsclOperation.numeric, "((((((0))))))").getResult()); Assert.assertEquals("0", cm.evaluate(JsclOperation.numeric, "((((((0))))))").getResult());
try {
Assert.assertEquals("0", cm.evaluate(JsclOperation.numeric, "((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((0))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))").getResult()); Assert.assertEquals("0", cm.evaluate(JsclOperation.numeric, "((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((0))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))").getResult());
fail();
} catch (ParseException e) {
// ok
}
/* Assert.assertEquals("0.524", cm.evaluate(JsclOperation.numeric, "30°").getResult()); /* Assert.assertEquals("0.524", cm.evaluate(JsclOperation.numeric, "30°").getResult());
@ -232,11 +227,7 @@ public class CalculatorEngineTest {
} catch (ParseException e) { } catch (ParseException e) {
} }
try {
Assert.assertEquals("0.739", cm.evaluate(JsclOperation.numeric, "cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(1))))))))))))))))))))))))))))))))))))").getResult()); Assert.assertEquals("0.739", cm.evaluate(JsclOperation.numeric, "cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(1))))))))))))))))))))))))))))))))))))").getResult());
Assert.fail();
} catch (ParseException e) {
}
CalculatorEngine.instance.getVarsRegister().add(new Var.Builder("si", 5d)); CalculatorEngine.instance.getVarsRegister().add(new Var.Builder("si", 5d));
Assert.assertEquals("5", cm.evaluate(JsclOperation.numeric, "si").getResult()); Assert.assertEquals("5", cm.evaluate(JsclOperation.numeric, "si").getResult());
@ -312,10 +303,17 @@ public class CalculatorEngineTest {
} catch (ParseException e) { } catch (ParseException e) {
} }
Assert.assertEquals("0.017", cm.evaluate(JsclOperation.numeric, "").getResult()); Assert.assertEquals("0.017", cm.evaluate(JsclOperation.numeric, "").getResult());
Assert.assertEquals("0.349", cm.evaluate(JsclOperation.numeric, "20.0°").getResult()); Assert.assertEquals("0.349", cm.evaluate(JsclOperation.numeric, "20.0°").getResult());
Assert.assertEquals("0.5", cm.evaluate(JsclOperation.numeric, "sin(30°)").getResult()); Assert.assertEquals("0.5", cm.evaluate(JsclOperation.numeric, "sin(30°)").getResult());
Assert.assertEquals("0.524", cm.evaluate(JsclOperation.numeric, "asin(sin(30°))").getResult()); Assert.assertEquals("0.524", cm.evaluate(JsclOperation.numeric, "asin(sin(30°))").getResult());
try {
Assert.assertEquals("∂(cos(t), t, t,1°)", cm.evaluate(JsclOperation.numeric, "∂(cos(t),t,t,1°)").getResult());
fail();
} catch (ParseException e) {
}
Assert.assertEquals("∂(cos(t), t, t,1°)", cm.evaluate(JsclOperation.simplify, "∂(cos(t),t,t,1°)").getResult());
} }
} }