changes
This commit is contained in:
@@ -48,6 +48,11 @@ 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("20x", textHighlighter.process("20x").toString());
|
||||
Assert.assertEquals("22x", textHighlighter.process("22x").toString());
|
||||
Assert.assertEquals("20t", textHighlighter.process("20t").toString());
|
||||
Assert.assertEquals("20k", textHighlighter.process("20k").toString());
|
||||
Assert.assertEquals("1 000 000E3", textHighlighter.process("1000000E3").toString());
|
||||
Assert.assertEquals("-1 000 000E3", textHighlighter.process("-1000000E3").toString());
|
||||
Assert.assertEquals("-1 000 000E-3", textHighlighter.process("-1000000E-3").toString());
|
||||
|
@@ -6,8 +6,12 @@
|
||||
|
||||
package org.solovyev.android.calculator.jscl;
|
||||
|
||||
import jscl.math.Expression;
|
||||
import jscl.math.Generic;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.solovyev.android.calculator.model.CalculatorEngine;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
@@ -16,13 +20,20 @@ import org.junit.Test;
|
||||
*/
|
||||
public class FromJsclNumericTextProcessorTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() throws Exception {
|
||||
CalculatorEngine.instance.init(null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateResultForComplexNumber() throws Exception {
|
||||
final FromJsclNumericTextProcessor cm = new FromJsclNumericTextProcessor();
|
||||
|
||||
Assert.assertEquals("1.22133+23 123i", cm.createResultForComplexNumber("1.22133232+23123*i"));
|
||||
Assert.assertEquals("1.22133+1.2i", cm.createResultForComplexNumber("1.22133232+1.2*i"));
|
||||
Assert.assertEquals("1.22i", cm.createResultForComplexNumber("1.22*i"));
|
||||
Assert.assertEquals("i", cm.createResultForComplexNumber("i"));
|
||||
Assert.assertEquals("1.22133+23 123i", cm.process(Expression.valueOf("1.22133232+23123*i").numeric()));
|
||||
Assert.assertEquals("1.22133+1.2i", cm.process(Expression.valueOf("1.22133232+1.2*i").numeric()));
|
||||
Assert.assertEquals("1.22i", cm.process(Expression.valueOf("1.22*i").numeric()));
|
||||
Assert.assertEquals("i", cm.process(Expression.valueOf("i").numeric()));
|
||||
Generic numeric = Expression.valueOf("e^(π*i)+1").numeric();
|
||||
junit.framework.Assert.assertEquals("0i", cm.process(numeric));
|
||||
}
|
||||
}
|
||||
|
@@ -132,8 +132,8 @@ public class CalculatorEngineTest {
|
||||
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("720", cm.evaluate(JsclOperation.numeric, "3!!").getResult());
|
||||
junit.framework.Assert.assertEquals("36.0", Expression.valueOf("3!^2").numeric().toString());
|
||||
junit.framework.Assert.assertEquals("3.0", Expression.valueOf("cubic(27)").numeric().toString());
|
||||
junit.framework.Assert.assertEquals("36", Expression.valueOf("3!^2").numeric().toString());
|
||||
junit.framework.Assert.assertEquals("3", Expression.valueOf("cubic(27)").numeric().toString());
|
||||
try {
|
||||
junit.framework.Assert.assertEquals("√(-1)!", cm.evaluate(JsclOperation.numeric, "i!").getResult());
|
||||
fail();
|
||||
@@ -369,8 +369,12 @@ public class CalculatorEngineTest {
|
||||
} catch (CalculatorEvalException e) {
|
||||
// ok
|
||||
}
|
||||
|
||||
cm.getEngine().setNumeralBase(NumeralBase.hex);
|
||||
Assert.assertEquals("637b", cm.evaluate(JsclOperation.numeric, "56ce+cad").getResult());
|
||||
} finally {
|
||||
cm.setNumeralBase(defaultNumeralBase);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -62,6 +62,11 @@ public class FromJsclSimplifyTextProcessorTest {
|
||||
|
||||
Assert.assertEquals("tlog(3)", tp.process("t*log(3)"));
|
||||
Assert.assertEquals("t√(3)", tp.process("t*√(3)"));
|
||||
Assert.assertEquals("20x", tp.process("20*x"));
|
||||
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"));
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -6,6 +6,8 @@
|
||||
|
||||
package org.solovyev.android.calculator.model;
|
||||
|
||||
import jscl.JsclMathEngine;
|
||||
import jscl.NumeralBase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
@@ -120,4 +122,20 @@ public class ToJsclTextProcessorTest {
|
||||
@Test
|
||||
public void testPostfixFunction() throws Exception {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNumeralBases() throws Exception {
|
||||
final ToJsclTextProcessor processor = new ToJsclTextProcessor();
|
||||
|
||||
final NumeralBase defaultNumeralBase = JsclMathEngine.instance.getNumeralBase();
|
||||
try{
|
||||
JsclMathEngine.instance.setNumeralBase(NumeralBase.bin);
|
||||
Assert.assertEquals("101", JsclMathEngine.instance.evaluate("10+11"));
|
||||
|
||||
JsclMathEngine.instance.setNumeralBase(NumeralBase.hex);
|
||||
Assert.assertEquals("56ce+cad", processor.process("56ce+cad").getExpression());
|
||||
} finally {
|
||||
JsclMathEngine.instance.setNumeralBase(defaultNumeralBase);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user