fixes for highlighting the expression and calculating factorial
This commit is contained in:
parent
dd63a57c0b
commit
81693efc98
@ -84,7 +84,9 @@ public class CalculatorEditor extends EditText {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Log.d(this.getClass().getName(), getText().toString());
|
Log.d(this.getClass().getName(), getText().toString());
|
||||||
setSelection(selectionStart, selectionEnd);
|
|
||||||
|
int length = getText().length();
|
||||||
|
setSelection(Math.max(Math.min(length - 1, selectionStart), 0), Math.max(Math.min(length - 1, selectionEnd), 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isHighlightText() {
|
public boolean isHighlightText() {
|
||||||
|
@ -45,10 +45,6 @@ class ToJsclTextProcessor implements TextProcessor<PreparedExpression> {
|
|||||||
|
|
||||||
if (mathTypeBefore == MathType.function && CollectionsUtils.find(MathType.openGroupSymbols, startsWithFinder) != null) {
|
if (mathTypeBefore == MathType.function && CollectionsUtils.find(MathType.openGroupSymbols, startsWithFinder) != null) {
|
||||||
throw new ParseException("Empty function: " + mathTypeResult.getMatch());
|
throw new ParseException("Empty function: " + mathTypeResult.getMatch());
|
||||||
} else if (mathTypeBefore == MathType.postfix_function && mathTypeResult.getMathType() == MathType.binary_operation) {
|
|
||||||
if ( mathTypeResult.getMatch().equals("^") ) {
|
|
||||||
throw new ParseException("Power operation after postfix function is currently unsupported!");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
i = mathTypeResult.processToJscl(result, i);
|
i = mathTypeResult.processToJscl(result, i);
|
||||||
|
@ -42,5 +42,16 @@ public class TextHighlighterTest {
|
|||||||
Assert.assertEquals(")", textHighlighter.process(")").toString());
|
Assert.assertEquals(")", textHighlighter.process(")").toString());
|
||||||
Assert.assertEquals(")()(", textHighlighter.process(")()(").toString());
|
Assert.assertEquals(")()(", textHighlighter.process(")()(").toString());
|
||||||
Assert.assertEquals("1 000 000", textHighlighter.process("1000000").toString());
|
Assert.assertEquals("1 000 000", textHighlighter.process("1000000").toString());
|
||||||
|
|
||||||
|
textHighlighter.process("cannot calculate 3^10^10 !!!\n" +
|
||||||
|
" unable to enter 0. FIXED\n" +
|
||||||
|
" empty display in Xperia Rayo\n" +
|
||||||
|
" check привиденная FIXED\n" +
|
||||||
|
" set display result only if text in editor was not changed FIXED\n" +
|
||||||
|
" shift M text to the left\n" +
|
||||||
|
" do not show SYNTAX ERROR always (may be show send clock?q) FIXED\n" +
|
||||||
|
" ln(8)*log(8) => ln(8)*og(8) FIXED\n" +
|
||||||
|
" copy/paste ln(8)*log(8)\n" +
|
||||||
|
" 6!^2 ERROR");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
package org.solovyev.android.calculator.model;
|
package org.solovyev.android.calculator.model;
|
||||||
|
|
||||||
|
import jscl.math.Expression;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -108,6 +109,7 @@ public class CalculatorEngineTest {
|
|||||||
junit.framework.Assert.assertEquals("120", cm.evaluate(JsclOperation.numeric, "(2+2+1)!").getResult());
|
junit.framework.Assert.assertEquals("120", cm.evaluate(JsclOperation.numeric, "(2+2+1)!").getResult());
|
||||||
junit.framework.Assert.assertEquals("24", cm.evaluate(JsclOperation.numeric, "(2.0+2.0)!").getResult());
|
junit.framework.Assert.assertEquals("24", cm.evaluate(JsclOperation.numeric, "(2.0+2.0)!").getResult());
|
||||||
junit.framework.Assert.assertEquals("24", cm.evaluate(JsclOperation.numeric, "4.0!").getResult());
|
junit.framework.Assert.assertEquals("24", cm.evaluate(JsclOperation.numeric, "4.0!").getResult());
|
||||||
|
junit.framework.Assert.assertEquals("36.0", Expression.valueOf("3!^2").numeric().toString());
|
||||||
try {
|
try {
|
||||||
junit.framework.Assert.assertEquals("i", cm.evaluate(JsclOperation.numeric, "i!").getResult());
|
junit.framework.Assert.assertEquals("i", cm.evaluate(JsclOperation.numeric, "i!").getResult());
|
||||||
fail();
|
fail();
|
||||||
|
Loading…
Reference in New Issue
Block a user