Fix for I calculations

This commit is contained in:
Sergey Solovyev 2012-05-14 14:43:25 +04:00
parent 6c54cf8af0
commit f75bab4a01
6 changed files with 36 additions and 12 deletions

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto" android:versionCode="79" android:versionName="1.3.0" package="org.solovyev.android.calculator">
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto" android:versionCode="79" android:versionName="1.2.34" package="org.solovyev.android.calculator">
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
@ -8,7 +8,7 @@
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="8"/>
<application android:hardwareAccelerated="false" android:icon="@drawable/icon" android:label="@string/c_app_name" android:name=".CalculatorApplication">
<application android:debuggable="true" android:hardwareAccelerated="false" android:icon="@drawable/icon" android:label="@string/c_app_name" android:name=".CalculatorApplication">
<activity android:label="@string/c_app_name" android:name=".CalculatorActivity" android:windowSoftInputMode="adjustPan">

View File

@ -64,7 +64,7 @@
<dependency>
<groupId>org.solovyev</groupId>
<artifactId>jscl</artifactId>
<version>0.0.1</version>
<version>0.0.2</version>
<exclusions>
<exclusion>
<artifactId>xercesImpl</artifactId>
@ -121,6 +121,12 @@
<!--<type>apklib</type>-->
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>11.0.2</version>
</dependency>
<dependency>
<groupId>com.intellij</groupId>
<artifactId>annotations</artifactId>

View File

@ -6,14 +6,14 @@ import android.util.Log;
import android.view.MenuItem;
import org.jetbrains.annotations.NotNull;
import org.solovyev.android.calculator.view.NumeralBaseConverterDialog;
import org.solovyev.android.menu.ActivityMenuItem;
import org.solovyev.android.menu.IdentifiableMenuItem;
/**
* User: serso
* Date: 4/23/12
* Time: 2:25 PM
*/
enum CalculatorMenu implements ActivityMenuItem {
enum CalculatorMenu implements IdentifiableMenuItem {
settings(R.id.main_menu_item_settings){
@Override

View File

@ -114,7 +114,7 @@ public enum CalculatorEngine {
private final AndroidMathRegistry<Operator> postfixFunctionsRegistry = new AndroidPostfixFunctionsRegistry(engine.getPostfixFunctionsRegistry());
@NotNull
@Nullable
private ThreadKiller threadKiller = new AndroidThreadKiller();
// calculation thread timeout in seconds, after timeout thread would be interrupted
@ -256,9 +256,10 @@ public enum CalculatorEngine {
final Thread calculationThreadLocal = calculationThread.getObject();
if (calculationThreadLocal != null) {
// todo serso: interrupt doesn't stop the thread but it MUST be killed
threadKiller.killThread(calculationThreadLocal);
//calculationThreadLocal.stop();
if (threadKiller != null) {
threadKiller.killThread(calculationThreadLocal);
}
//calculationThreadLocal.stop();
}
if (parseExceptionObject != null || evalExceptionObject != null) {
@ -396,7 +397,7 @@ public enum CalculatorEngine {
}
// for tests only
void setThreadKiller(@NotNull ThreadKiller threadKiller) {
void setThreadKiller(@Nullable ThreadKiller threadKiller) {
this.threadKiller = threadKiller;
}

View File

@ -6,6 +6,8 @@
package org.solovyev.android.calculator.jscl;
import jscl.AngleUnit;
import jscl.JsclMathEngine;
import jscl.math.Expression;
import jscl.math.Generic;
import org.junit.Assert;
@ -29,9 +31,19 @@ public class FromJsclNumericTextProcessorTest {
public void testCreateResultForComplexNumber() throws Exception {
final FromJsclNumericTextProcessor cm = new FromJsclNumericTextProcessor();
final JsclMathEngine me = JsclMathEngine.instance;
final AngleUnit defaultAngleUnits = me.getAngleUnits();
Assert.assertEquals("1.22133+23 123i", cm.process(Expression.valueOf("1.22133232+23123*i").numeric()));
Assert.assertEquals("1.22133+1.2i", cm.process(Expression.valueOf("1.22133232+1.2*i").numeric()));
Assert.assertEquals("1.22i", cm.process(Expression.valueOf("1.22*i").numeric()));
Assert.assertEquals("1.22133+0i", cm.process(Expression.valueOf("1.22133232+0.000000001*i").numeric()));
try {
me.setAngleUnits(AngleUnit.rad);
Assert.assertEquals("1-0i", cm.process(Expression.valueOf("-(e^(i*π))").numeric()));
} finally {
me.setAngleUnits(defaultAngleUnits);
}
Assert.assertEquals("1.22i", cm.process(Expression.valueOf("1.22*i").numeric()));
Assert.assertEquals("i", cm.process(Expression.valueOf("i").numeric()));
Generic numeric = Expression.valueOf("e^(Π*i)+1").numeric();
junit.framework.Assert.assertEquals("0i", cm.process(numeric));

View File

@ -18,7 +18,6 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<android.sdk.path>/home/ssolovyev/projects/org.solovyev/misc/lib/android-sdk-linux_x86</android.sdk.path>
</properties>
<dependencyManagement>
@ -56,6 +55,12 @@
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>11.0.2</version>
</dependency>
</dependencies>
</dependencyManagement>