diff --git a/res/layout/calc_eight_digit_button.xml b/res/layout/calc_eight_digit_button.xml
index ed3f46ad..635a3918 100644
--- a/res/layout/calc_eight_digit_button.xml
+++ b/res/layout/calc_eight_digit_button.xml
@@ -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"/>
\ No newline at end of file
diff --git a/res/layout/calc_five_digit_button.xml b/res/layout/calc_five_digit_button.xml
index c18062ec..af262729 100644
--- a/res/layout/calc_five_digit_button.xml
+++ b/res/layout/calc_five_digit_button.xml
@@ -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"/>
\ No newline at end of file
diff --git a/res/layout/calc_four_digit_button.xml b/res/layout/calc_four_digit_button.xml
index d7475560..35e06a0e 100644
--- a/res/layout/calc_four_digit_button.xml
+++ b/res/layout/calc_four_digit_button.xml
@@ -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"/>
\ No newline at end of file
diff --git a/res/layout/calc_nine_digit_button.xml b/res/layout/calc_nine_digit_button.xml
index 327d5e6f..86027e41 100644
--- a/res/layout/calc_nine_digit_button.xml
+++ b/res/layout/calc_nine_digit_button.xml
@@ -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"/>
\ No newline at end of file
diff --git a/res/layout/calc_one_digit_button.xml b/res/layout/calc_one_digit_button.xml
index f01a399c..049207e4 100644
--- a/res/layout/calc_one_digit_button.xml
+++ b/res/layout/calc_one_digit_button.xml
@@ -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"/>
\ No newline at end of file
diff --git a/res/layout/calc_seven_digit_button.xml b/res/layout/calc_seven_digit_button.xml
index c467479b..c61ee349 100644
--- a/res/layout/calc_seven_digit_button.xml
+++ b/res/layout/calc_seven_digit_button.xml
@@ -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"/>
\ No newline at end of file
diff --git a/res/layout/calc_six_digit_button.xml b/res/layout/calc_six_digit_button.xml
index 91b54339..cd36b215 100644
--- a/res/layout/calc_six_digit_button.xml
+++ b/res/layout/calc_six_digit_button.xml
@@ -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"/>
\ No newline at end of file
diff --git a/res/layout/calc_three_digit_button.xml b/res/layout/calc_three_digit_button.xml
index a7ecee06..a33d780a 100644
--- a/res/layout/calc_three_digit_button.xml
+++ b/res/layout/calc_three_digit_button.xml
@@ -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"/>
\ No newline at end of file
diff --git a/res/layout/calc_two_digit_button.xml b/res/layout/calc_two_digit_button.xml
index 8c05fac1..65b789c1 100644
--- a/res/layout/calc_two_digit_button.xml
+++ b/res/layout/calc_two_digit_button.xml
@@ -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"/>
\ No newline at end of file
diff --git a/res/values/attrs.xml b/res/values/attrs.xml
index 5fd57fd4..a523e340 100644
--- a/res/values/attrs.xml
+++ b/res/values/attrs.xml
@@ -4,7 +4,7 @@
-
+
diff --git a/res/values/default_values.xml b/res/values/default_values.xml
index 215dfecf..00babc34 100644
--- a/res/values/default_values.xml
+++ b/res/values/default_values.xml
@@ -7,7 +7,7 @@
org.solovyev.android.calculator.DragButtonCalibrationActivity_distance
- 15;350
+ 35;350
org.solovyev.android.calculator.DragButtonCalibrationActivity_angle
0;45
diff --git a/res/xml/main_preferences.xml b/res/xml/main_preferences.xml
index ceb9c06e..0b27ae69 100644
--- a/res/xml/main_preferences.xml
+++ b/res/xml/main_preferences.xml
@@ -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"/>
diff --git a/src/main/java/org/solovyev/android/calculator/TextHighlighter.java b/src/main/java/org/solovyev/android/calculator/TextHighlighter.java
index 906b9150..2b1d9b79 100644
--- a/src/main/java/org/solovyev/android/calculator/TextHighlighter.java
+++ b/src/main/java/org/solovyev/android/calculator/TextHighlighter.java
@@ -132,7 +132,7 @@ public class TextHighlighter implements TextProcessor 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 numberOffset) {
+ private static MathType.Result replaceSystemVars(StringBuilder sb, String number, int numberOfTokens, @Nullable MutableObject 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);
+ }
}
}
diff --git a/src/main/java/org/solovyev/android/view/widgets/DirectionDragButton.java b/src/main/java/org/solovyev/android/view/widgets/DirectionDragButton.java
index 21b1061d..f61473cd 100644
--- a/src/main/java/org/solovyev/android/view/widgets/DirectionDragButton.java
+++ b/src/main/java/org/solovyev/android/view/widgets/DirectionDragButton.java
@@ -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 directionTextDataMap = new EnumMap(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 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 getDirectionTextScales() {
+ final List scales = CollectionsUtils.split(getDirectionTextScale(), ";", new NumberParser(Float.class));
+
+ final Map result = new HashMap();
+ 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 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;
+ }
+
}
diff --git a/src/test/java/org/solovyev/android/calculator/TextHighlighterTest.java b/src/test/java/org/solovyev/android/calculator/TextHighlighterTest.java
index a9435605..ab143cdf 100644
--- a/src/test/java/org/solovyev/android/calculator/TextHighlighterTest.java
+++ b/src/test/java/org/solovyev/android/calculator/TextHighlighterTest.java
@@ -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("20x:", textHighlighter.process("20x:").toString());
+ Assert.assertEquals("20x:", 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("sin(2)", textHighlighter.process("sin(2)").toString());
Assert.assertEquals("atanh(2)", textHighlighter.process("atanh(2)").toString());
+
+ Assert.assertEquals("0x:E", textHighlighter.process("0x:E").toString());
+ Assert.assertEquals("0x:6F", textHighlighter.process("0x:6F").toString());
+ Assert.assertEquals("0x:6F", textHighlighter.process("0x:6F.").toString());
+ Assert.assertEquals("0x:6F", textHighlighter.process("0x:6F.2").toString());
+ Assert.assertEquals("0x:6F", textHighlighter.process("0x:6F.B").toString());
+ Assert.assertEquals("0x:6F", textHighlighter.process("0x:006F.B").toString());
+ Assert.assertEquals("0x:0", textHighlighter.process("0x:0").toString());
+ Assert.assertEquals("0x:FF33233FFE", textHighlighter.process("0x:FF33233FFE").toString());
+ Assert.assertEquals("0x: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("0b:110101", textHighlighter.process("0b:110101").toString());
+ Assert.assertEquals("0b:110101", textHighlighter.process("0b:110101.").toString());
+ Assert.assertEquals("0b:110101", textHighlighter.process("0b:110101.101").toString());
+ Assert.assertEquals("0b:11010100", textHighlighter.process("0b:11010100.1").toString());
+ Assert.assertEquals("0b:110101", textHighlighter.process("0b:110101.0").toString());
+ Assert.assertEquals("0b:0", textHighlighter.process("0b:0").toString());
+ Assert.assertEquals("0b:1010100101111010101001", textHighlighter.process("0b:1010100101111010101001").toString());
+ Assert.assertEquals("0b: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);
+ }
}
}
diff --git a/src/test/java/org/solovyev/android/calculator/model/CalculatorEngineTest.java b/src/test/java/org/solovyev/android/calculator/model/CalculatorEngineTest.java
index 2ec50e0f..3e04b076 100644
--- a/src/test/java/org/solovyev/android/calculator/model/CalculatorEngineTest.java
+++ b/src/test/java/org/solovyev/android/calculator/model/CalculatorEngineTest.java
@@ -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);
}
diff --git a/src/test/java/org/solovyev/android/calculator/model/FromJsclSimplifyTextProcessorTest.java b/src/test/java/org/solovyev/android/calculator/model/FromJsclSimplifyTextProcessorTest.java
index b0066679..e3d0248d 100644
--- a/src/test/java/org/solovyev/android/calculator/model/FromJsclSimplifyTextProcessorTest.java
+++ b/src/test/java/org/solovyev/android/calculator/model/FromJsclSimplifyTextProcessorTest.java
@@ -66,7 +66,7 @@ public class FromJsclSimplifyTextProcessorTest {
Assert.assertEquals("20x", tp.process("20x"));
Assert.assertEquals("2×0x3", tp.process("2*0x3"));
Assert.assertEquals("2×0x:3", tp.process("2*0x:3"));
- Assert.assertEquals("0x:3 000 000", tp.process("0x:3 000 000.00000000000001"));
+ Assert.assertEquals("0x:3000000", tp.process("0x:3 000 000.00000000000001"));
}
}
diff --git a/src/test/java/org/solovyev/android/calculator/model/NumeralBaseTest.java b/src/test/java/org/solovyev/android/calculator/model/NumeralBaseTest.java
index 075a429b..d47bfc75 100644
--- a/src/test/java/org/solovyev/android/calculator/model/NumeralBaseTest.java
+++ b/src/test/java/org/solovyev/android/calculator/model/NumeralBaseTest.java
@@ -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 input = new ArrayList();
input.add(dec);
@@ -93,9 +93,9 @@ public class NumeralBaseTest {
}
public static void testExpression(@NotNull String[] line, @NotNull Converter 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();
diff --git a/src/test/java/org/solovyev/android/calculator/model/ToJsclTextProcessorTest.java b/src/test/java/org/solovyev/android/calculator/model/ToJsclTextProcessorTest.java
index 3bce2998..68756933 100644
--- a/src/test/java/org/solovyev/android/calculator/model/ToJsclTextProcessorTest.java
+++ b/src/test/java/org/solovyev/android/calculator/model/ToJsclTextProcessorTest.java
@@ -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);
}