fixes for highlighting the expression and calculating factorial

This commit is contained in:
serso 2011-10-30 00:36:07 +04:00
parent dd63a57c0b
commit 81693efc98
4 changed files with 16 additions and 5 deletions

View File

@ -84,7 +84,9 @@ public class CalculatorEditor extends EditText {
}
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() {

View File

@ -45,10 +45,6 @@ class ToJsclTextProcessor implements TextProcessor<PreparedExpression> {
if (mathTypeBefore == MathType.function && CollectionsUtils.find(MathType.openGroupSymbols, startsWithFinder) != null) {
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);

View File

@ -42,5 +42,16 @@ public class TextHighlighterTest {
Assert.assertEquals(")", textHighlighter.process(")").toString());
Assert.assertEquals(")()(", textHighlighter.process(")()(").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");
}
}

View File

@ -5,6 +5,7 @@
package org.solovyev.android.calculator.model;
import jscl.math.Expression;
import org.junit.Assert;
import org.junit.BeforeClass;
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("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("36.0", Expression.valueOf("3!^2").numeric().toString());
try {
junit.framework.Assert.assertEquals("i", cm.evaluate(JsclOperation.numeric, "i!").getResult());
fail();