From 5372c500e8980ea810b6fe250e49dc186e17f9d7 Mon Sep 17 00:00:00 2001 From: serso Date: Thu, 17 Nov 2011 17:50:14 +0400 Subject: [PATCH] fixes --- res/layout/calc_operators_button.xml | 1 - .../org/solovyev/android/calculator/TextHighlighter.java | 5 +++++ .../android/calculator/model/CalculatorEngineTest.java | 8 +++++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/res/layout/calc_operators_button.xml b/res/layout/calc_operators_button.xml index ffb943fc..a62fce58 100644 --- a/res/layout/calc_operators_button.xml +++ b/res/layout/calc_operators_button.xml @@ -9,6 +9,5 @@ \ No newline at end of file diff --git a/src/main/java/org/solovyev/android/calculator/TextHighlighter.java b/src/main/java/org/solovyev/android/calculator/TextHighlighter.java index 34ccca9e..676571ca 100644 --- a/src/main/java/org/solovyev/android/calculator/TextHighlighter.java +++ b/src/main/java/org/solovyev/android/calculator/TextHighlighter.java @@ -105,6 +105,11 @@ public class TextHighlighter implements TextProcessor { text1.append(text.charAt(i)); break; case operator: + text1.append(mathType.getMatch()); + if (mathType.getMatch().length() > 1) { + i += mathType.getMatch().length() - 1; + } + break; case function: i = processHighlightedText(text1, i, mathType.getMatch(), "i"); break; 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 58bf8ff3..dc081551 100644 --- a/src/test/java/org/solovyev/android/calculator/model/CalculatorEngineTest.java +++ b/src/test/java/org/solovyev/android/calculator/model/CalculatorEngineTest.java @@ -81,7 +81,7 @@ public class CalculatorEngineTest { Assert.assertEquals("0", cm.evaluate(JsclOperation.numeric, "eq(0, 1)").getResult()); Assert.assertEquals("1", cm.evaluate(JsclOperation.numeric, "eq(1, 1)").getResult()); Assert.assertEquals("1", cm.evaluate(JsclOperation.numeric, "eq( 1, 1)").getResult()); - Assert.assertEquals("eq(1,1)", cm.evaluate(JsclOperation.simplify, "eq( 1, 1)").getResult()); + Assert.assertEquals("1", cm.evaluate(JsclOperation.simplify, "eq( 1, 1)").getResult()); Assert.assertEquals("1", cm.evaluate(JsclOperation.numeric, "lg(10)").getResult()); Assert.assertEquals("4", cm.evaluate(JsclOperation.numeric, "2+2").getResult()); Assert.assertEquals("-0.757", cm.evaluate(JsclOperation.numeric, "sin(4)").getResult()); @@ -184,6 +184,12 @@ public class CalculatorEngineTest { cm.setTimeout(3000); }*/ + CalculatorEngine.instance.getVarsRegister().add(new Var.Builder("t", (String) null)); + Assert.assertEquals("2t", cm.evaluate(JsclOperation.simplify, "∂(t^2,t)").getResult()); + Assert.assertEquals("2t", cm.evaluate(JsclOperation.numeric, "∂(t^2,t)").getResult()); + CalculatorEngine.instance.getVarsRegister().add(new Var.Builder("t", "2")); + Assert.assertEquals("2t", cm.evaluate(JsclOperation.simplify, "∂(t^2,t)").getResult()); + Assert.assertEquals("4", cm.evaluate(JsclOperation.numeric, "∂(t^2,t)").getResult()); } @Test