VarsRegistry->VariablesRegistry
This commit is contained in:
parent
59e4a15bd2
commit
f767f10795
@ -472,15 +472,15 @@ public class CalculatorImpl implements Calculator, CalculatorEventListener {
|
|||||||
if (TextUtils.isEmpty(text)) {
|
if (TextUtils.isEmpty(text)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final EntitiesRegistry<IConstant> varsRegistry = Locator.getInstance().getEngine().getVarsRegistry();
|
final EntitiesRegistry<IConstant> varsRegistry = Locator.getInstance().getEngine().getVariablesRegistry();
|
||||||
final IConstant ansVar = varsRegistry.get(VarsRegistry.ANS);
|
final IConstant ansVar = varsRegistry.get(VariablesRegistry.ANS);
|
||||||
|
|
||||||
final Var.Builder builder = ansVar != null ? new Var.Builder(ansVar) : new Var.Builder();
|
final Var.Builder builder = ansVar != null ? new Var.Builder(ansVar) : new Var.Builder();
|
||||||
builder.setName(VarsRegistry.ANS);
|
builder.setName(VariablesRegistry.ANS);
|
||||||
builder.setValue(text);
|
builder.setValue(text);
|
||||||
builder.setDescription(CalculatorMessages.getBundle().getString(CalculatorMessages.ans_description));
|
builder.setDescription(CalculatorMessages.getBundle().getString(CalculatorMessages.ans_description));
|
||||||
|
|
||||||
VarsRegistry.saveVariable(varsRegistry, builder, ansVar, this, false);
|
VariablesRegistry.saveVariable(varsRegistry, builder, ansVar, this, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
@ -498,7 +498,7 @@ public class CalculatorImpl implements Calculator, CalculatorEventListener {
|
|||||||
switch (calculatorEventType) {
|
switch (calculatorEventType) {
|
||||||
case constant_changed:
|
case constant_changed:
|
||||||
final IConstant newConstant = ((Change<IConstant>) data).getNewValue();
|
final IConstant newConstant = ((Change<IConstant>) data).getNewValue();
|
||||||
if (!newConstant.getName().equals(VarsRegistry.ANS)) {
|
if (!newConstant.getName().equals(VariablesRegistry.ANS)) {
|
||||||
evaluate();
|
evaluate();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -54,7 +54,7 @@ public final class CalculatorUtils {
|
|||||||
final Set<Constant> notSystemConstants = new HashSet<Constant>();
|
final Set<Constant> notSystemConstants = new HashSet<Constant>();
|
||||||
|
|
||||||
for (Constant constant : expression.getConstants()) {
|
for (Constant constant : expression.getConstants()) {
|
||||||
IConstant var = Locator.getInstance().getEngine().getVarsRegistry().get(constant.getName());
|
IConstant var = Locator.getInstance().getEngine().getVariablesRegistry().get(constant.getName());
|
||||||
if (var != null && !var.isSystem() && !var.isDefined()) {
|
if (var != null && !var.isSystem() && !var.isDefined()) {
|
||||||
notSystemConstants.add(constant);
|
notSystemConstants.add(constant);
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ public class Engine implements SharedPreferences.OnSharedPreferenceChangeListene
|
|||||||
@Nonnull
|
@Nonnull
|
||||||
private final MathEngine mathEngine;
|
private final MathEngine mathEngine;
|
||||||
@Nonnull
|
@Nonnull
|
||||||
private final VarsRegistry varsRegistry;
|
private final VariablesRegistry variablesRegistry;
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
private final EntitiesRegistry<Operator> operatorsRegistry;
|
private final EntitiesRegistry<Operator> operatorsRegistry;
|
||||||
@ -71,9 +71,9 @@ public class Engine implements SharedPreferences.OnSharedPreferenceChangeListene
|
|||||||
@Nonnull
|
@Nonnull
|
||||||
private String multiplicationSign = Preferences.multiplicationSign.getDefaultValue();
|
private String multiplicationSign = Preferences.multiplicationSign.getDefaultValue();
|
||||||
|
|
||||||
public Engine(@Nonnull MathEngine mathEngine, @Nonnull VarsRegistry varsRegistry, @Nonnull FunctionsRegistry functionsRegistry, @Nonnull EntitiesRegistry<Operator> operatorsRegistry, @Nonnull EntitiesRegistry<Operator> postfixFunctionsRegistry) {
|
public Engine(@Nonnull MathEngine mathEngine, @Nonnull VariablesRegistry variablesRegistry, @Nonnull FunctionsRegistry functionsRegistry, @Nonnull EntitiesRegistry<Operator> operatorsRegistry, @Nonnull EntitiesRegistry<Operator> postfixFunctionsRegistry) {
|
||||||
this.mathEngine = mathEngine;
|
this.mathEngine = mathEngine;
|
||||||
this.varsRegistry = varsRegistry;
|
this.variablesRegistry = variablesRegistry;
|
||||||
this.functionsRegistry = functionsRegistry;
|
this.functionsRegistry = functionsRegistry;
|
||||||
this.operatorsRegistry = operatorsRegistry;
|
this.operatorsRegistry = operatorsRegistry;
|
||||||
this.postfixFunctionsRegistry = postfixFunctionsRegistry;
|
this.postfixFunctionsRegistry = postfixFunctionsRegistry;
|
||||||
@ -86,7 +86,7 @@ public class Engine implements SharedPreferences.OnSharedPreferenceChangeListene
|
|||||||
this.mathEngine.setRoundResult(true);
|
this.mathEngine.setRoundResult(true);
|
||||||
this.mathEngine.setUseGroupingSeparator(true);
|
this.mathEngine.setUseGroupingSeparator(true);
|
||||||
|
|
||||||
this.varsRegistry = new VarsRegistry(mathEngine.getConstantsRegistry(), new EntityDao<>("org.solovyev.android.calculator.CalculatorModel_vars", Vars.class, preferences));
|
this.variablesRegistry = new VariablesRegistry(mathEngine.getConstantsRegistry(), new EntityDao<>("org.solovyev.android.calculator.CalculatorModel_vars", Vars.class, preferences));
|
||||||
this.operatorsRegistry = new OperatorsRegistry(mathEngine.getOperatorsRegistry());
|
this.operatorsRegistry = new OperatorsRegistry(mathEngine.getOperatorsRegistry());
|
||||||
this.postfixFunctionsRegistry = new PostfixFunctionsRegistry(mathEngine.getPostfixFunctionsRegistry());
|
this.postfixFunctionsRegistry = new PostfixFunctionsRegistry(mathEngine.getPostfixFunctionsRegistry());
|
||||||
}
|
}
|
||||||
@ -106,8 +106,8 @@ public class Engine implements SharedPreferences.OnSharedPreferenceChangeListene
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public VarsRegistry getVarsRegistry() {
|
public VariablesRegistry getVariablesRegistry() {
|
||||||
return varsRegistry;
|
return variablesRegistry;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@ -169,7 +169,7 @@ public class Engine implements SharedPreferences.OnSharedPreferenceChangeListene
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initAsync() {
|
private void initAsync() {
|
||||||
init(varsRegistry);
|
init(variablesRegistry);
|
||||||
init(functionsRegistry);
|
init(functionsRegistry);
|
||||||
init(operatorsRegistry);
|
init(operatorsRegistry);
|
||||||
init(postfixFunctionsRegistry);
|
init(postfixFunctionsRegistry);
|
||||||
|
@ -114,9 +114,9 @@ public class ToJsclTextProcessor implements TextProcessor<PreparedExpression, St
|
|||||||
if (functionName == null) {
|
if (functionName == null) {
|
||||||
String operatorName = App.find(MathType.operator.getTokens(), startsWithFinder);
|
String operatorName = App.find(MathType.operator.getTokens(), startsWithFinder);
|
||||||
if (operatorName == null) {
|
if (operatorName == null) {
|
||||||
String varName = App.find(Locator.getInstance().getEngine().getVarsRegistry().getNames(), startsWithFinder);
|
String varName = App.find(Locator.getInstance().getEngine().getVariablesRegistry().getNames(), startsWithFinder);
|
||||||
if (varName != null) {
|
if (varName != null) {
|
||||||
final IConstant var = Locator.getInstance().getEngine().getVarsRegistry().get(varName);
|
final IConstant var = Locator.getInstance().getEngine().getVariablesRegistry().get(varName);
|
||||||
if (var != null) {
|
if (var != null) {
|
||||||
if (!var.isDefined()) {
|
if (!var.isDefined()) {
|
||||||
undefinedVars.add(var);
|
undefinedVars.add(var);
|
||||||
|
@ -22,7 +22,6 @@
|
|||||||
|
|
||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
import jscl.math.function.IConstant;
|
|
||||||
import org.solovyev.android.calculator.model.EntityDao;
|
import org.solovyev.android.calculator.model.EntityDao;
|
||||||
import org.solovyev.android.calculator.model.MathEntityBuilder;
|
import org.solovyev.android.calculator.model.MathEntityBuilder;
|
||||||
import org.solovyev.android.calculator.model.Var;
|
import org.solovyev.android.calculator.model.Var;
|
||||||
@ -31,12 +30,15 @@ import org.solovyev.common.JBuilder;
|
|||||||
import org.solovyev.common.math.MathEntity;
|
import org.solovyev.common.math.MathEntity;
|
||||||
import org.solovyev.common.math.MathRegistry;
|
import org.solovyev.common.math.MathRegistry;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class VarsRegistry extends BaseEntitiesRegistry<IConstant, Var> {
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
import jscl.math.function.IConstant;
|
||||||
|
|
||||||
|
public class VariablesRegistry extends BaseEntitiesRegistry<IConstant, Var> {
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static final String ANS = "ans";
|
public static final String ANS = "ans";
|
||||||
@ -52,8 +54,8 @@ public class VarsRegistry extends BaseEntitiesRegistry<IConstant, Var> {
|
|||||||
substitutes.put("NaN", "nan");
|
substitutes.put("NaN", "nan");
|
||||||
}
|
}
|
||||||
|
|
||||||
public VarsRegistry(@Nonnull MathRegistry<IConstant> mathRegistry,
|
public VariablesRegistry(@Nonnull MathRegistry<IConstant> mathRegistry,
|
||||||
@Nonnull EntityDao<Var> entityDao) {
|
@Nonnull EntityDao<Var> entityDao) {
|
||||||
super(mathRegistry, "c_var_description_", entityDao);
|
super(mathRegistry, "c_var_description_", entityDao);
|
||||||
}
|
}
|
||||||
|
|
@ -60,7 +60,7 @@ import org.solovyev.android.calculator.KeyboardWindow;
|
|||||||
import org.solovyev.android.calculator.Locator;
|
import org.solovyev.android.calculator.Locator;
|
||||||
import org.solovyev.android.calculator.ParseException;
|
import org.solovyev.android.calculator.ParseException;
|
||||||
import org.solovyev.android.calculator.R;
|
import org.solovyev.android.calculator.R;
|
||||||
import org.solovyev.android.calculator.VarsRegistry;
|
import org.solovyev.android.calculator.VariablesRegistry;
|
||||||
import org.solovyev.android.calculator.math.edit.FunctionsActivity;
|
import org.solovyev.android.calculator.math.edit.FunctionsActivity;
|
||||||
import org.solovyev.android.calculator.math.edit.VarEditorSaver;
|
import org.solovyev.android.calculator.math.edit.VarEditorSaver;
|
||||||
import org.solovyev.android.calculator.view.EditTextCompat;
|
import org.solovyev.android.calculator.view.EditTextCompat;
|
||||||
@ -91,7 +91,7 @@ public class EditFunctionFragment extends BaseDialogFragment implements View.OnC
|
|||||||
private static final int MENU_CATEGORY = Menu.FIRST + 2;
|
private static final int MENU_CATEGORY = Menu.FIRST + 2;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final VarsRegistry constantsRegistry = Locator.getInstance().getEngine().getVarsRegistry();
|
private final VariablesRegistry constantsRegistry = Locator.getInstance().getEngine().getVariablesRegistry();
|
||||||
@NonNull
|
@NonNull
|
||||||
private final KeyboardWindow keyboardWindow = new KeyboardWindow();
|
private final KeyboardWindow keyboardWindow = new KeyboardWindow();
|
||||||
@NonNull
|
@NonNull
|
||||||
|
@ -170,7 +170,7 @@ public enum MathType {
|
|||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public List<String> getTokens() {
|
public List<String> getTokens() {
|
||||||
return Locator.getInstance().getEngine().getVarsRegistry().getNames();
|
return Locator.getInstance().getEngine().getVariablesRegistry().getNames();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -91,7 +91,7 @@ public class MathEntityRemover<T extends MathEntity> implements View.OnClickList
|
|||||||
@Nullable DialogInterface.OnClickListener callbackOnCancel,
|
@Nullable DialogInterface.OnClickListener callbackOnCancel,
|
||||||
@Nonnull Context context,
|
@Nonnull Context context,
|
||||||
@Nonnull Object source) {
|
@Nonnull Object source) {
|
||||||
return new MathEntityRemover<IConstant>(constant, callbackOnCancel, false, Locator.getInstance().getEngine().getVarsRegistry(), context, source, Params.newConstantInstance());
|
return new MathEntityRemover<IConstant>(constant, callbackOnCancel, false, Locator.getInstance().getEngine().getVariablesRegistry(), context, source, Params.newConstantInstance());
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -163,7 +163,7 @@ public class VarEditDialogFragment extends DialogFragment implements CalculatorE
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
root.findViewById(R.id.save_button).setOnClickListener(new VarEditorSaver<IConstant>(varBuilder, constant, root, Locator.getInstance().getEngine().getVarsRegistry(), this));
|
root.findViewById(R.id.save_button).setOnClickListener(new VarEditorSaver<IConstant>(varBuilder, constant, root, Locator.getInstance().getEngine().getVariablesRegistry(), this));
|
||||||
|
|
||||||
if (constant == null) {
|
if (constant == null) {
|
||||||
// CREATE MODE
|
// CREATE MODE
|
||||||
|
@ -28,7 +28,7 @@ import android.widget.EditText;
|
|||||||
import org.solovyev.android.calculator.EntitiesRegistry;
|
import org.solovyev.android.calculator.EntitiesRegistry;
|
||||||
import org.solovyev.android.calculator.Locator;
|
import org.solovyev.android.calculator.Locator;
|
||||||
import org.solovyev.android.calculator.R;
|
import org.solovyev.android.calculator.R;
|
||||||
import org.solovyev.android.calculator.VarsRegistry;
|
import org.solovyev.android.calculator.VariablesRegistry;
|
||||||
import org.solovyev.android.calculator.math.MathType;
|
import org.solovyev.android.calculator.math.MathType;
|
||||||
import org.solovyev.android.calculator.model.MathEntityBuilder;
|
import org.solovyev.android.calculator.model.MathEntityBuilder;
|
||||||
import org.solovyev.common.math.MathEntity;
|
import org.solovyev.common.math.MathEntity;
|
||||||
@ -145,7 +145,7 @@ public class VarEditorSaver<T extends MathEntity> implements View.OnClickListene
|
|||||||
if (error != null) {
|
if (error != null) {
|
||||||
Locator.getInstance().getNotifier().showMessage(error, MessageType.error);
|
Locator.getInstance().getNotifier().showMessage(error, MessageType.error);
|
||||||
} else {
|
} else {
|
||||||
VarsRegistry.saveVariable(mathRegistry, varBuilder, editedInstance, source, true);
|
VariablesRegistry.saveVariable(mathRegistry, varBuilder, editedInstance, source, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ public class VarsFragment extends BaseEntitiesFragment<IConstant>implements Calc
|
|||||||
|
|
||||||
public static final String CREATE_VAR_EXTRA_STRING = "create_var";
|
public static final String CREATE_VAR_EXTRA_STRING = "create_var";
|
||||||
@NonNull
|
@NonNull
|
||||||
private final EntitiesRegistry<IConstant> registry = Locator.getInstance().getEngine().getVarsRegistry();
|
private final EntitiesRegistry<IConstant> registry = Locator.getInstance().getEngine().getVariablesRegistry();
|
||||||
|
|
||||||
public VarsFragment() {
|
public VarsFragment() {
|
||||||
super(CalculatorFragmentType.variables);
|
super(CalculatorFragmentType.variables);
|
||||||
|
@ -23,8 +23,9 @@
|
|||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import com.squareup.otto.Bus;
|
import com.squareup.otto.Bus;
|
||||||
import jscl.JsclMathEngine;
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
import org.robolectric.fakes.RoboSharedPreferences;
|
import org.robolectric.fakes.RoboSharedPreferences;
|
||||||
@ -33,9 +34,12 @@ import org.solovyev.android.calculator.language.Languages;
|
|||||||
import org.solovyev.android.calculator.model.EntityDao;
|
import org.solovyev.android.calculator.model.EntityDao;
|
||||||
import org.solovyev.android.calculator.plot.CalculatorPlotter;
|
import org.solovyev.android.calculator.plot.CalculatorPlotter;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import java.io.ByteArrayInputStream;
|
||||||
import javax.annotation.Nullable;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.*;
|
import java.io.IOException;
|
||||||
|
import java.io.ObjectInputStream;
|
||||||
|
import java.io.ObjectOutputStream;
|
||||||
|
import java.io.Serializable;
|
||||||
import java.text.DecimalFormatSymbols;
|
import java.text.DecimalFormatSymbols;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -43,6 +47,11 @@ import java.util.concurrent.CountDownLatch;
|
|||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
import jscl.JsclMathEngine;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: serso
|
* User: serso
|
||||||
* Date: 10/7/12
|
* Date: 10/7/12
|
||||||
@ -94,12 +103,12 @@ public class CalculatorTestUtils {
|
|||||||
|
|
||||||
final JsclMathEngine jsclEngine = JsclMathEngine.getInstance();
|
final JsclMathEngine jsclEngine = JsclMathEngine.getInstance();
|
||||||
|
|
||||||
final VarsRegistry varsRegistry = new VarsRegistry(jsclEngine.getConstantsRegistry(), entityDao);
|
final VariablesRegistry variablesRegistry = new VariablesRegistry(jsclEngine.getConstantsRegistry(), entityDao);
|
||||||
final FunctionsRegistry functionsRegistry = new FunctionsRegistry(jsclEngine);
|
final FunctionsRegistry functionsRegistry = new FunctionsRegistry(jsclEngine);
|
||||||
final OperatorsRegistry operatorsRegistry = new OperatorsRegistry(jsclEngine.getOperatorsRegistry());
|
final OperatorsRegistry operatorsRegistry = new OperatorsRegistry(jsclEngine.getOperatorsRegistry());
|
||||||
final PostfixFunctionsRegistry postfixFunctionsRegistry = new PostfixFunctionsRegistry(jsclEngine.getPostfixFunctionsRegistry());
|
final PostfixFunctionsRegistry postfixFunctionsRegistry = new PostfixFunctionsRegistry(jsclEngine.getPostfixFunctionsRegistry());
|
||||||
|
|
||||||
return new Engine(jsclEngine, varsRegistry, functionsRegistry, operatorsRegistry, postfixFunctionsRegistry);
|
return new Engine(jsclEngine, variablesRegistry, functionsRegistry, operatorsRegistry, postfixFunctionsRegistry);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void assertEval(@Nonnull String expected, @Nonnull String expression) {
|
public static void assertEval(@Nonnull String expected, @Nonnull String expression) {
|
||||||
|
@ -57,15 +57,15 @@ public class FromJsclSimplifyTextProcessorTest extends AbstractCalculatorTest {
|
|||||||
//Assert.assertEquals("e", tp.process("2.718281828459045"));
|
//Assert.assertEquals("e", tp.process("2.718281828459045"));
|
||||||
//Assert.assertEquals("tee", tp.process("t2.718281828459045*2.718281828459045"));
|
//Assert.assertEquals("tee", tp.process("t2.718281828459045*2.718281828459045"));
|
||||||
|
|
||||||
Locator.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("t2.718281828459045", "2"));
|
Locator.getInstance().getEngine().getVariablesRegistry().add(new Var.Builder("t2.718281828459045", "2"));
|
||||||
Locator.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("t", (String) null));
|
Locator.getInstance().getEngine().getVariablesRegistry().add(new Var.Builder("t", (String) null));
|
||||||
//Assert.assertEquals("t2.718281828459045e", tp.process("t2.718281828459045*2.718281828459045"));
|
//Assert.assertEquals("t2.718281828459045e", tp.process("t2.718281828459045*2.718281828459045"));
|
||||||
//Assert.assertEquals("ee", tp.process("2.718281828459045*2.718281828459045"));
|
//Assert.assertEquals("ee", tp.process("2.718281828459045*2.718281828459045"));
|
||||||
Assert.assertEquals("t×", tp.process("t*"));
|
Assert.assertEquals("t×", tp.process("t*"));
|
||||||
Assert.assertEquals("×t", tp.process("*t"));
|
Assert.assertEquals("×t", tp.process("*t"));
|
||||||
Assert.assertEquals("t2", tp.process("t*2"));
|
Assert.assertEquals("t2", tp.process("t*2"));
|
||||||
Assert.assertEquals("2t", tp.process("2*t"));
|
Assert.assertEquals("2t", tp.process("2*t"));
|
||||||
Locator.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("t", (String) null));
|
Locator.getInstance().getEngine().getVariablesRegistry().add(new Var.Builder("t", (String) null));
|
||||||
Assert.assertEquals("t×", tp.process("t*"));
|
Assert.assertEquals("t×", tp.process("t*"));
|
||||||
Assert.assertEquals("×t", tp.process("*t"));
|
Assert.assertEquals("×t", tp.process("*t"));
|
||||||
|
|
||||||
@ -78,7 +78,7 @@ public class FromJsclSimplifyTextProcessorTest extends AbstractCalculatorTest {
|
|||||||
Assert.assertEquals("t^[2×2t]", tp.process("t^[2*2*t]"));
|
Assert.assertEquals("t^[2×2t]", tp.process("t^[2*2*t]"));
|
||||||
Assert.assertEquals("2t^2[2t]", tp.process("2*t^2[2*t]"));
|
Assert.assertEquals("2t^2[2t]", tp.process("2*t^2[2*t]"));
|
||||||
|
|
||||||
Locator.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("k", (String) null));
|
Locator.getInstance().getEngine().getVariablesRegistry().add(new Var.Builder("k", (String) null));
|
||||||
Assert.assertEquals("(t+2k)[k+2t]", tp.process("(t+2*k)*[k+2*t]"));
|
Assert.assertEquals("(t+2k)[k+2t]", tp.process("(t+2*k)*[k+2*t]"));
|
||||||
Assert.assertEquals("(te+2k)e[k+2te]", tp.process("(t*e+2*k)*e*[k+2*t*e]"));
|
Assert.assertEquals("(te+2k)e[k+2te]", tp.process("(t*e+2*k)*e*[k+2*t*e]"));
|
||||||
|
|
||||||
|
@ -139,7 +139,7 @@ public class AndroidEngineTest extends AbstractCalculatorTest {
|
|||||||
cm.setAngleUnits(defaultAngleUnit);
|
cm.setAngleUnits(defaultAngleUnit);
|
||||||
}
|
}
|
||||||
|
|
||||||
Locator.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("si", 5d));
|
Locator.getInstance().getEngine().getVariablesRegistry().add(new Var.Builder("si", 5d));
|
||||||
CalculatorTestUtils.assertEval("5", cm.evaluate("si"));
|
CalculatorTestUtils.assertEval("5", cm.evaluate("si"));
|
||||||
|
|
||||||
CalculatorTestUtils.assertError("sin");
|
CalculatorTestUtils.assertError("sin");
|
||||||
|
@ -116,7 +116,7 @@ public class EvaluateTest extends AbstractCalculatorTest {
|
|||||||
CalculatorTestUtils.assertError("(-1)i!");
|
CalculatorTestUtils.assertError("(-1)i!");
|
||||||
CalculatorTestUtils.assertEval("24i", "4!i");
|
CalculatorTestUtils.assertEval("24i", "4!i");
|
||||||
|
|
||||||
Locator.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("si", 5d));
|
Locator.getInstance().getEngine().getVariablesRegistry().add(new Var.Builder("si", 5d));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
cm.setAngleUnits(AngleUnit.rad);
|
cm.setAngleUnits(AngleUnit.rad);
|
||||||
@ -130,14 +130,14 @@ public class EvaluateTest extends AbstractCalculatorTest {
|
|||||||
cm.setAngleUnits(defaultAngleUnit);
|
cm.setAngleUnits(defaultAngleUnit);
|
||||||
}
|
}
|
||||||
|
|
||||||
Locator.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("s", 1d));
|
Locator.getInstance().getEngine().getVariablesRegistry().add(new Var.Builder("s", 1d));
|
||||||
CalculatorTestUtils.assertEval("5", cm.evaluate("si"));
|
CalculatorTestUtils.assertEval("5", cm.evaluate("si"));
|
||||||
|
|
||||||
Locator.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("k", 3.5d));
|
Locator.getInstance().getEngine().getVariablesRegistry().add(new Var.Builder("k", 3.5d));
|
||||||
Locator.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("k1", 4d));
|
Locator.getInstance().getEngine().getVariablesRegistry().add(new Var.Builder("k1", 4d));
|
||||||
CalculatorTestUtils.assertEval("4", "k11");
|
CalculatorTestUtils.assertEval("4", "k11");
|
||||||
|
|
||||||
Locator.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("t", (String) null));
|
Locator.getInstance().getEngine().getVariablesRegistry().add(new Var.Builder("t", (String) null));
|
||||||
CalculatorTestUtils.assertEval("11t", "t11");
|
CalculatorTestUtils.assertEval("11t", "t11");
|
||||||
CalculatorTestUtils.assertEval("11et", "t11e");
|
CalculatorTestUtils.assertEval("11et", "t11e");
|
||||||
CalculatorTestUtils.assertEval("∞", "∞");
|
CalculatorTestUtils.assertEval("∞", "∞");
|
||||||
@ -183,10 +183,10 @@ public class EvaluateTest extends AbstractCalculatorTest {
|
|||||||
cm.setTimeout(3000);
|
cm.setTimeout(3000);
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
Locator.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("t", (String) null));
|
Locator.getInstance().getEngine().getVariablesRegistry().add(new Var.Builder("t", (String) null));
|
||||||
CalculatorTestUtils.assertEval("2t", "∂(t^2,t)", JsclOperation.simplify);
|
CalculatorTestUtils.assertEval("2t", "∂(t^2,t)", JsclOperation.simplify);
|
||||||
CalculatorTestUtils.assertEval("2t", "∂(t^2,t)");
|
CalculatorTestUtils.assertEval("2t", "∂(t^2,t)");
|
||||||
Locator.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("t", "2"));
|
Locator.getInstance().getEngine().getVariablesRegistry().add(new Var.Builder("t", "2"));
|
||||||
CalculatorTestUtils.assertEval("2t", "∂(t^2,t)", JsclOperation.simplify);
|
CalculatorTestUtils.assertEval("2t", "∂(t^2,t)", JsclOperation.simplify);
|
||||||
CalculatorTestUtils.assertEval("4", "∂(t^2,t)");
|
CalculatorTestUtils.assertEval("4", "∂(t^2,t)");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user