This commit is contained in:
serso 2011-12-15 03:19:10 +04:00
parent 85b3dc7e52
commit 9ab192abaa
21 changed files with 224 additions and 63 deletions

View File

@ -12,7 +12,6 @@
calc:textUp="ln"
calc:textLeft="0b:"
calc:textDown="lg"
calc:directionTextScale="0.5"
calc:directionTextScale="0.5;0.5;0.5;0.33"
style="?digitButtonStyle"
a:onClick="digitButtonClickHandler"/>

View File

@ -10,7 +10,7 @@
a:id="@+id/fiveDigitButton"
a:text="5"
calc:textUp="t"
calc:textLeft="e"
calc:textLeft="E"
calc:textDown="j"
style="?digitButtonStyle"
a:onClick="digitButtonClickHandler"/>

View File

@ -10,7 +10,7 @@
a:id="@+id/fourDigitButton"
a:text="4"
calc:textUp="x"
calc:textLeft="d"
calc:textLeft="D"
calc:textDown="y"
style="?digitButtonStyle"
a:onClick="digitButtonClickHandler"/>

View File

@ -12,6 +12,6 @@
calc:textDown="e"
calc:textLeft="0o:"
calc:textUp="π"
calc:directionTextScale="0.5"
calc:directionTextScale="0.5;0.5;0.5;0.33"
style="?digitButtonStyle"
a:onClick="digitButtonClickHandler"/>

View File

@ -11,7 +11,7 @@
a:id="@+id/oneDigitButton"
a:text="1"
calc:textUp="sin"
calc:textLeft="a"
calc:textLeft="A"
calc:textDown="asin"
style="?digitButtonStyle"
a:onClick="digitButtonClickHandler"/>

View File

@ -12,7 +12,6 @@
calc:textUp="i"
calc:textLeft="0x:"
calc:textDown="!"
calc:directionTextScale="0.5"
calc:directionTextScale="0.5;0.5;0.5;0.33"
style="?digitButtonStyle"
a:onClick="digitButtonClickHandler"/>

View File

@ -11,7 +11,7 @@
calc:textUp="deg"
a:id="@+id/sixDigitButton"
a:text="6"
calc:textLeft="f"
calc:textLeft="F"
calc:textDown="rad"
style="?digitButtonStyle"
a:onClick="digitButtonClickHandler"/>

View File

@ -11,7 +11,7 @@
a:id="@+id/threeDigitButton"
a:text="3"
calc:textUp="tan"
calc:textLeft="c"
calc:textLeft="C"
calc:textDown="atan"
style="?digitButtonStyle"
a:onClick="digitButtonClickHandler"/>

View File

@ -11,7 +11,7 @@
a:id="@+id/twoDigitButton"
a:text="2"
calc:textUp="cos"
calc:textLeft="b"
calc:textLeft="B"
calc:textDown="acos"
style="?digitButtonStyle"
a:onClick="digitButtonClickHandler"/>

View File

@ -4,7 +4,7 @@
<attr name="textUp" format="string"/>
<attr name="textDown" format="string"/>
<attr name="textLeft" format="string"/>
<attr name="directionTextScale" format="float"/>
<attr name="directionTextScale" format="string"/>
<attr name="hTextPosition" format="float"/>
</declare-styleable>

View File

@ -7,7 +7,7 @@
<resources>
<string name="p_drag_distance_key">org.solovyev.android.calculator.DragButtonCalibrationActivity_distance</string>
<string name="p_drag_distance">15;350</string>
<string name="p_drag_distance">35;350</string>
<string name="p_drag_angle_key">org.solovyev.android.calculator.DragButtonCalibrationActivity_angle</string>
<string name="p_drag_angle">0;45</string>

View File

@ -76,7 +76,7 @@
a:title="@string/c_swipe_distance"
a:summary="@string/c_swipe_distance_summary"
a:text=" pxs"
a:defaultValue="15;350"
a:defaultValue="35;350"
range:steps="10"
range:boundaries="10;500"/>

View File

@ -132,7 +132,7 @@ public class TextHighlighter implements TextProcessor<TextHighlighter.Result, St
i = processHighlightedText(text1, i, match, "b", null);
break;
case numeral_base:
i = processHighlightedText(text1, i, match, "font", nbFontAttributes);
i = processHighlightedText(text1, i, match, "b", null);
break;
default:
if (mathType.getMathType() == MathType.text || match.length() <= 1) {

View File

@ -133,7 +133,7 @@ public enum CalculatorEngine {
final PreparedExpression preparedExpression = preprocessor.process(expression);
sb.append(preparedExpression);
//Log.d(CalculatorEngine.class.getName(), "Preprocessed expression: " + preprocessedExpression);
//Log.d(CalculatorEngine.class.getName(), "Preprocessed expression: " + preparedExpression);
/*if (operation == JsclOperation.numeric && preparedExpression.isExistsUndefinedVar()) {
operation = JsclOperation.simplify;

View File

@ -6,7 +6,11 @@
package org.solovyev.android.calculator.model;
import jscl.MathEngine;
import jscl.NumeralBase;
import jscl.math.numeric.Numeric;
import jscl.math.numeric.Real;
import jscl.text.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.math.MathType;
@ -105,6 +109,7 @@ public class NumberBuilder {
public MathType.Result process(@NotNull StringBuilder sb, @Nullable MutableObject<Integer> numberOffset) {
int numberOfTokens = 0;
final NumeralBase localNb;
if (numberBuilder != null) {
try {
number = numberBuilder.toString();
@ -116,22 +121,26 @@ public class NumberBuilder {
numberOfTokens += number.length() - newNumber.length();
number = newNumber;
}
Double.valueOf(number);
toDouble(number, getNumeralBase());
} catch (NumberFormatException e) {
number = null;
}
numberBuilder = null;
localNb = getNumeralBase();
nb = defaultNumeralBase;
} else {
number = null;
localNb = getNumeralBase();
}
return replaceSystemVars(sb, number, numberOfTokens, numberOffset);
return replaceSystemVars(sb, number, numberOfTokens, numberOffset, localNb, simpleFormat);
}
@Nullable
private MathType.Result replaceSystemVars(StringBuilder sb, String number, int numberOfTokens, @Nullable MutableObject<Integer> numberOffset) {
private static MathType.Result replaceSystemVars(StringBuilder sb, String number, int numberOfTokens, @Nullable MutableObject<Integer> numberOffset, @NotNull NumeralBase nb, boolean simpleFormat) {
MathType.Result result = null;
if (number != null) {
@ -156,13 +165,18 @@ public class NumberBuilder {
int indexOfDot = number.indexOf('.');
if (indexOfDot < 0) {
int indexOfE = number.indexOf('E');
int indexOfE;
if (nb == NumeralBase.hex) {
indexOfE = -1;
} else {
indexOfE = number.indexOf('E');
}
if (indexOfE < 0) {
formattedNumber = CalculatorEngine.instance.format(Double.valueOf(number), false);
formattedNumber = Numeric.toString(toDouble(number, nb), nb);
} else {
final String part;
if (indexOfDot != 0) {
part = CalculatorEngine.instance.format(Double.valueOf(number.substring(0, indexOfE)), false);
part = Numeric.toString(toDouble(number.substring(0, indexOfE), nb), nb);
} else {
part = "";
}
@ -171,14 +185,14 @@ public class NumberBuilder {
} else {
final String integerPart;
if (indexOfDot != 0) {
integerPart = CalculatorEngine.instance.format(Double.valueOf(number.substring(0, indexOfDot)), false);
integerPart = Numeric.toString(toDouble(number.substring(0, indexOfDot), nb), nb);
} else {
integerPart = "";
}
formattedNumber = integerPart + number.substring(indexOfDot);
}
} else {
formattedNumber = CalculatorEngine.instance.format(Double.valueOf(number), true);
formattedNumber = Numeric.toString(toDouble(number, nb), nb);
}
if (numberOffset != null) {
@ -192,6 +206,35 @@ public class NumberBuilder {
}
public boolean isHexMode() {
return nb == NumeralBase.hex;
return nb == NumeralBase.hex || ( nb == null && defaultNumeralBase == NumeralBase.hex);
}
@NotNull
private NumeralBase getNumeralBase(){
return nb == null ? defaultNumeralBase : nb;
}
@NotNull
private static Double toDouble(@NotNull String s, @NotNull NumeralBase nb) throws NumberFormatException{
final MathEngine me = CalculatorEngine.instance.getEngine();
final NumeralBase defaultNb = me.getNumeralBase();
try {
me.setNumeralBase(nb);
try {
return JsclIntegerParser.parser.parse(Parser.Parameters.newInstance(s, new MutableInt(0), me), null).content().doubleValue();
} catch (ParseException e) {
try {
return ((Real) DoubleParser.parser.parse(Parser.Parameters.newInstance(s, new MutableInt(0), me), null).content()).doubleValue();
} catch (ParseException e1) {
throw new NumberFormatException();
}
}
} finally {
me.setNumeralBase(defaultNb);
}
}
}

View File

@ -15,10 +15,14 @@ import android.util.AttributeSet;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.R;
import org.solovyev.common.NumberParser;
import org.solovyev.common.utils.CollectionsUtils;
import org.solovyev.common.utils.Point2d;
import org.solovyev.common.utils.StringUtils;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
@ -29,7 +33,10 @@ import java.util.Map;
public class DirectionDragButton extends DragButton {
@NotNull
private final static Float DEFAULT_DIRECTION_TEXT_SCALE = 0.33f;
private final static Float DEFAULT_DIRECTION_TEXT_SCALE_FLOAT = 0.33f;
@NotNull
private final static String DEFAULT_DIRECTION_TEXT_SCALE = "0.33;0.33;0.33;0.33";
@Nullable
private String textMiddle;
@ -48,6 +55,9 @@ public class DirectionDragButton extends DragButton {
@NotNull
private TextPaint paint;
@NotNull
private Float textScale;
private DirectionTextData(@NotNull GuiDragDirection guiDragDirection, @NotNull String text) {
this.guiDragDirection = guiDragDirection;
this.text = text;
@ -84,10 +94,19 @@ public class DirectionDragButton extends DragButton {
public void setPaint(@NotNull TextPaint paint) {
this.paint = paint;
}
@NotNull
public Float getTextScale() {
return textScale;
}
public void setTextScale(@NotNull Float textScale) {
this.textScale = textScale;
}
}
protected static enum GuiDragDirection {
up(DragDirection.up) {
up(DragDirection.up, 0) {
@Override
public int getAttributeId() {
return R.styleable.DragButton_textUp;
@ -99,7 +118,7 @@ public class DirectionDragButton extends DragButton {
return getUpDownTextPosition(paint, basePaint, text, baseText, 1, w, h);
}
},
down(DragDirection.down) {
down(DragDirection.down, 2) {
@Override
public int getAttributeId() {
return R.styleable.DragButton_textDown;
@ -111,7 +130,7 @@ public class DirectionDragButton extends DragButton {
return getUpDownTextPosition(paint, basePaint, text, baseText, -1, w, h);
}
},
left(DragDirection.left) {
left(DragDirection.left, 3) {
@Override
public int getAttributeId() {
return R.styleable.DragButton_textLeft;
@ -134,7 +153,7 @@ public class DirectionDragButton extends DragButton {
return result;
}
}/*,
right(DragDirection.right) {
right(DragDirection.right, 1) {
@Override
public int getAttributeId() {
return 0;
@ -144,12 +163,19 @@ public class DirectionDragButton extends DragButton {
@NotNull
private final DragDirection dragDirection;
GuiDragDirection(@NotNull DragDirection dragDirection) {
private final int attributePosition;
GuiDragDirection(@NotNull DragDirection dragDirection, int attributePosition) {
this.dragDirection = dragDirection;
this.attributePosition = attributePosition;
}
public abstract int getAttributeId();
public int getAttributePosition() {
return attributePosition;
}
@NotNull
public abstract Point2d getTextPosition(@NotNull Paint paint, @NotNull Paint basePaint, @NotNull CharSequence text, CharSequence baseText, int w, int h);
@ -188,7 +214,7 @@ public class DirectionDragButton extends DragButton {
private final Map<GuiDragDirection, DirectionTextData> directionTextDataMap = new EnumMap<GuiDragDirection, DirectionTextData>(GuiDragDirection.class);
@NotNull
private Float directionTextScale = DEFAULT_DIRECTION_TEXT_SCALE;
private String directionTextScale = DEFAULT_DIRECTION_TEXT_SCALE;
private boolean initialized = false;
@ -210,7 +236,7 @@ public class DirectionDragButton extends DragButton {
if (!StringUtils.isEmpty(attrValue)) {
switch (attr) {
case R.styleable.DragButton_directionTextScale:
this.directionTextScale = Float.valueOf(attrValue);
this.directionTextScale = attrValue;
break;
default:
// try drag direction text
@ -225,6 +251,13 @@ public class DirectionDragButton extends DragButton {
}
}
for (Map.Entry<GuiDragDirection, Float> entry : getDirectionTextScales().entrySet()) {
final DirectionTextData dtd = directionTextDataMap.get(entry.getKey());
if (dtd != null) {
dtd.setTextScale(entry.getValue());
}
}
// backup text
this.textMiddle = String.valueOf(getText());
@ -275,7 +308,7 @@ public class DirectionDragButton extends DragButton {
directionTextPaint.setColor(resources.getColor(R.color.button_text_color));
directionTextPaint.setAlpha(getDefaultDirectionTextAlpha());
directionTextPaint.setTextSize(basePaint.getTextSize() * getDirectionTextScale());
directionTextPaint.setTextSize(basePaint.getTextSize() * directionTextData.getTextScale());
directionTextData.setPaint(directionTextPaint);
}
@ -313,8 +346,35 @@ public class DirectionDragButton extends DragButton {
@NotNull
public Float getDirectionTextScale() {
public String getDirectionTextScale() {
return directionTextScale;
}
@NotNull
private Map<GuiDragDirection, Float> getDirectionTextScales() {
final List<Float> scales = CollectionsUtils.split(getDirectionTextScale(), ";", new NumberParser<Float>(Float.class));
final Map<GuiDragDirection, Float> result = new HashMap<GuiDragDirection, Float>();
for (GuiDragDirection guiDragDirection : GuiDragDirection.values()) {
result.put(guiDragDirection, DEFAULT_DIRECTION_TEXT_SCALE_FLOAT);
}
if (scales.size() == 1) {
final Float scale = scales.get(0);
for (Map.Entry<GuiDragDirection, Float> entry : result.entrySet()) {
entry.setValue(scale);
}
} else {
for (int i = 0; i < scales.size(); i++) {
for (GuiDragDirection guiDragDirection : GuiDragDirection.values()) {
if (guiDragDirection.getAttributePosition() == i) {
result.put(guiDragDirection, scales.get(i));
}
}
}
}
return result;
}
}

View File

@ -7,8 +7,11 @@
package org.solovyev.android.calculator;
import jscl.JsclMathEngine;
import jscl.MathEngine;
import jscl.NumeralBase;
import junit.framework.Assert;
import org.junit.Test;
import org.solovyev.android.calculator.model.CalculatorEngine;
import org.solovyev.android.calculator.model.TextProcessor;
import java.util.Date;
@ -23,7 +26,7 @@ public class TextHighlighterTest {
@Test
public void testProcess() throws Exception {
TextProcessor textHighlighter = new TextHighlighter(0, true, JsclMathEngine.instance);
TextProcessor<?, String> textHighlighter = new TextHighlighter(0, true, JsclMathEngine.instance);
final Random random = new Random(new Date().getTime());
for (int i = 0; i < 1000; i++) {
@ -48,7 +51,7 @@ public class TextHighlighterTest {
textHighlighter = new TextHighlighter(0, false, JsclMathEngine.instance);
Assert.assertEquals("0.1E3", textHighlighter.process("0.1E3").toString());
Assert.assertEquals("1E3", textHighlighter.process("1E3").toString());
Assert.assertEquals("2<font color=\"#008000\">0x:</font>", textHighlighter.process("20x:").toString());
Assert.assertEquals("2<b>0x:</b>", textHighlighter.process("20x:").toString());
Assert.assertEquals("20x", textHighlighter.process("20x").toString());
Assert.assertEquals("22x", textHighlighter.process("22x").toString());
Assert.assertEquals("20t", textHighlighter.process("20t").toString());
@ -73,5 +76,55 @@ public class TextHighlighterTest {
Assert.assertEquals("<font color=\"#000000\"><i>sin</i>(</font><font color=\"#ffff9a\">2</font><font color=\"#000000\">)</font>", textHighlighter.process("sin(2)").toString());
Assert.assertEquals("<font color=\"#000000\"><i>atanh</i>(</font><font color=\"#ffff9a\">2</font><font color=\"#000000\">)</font>", textHighlighter.process("atanh(2)").toString());
Assert.assertEquals("<b>0x:</b>E", textHighlighter.process("0x:E").toString());
Assert.assertEquals("<b>0x:</b>6F", textHighlighter.process("0x:6F").toString());
Assert.assertEquals("<b>0x:</b>6F", textHighlighter.process("0x:6F.").toString());
Assert.assertEquals("<b>0x:</b>6F", textHighlighter.process("0x:6F.2").toString());
Assert.assertEquals("<b>0x:</b>6F", textHighlighter.process("0x:6F.B").toString());
Assert.assertEquals("<b>0x:</b>6F", textHighlighter.process("0x:006F.B").toString());
Assert.assertEquals("<b>0x:</b>0", textHighlighter.process("0x:0").toString());
Assert.assertEquals("<b>0x:</b>FF33233FFE", textHighlighter.process("0x:FF33233FFE").toString());
Assert.assertEquals("<b>0x:</b>FF33233FFE", textHighlighter.process("0x:FF33 233 FFE").toString());
final MathEngine me = CalculatorEngine.instance.getEngine();
try {
me.setNumeralBase(NumeralBase.hex);
Assert.assertEquals("E", textHighlighter.process("E").toString());
Assert.assertEquals(".E", textHighlighter.process(".E").toString());
Assert.assertEquals("E", textHighlighter.process("E.").toString());
Assert.assertEquals(".E.", textHighlighter.process(".E.").toString());
Assert.assertEquals("6F", textHighlighter.process("6F").toString());
Assert.assertEquals("6F", textHighlighter.process("6F").toString());
Assert.assertEquals("6F", textHighlighter.process("6F.").toString());
Assert.assertEquals("6F", textHighlighter.process("6F.2").toString());
Assert.assertEquals("6F", textHighlighter.process("6F.B").toString());
Assert.assertEquals("6F", textHighlighter.process("006F.B").toString());
} finally {
me.setNumeralBase(NumeralBase.dec);
}
Assert.assertEquals("<b>0b:</b>110101", textHighlighter.process("0b:110101").toString());
Assert.assertEquals("<b>0b:</b>110101", textHighlighter.process("0b:110101.").toString());
Assert.assertEquals("<b>0b:</b>110101", textHighlighter.process("0b:110101.101").toString());
Assert.assertEquals("<b>0b:</b>11010100", textHighlighter.process("0b:11010100.1").toString());
Assert.assertEquals("<b>0b:</b>110101", textHighlighter.process("0b:110101.0").toString());
Assert.assertEquals("<b>0b:</b>0", textHighlighter.process("0b:0").toString());
Assert.assertEquals("<b>0b:</b>1010100101111010101001", textHighlighter.process("0b:1010100101111010101001").toString());
Assert.assertEquals("<b>0b:</b>1010100101111010101001", textHighlighter.process("0b:101 010 01 0 111 1 0 10101001").toString());
try {
me.setNumeralBase(NumeralBase.bin);
Assert.assertEquals("110101", textHighlighter.process("110101").toString());
Assert.assertEquals("110101", textHighlighter.process("110101.").toString());
Assert.assertEquals("110101", textHighlighter.process("110101.101").toString());
Assert.assertEquals("11010100", textHighlighter.process("11010100.1").toString());
Assert.assertEquals("110101", textHighlighter.process("110101.0").toString());
Assert.assertEquals("0", textHighlighter.process("0").toString());
Assert.assertEquals("1010100101111010101001", textHighlighter.process("1010100101111010101001").toString());
Assert.assertEquals("1010100101111010101001", textHighlighter.process("101 010 01 0 111 1 0 10101001").toString());
} finally {
me.setNumeralBase(NumeralBase.dec);
}
}
}

View File

@ -367,12 +367,12 @@ public class CalculatorEngineTest {
public void testNumeralSystems() throws Exception {
final CalculatorEngine cm = CalculatorEngine.instance;
Assert.assertEquals("11 259 375", cm.evaluate(JsclOperation.numeric, "0x:abcdef").getResult());
Assert.assertEquals("30 606 154.462", cm.evaluate(JsclOperation.numeric, "0x:abcdef*e").getResult());
Assert.assertEquals("30 606 154.462", cm.evaluate(JsclOperation.numeric, "e*0x:abcdef").getResult());
Assert.assertEquals("2.718", cm.evaluate(JsclOperation.numeric, "e*0x:abcdef/0x:abcdef").getResult());
Assert.assertEquals("30 606 154.462", cm.evaluate(JsclOperation.numeric, "0x:abcdef*e*0x:abcdef/0x:abcdef").getResult());
Assert.assertEquals("30 606 154.462", cm.evaluate(JsclOperation.numeric, "c+0x:abcdef*e*0x:abcdef/0x:abcdef-c+0x:c-0x:c").getResult());
Assert.assertEquals("11 259 375", cm.evaluate(JsclOperation.numeric, "0x:ABCDEF").getResult());
Assert.assertEquals("30 606 154.462", cm.evaluate(JsclOperation.numeric, "0x:ABCDEF*e").getResult());
Assert.assertEquals("30 606 154.462", cm.evaluate(JsclOperation.numeric, "e*0x:ABCDEF").getResult());
Assert.assertEquals("2.718", cm.evaluate(JsclOperation.numeric, "e*0x:ABCDEF/0x:ABCDEF").getResult());
Assert.assertEquals("30 606 154.462", cm.evaluate(JsclOperation.numeric, "0x:ABCDEF*e*0x:ABCDEF/0x:ABCDEF").getResult());
Assert.assertEquals("30 606 154.462", cm.evaluate(JsclOperation.numeric, "c+0x:ABCDEF*e*0x:ABCDEF/0x:ABCDEF-c+0x:C-0x:C").getResult());
Assert.assertEquals("1 446 257 064 651.832", cm.evaluate(JsclOperation.numeric, "28*28 * sin(28) - 0b:1101 + √(28) + exp ( 28) ").getResult());
Assert.assertEquals("13", cm.evaluate(JsclOperation.numeric, "0b:1101").getResult());
@ -388,7 +388,8 @@ public class CalculatorEngineTest {
}
cm.getEngine().setNumeralBase(NumeralBase.hex);
Assert.assertEquals("637b", cm.evaluate(JsclOperation.numeric, "56ce+cad").getResult());
Assert.assertEquals("637B", cm.evaluate(JsclOperation.numeric, "56CE+CAD").getResult());
Assert.assertEquals("E", cm.evaluate(JsclOperation.numeric, "E").getResult());
} finally {
cm.setNumeralBase(defaultNumeralBase);
}

View File

@ -49,9 +49,9 @@ public class NumeralBaseTest {
testExpression(line, new Expression2());
testExpression(line, new Expression3());
final String dec = line[0];
final String hex = "0x:" + line[1];
final String bin = "0b:" + line[2];
final String dec = line[0].toUpperCase();
final String hex = "0x:" + line[1].toUpperCase();
final String bin = "0b:" + line[2].toUpperCase();
final List<String> input = new ArrayList<String>();
input.add(dec);
@ -93,9 +93,9 @@ public class NumeralBaseTest {
}
public static void testExpression(@NotNull String[] line, @NotNull Converter<String, String> converter) throws ParseException, CalculatorEvalException, CalculatorParseException {
final String dec = line[0];
final String hex = "0x:" + line[1];
final String bin = "0b:" + line[2];
final String dec = line[0].toUpperCase();
final String hex = "0x:" + line[1].toUpperCase();
final String bin = "0b:" + line[2].toUpperCase();
final String decExpression = converter.convert(dec);
final String decResult = CalculatorEngine.instance.evaluate(JsclOperation.numeric, decExpression).getResult();

View File

@ -62,18 +62,24 @@ public class ToJsclTextProcessorTest {
Assert.assertEquals( "E(-1.2)", preprocessor.process("E(-1.2)").toString());
Assert.assertEquals( "EE", preprocessor.process("EE").toString());
Assert.assertEquals( "0x:abcdef", preprocessor.process("0x:abcdef").toString());
Assert.assertEquals( "0x:abcdef", preprocessor.process("0x:a bc def").toString());
Assert.assertEquals( "0x:abcdef", preprocessor.process("0x:a bc def").toString());
Assert.assertEquals( "0x:abcdef*0*x", preprocessor.process("0x:a bc def*0x").toString());
Assert.assertEquals( "0x:abcdef001*0*x", preprocessor.process("0x:a bc def001*0x").toString());
Assert.assertEquals( "0x:abcdef001*0*c", preprocessor.process("0x:a bc def001*0c").toString());
Assert.assertEquals( "0x:abcdef001*c", preprocessor.process("0x:a bc def001*c").toString());
try {
CalculatorEngine.instance.getEngine().setNumeralBase(NumeralBase.hex);
Assert.assertEquals( "22F*exp(F)", preprocessor.process("22Fexp(F)").toString());
} finally {
CalculatorEngine.instance.getEngine().setNumeralBase(NumeralBase.dec);
}
Assert.assertEquals( "0x:ABCDEF", preprocessor.process("0x:ABCDEF").toString());
Assert.assertEquals( "0x:ABCDEF", preprocessor.process("0x:A BC DEF").toString());
Assert.assertEquals( "0x:ABCDEF", preprocessor.process("0x:A BC DEF").toString());
Assert.assertEquals( "0x:ABCDEF*0*x", preprocessor.process("0x:A BC DEF*0x").toString());
Assert.assertEquals( "0x:ABCDEF001*0*x", preprocessor.process("0x:A BC DEF001*0x").toString());
Assert.assertEquals( "0x:ABCDEF001*0*c", preprocessor.process("0x:A BC DEF001*0c").toString());
Assert.assertEquals( "0x:ABCDEF001*c", preprocessor.process("0x:A BC DEF001*c").toString());
Assert.assertEquals( "0b:1101", preprocessor.process("0b:1101").toString());
Assert.assertEquals( "0x:1c", preprocessor.process("0x:1c").toString());
Assert.assertEquals( "0x:1c", preprocessor.process(" 0x:1c").toString());
Assert.assertEquals( "0x:1c*0x:1c*sin(0x:1c)-0b:1101+√(0x:1c)+exp(0x:1c)", preprocessor.process("0x:1c*0x:1c * sin(0x:1c) - 0b:1101 + √(0x:1c) + exp ( 0x:1c)").toString());
Assert.assertEquals( "0x:1c*0x:1c*sin(0x:1c)-0b:1101+√(0x:1c)+exp(0x:1c)", preprocessor.process("0x:1c*0x:1c * sin(0x:1c) - 0b:1101 + √(0x:1c) + exp ( 0x:1c)").toString());
Assert.assertEquals( "0x:1C", preprocessor.process("0x:1C").toString());
Assert.assertEquals( "0x:1C", preprocessor.process(" 0x:1C").toString());
Assert.assertEquals( "0x:1C*0x:1C*sin(0x:1C)-0b:1101+√(0x:1C)+exp(0x:1C)", preprocessor.process("0x:1C*0x:1C * sin(0x:1C) - 0b:1101 + √(0x:1C) + exp ( 0x:1C)").toString());
Assert.assertEquals( "0x:1C*0x:1C*sin(0x:1C)-0b:1101+√(0x:1C)+exp(0x:1C)", preprocessor.process("0x:1C*0x:1C * sin(0x:1C) - 0b:1101 + √(0x:1C) + exp ( 0x:1C)").toString());
try {
preprocessor.process("ln()");
@ -147,7 +153,7 @@ public class ToJsclTextProcessorTest {
Assert.assertEquals("101", JsclMathEngine.instance.evaluate("10+11"));
JsclMathEngine.instance.setNumeralBase(NumeralBase.hex);
Assert.assertEquals("56ce+cad", processor.process("56ce+cad").getExpression());
Assert.assertEquals("56CE+CAD", processor.process("56CE+CAD").getExpression());
} finally {
JsclMathEngine.instance.setNumeralBase(defaultNumeralBase);
}