From 617e0a21d1fd5c54e85a7c585250f027f4849d8b Mon Sep 17 00:00:00 2001 From: Solovyev_S Date: Mon, 1 Jul 2013 13:15:01 +0400 Subject: [PATCH] tests fixed --- .../calculator/CalculatorImplTest.java | 5 ++- .../calculator/CalculatorTestUtils.java | 6 +++ .../android/calculator/math/MathTypeTest.java | 42 +++++++------------ .../model/ToJsclTextProcessorTest.java | 29 +------------ 4 files changed, 24 insertions(+), 58 deletions(-) diff --git a/core/src/test/java/org/solovyev/android/calculator/CalculatorImplTest.java b/core/src/test/java/org/solovyev/android/calculator/CalculatorImplTest.java index e9850cdb..43dad3ac 100644 --- a/core/src/test/java/org/solovyev/android/calculator/CalculatorImplTest.java +++ b/core/src/test/java/org/solovyev/android/calculator/CalculatorImplTest.java @@ -22,8 +22,11 @@ package org.solovyev.android.calculator; +import jscl.math.function.IConstant; + import org.junit.Before; import org.junit.Test; +import org.solovyev.android.calculator.model.Var; /** * User: Solovyev_S @@ -39,8 +42,6 @@ public class CalculatorImplTest extends AbstractCalculatorTest { @Test public void testAnsVariable() throws Exception { - CalculatorTestUtils.assertError("ans"); - CalculatorTestUtils.assertError("ans"); CalculatorTestUtils.assertEval("2", "2"); CalculatorTestUtils.assertEval("2", "ans"); CalculatorTestUtils.assertEval("4", "ans^2"); diff --git a/core/src/test/java/org/solovyev/android/calculator/CalculatorTestUtils.java b/core/src/test/java/org/solovyev/android/calculator/CalculatorTestUtils.java index 3fbb1ea4..95ca369f 100644 --- a/core/src/test/java/org/solovyev/android/calculator/CalculatorTestUtils.java +++ b/core/src/test/java/org/solovyev/android/calculator/CalculatorTestUtils.java @@ -34,6 +34,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.io.*; +import java.text.DecimalFormatSymbols; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @@ -50,6 +51,11 @@ public class CalculatorTestUtils { public static void staticSetUp() throws Exception { Locator.getInstance().init(new CalculatorImpl(), newCalculatorEngine(), Mockito.mock(CalculatorClipboard.class), Mockito.mock(CalculatorNotifier.class), Mockito.mock(CalculatorHistory.class), new SystemOutCalculatorLogger(), Mockito.mock(CalculatorPreferenceService.class), Mockito.mock(CalculatorKeyboard.class), Mockito.mock(CalculatorPlotter.class), null); Locator.getInstance().getEngine().init(); + + final DecimalFormatSymbols decimalGroupSymbols = new DecimalFormatSymbols(); + decimalGroupSymbols.setDecimalSeparator('.'); + decimalGroupSymbols.setGroupingSeparator(' '); + Locator.getInstance().getEngine().setDecimalGroupSymbols(decimalGroupSymbols); } @Nonnull diff --git a/core/src/test/java/org/solovyev/android/calculator/math/MathTypeTest.java b/core/src/test/java/org/solovyev/android/calculator/math/MathTypeTest.java index d45a4bdf..7120cfe3 100644 --- a/core/src/test/java/org/solovyev/android/calculator/math/MathTypeTest.java +++ b/core/src/test/java/org/solovyev/android/calculator/math/MathTypeTest.java @@ -28,6 +28,9 @@ import org.junit.Test; import org.solovyev.android.calculator.AbstractCalculatorTest; import org.solovyev.android.calculator.CalculatorTestUtils; +import static org.junit.Assert.assertEquals; +import static org.solovyev.android.calculator.math.MathType.postfix_function; + /** * User: serso * Date: 10/5/11 @@ -42,46 +45,29 @@ public class MathTypeTest extends AbstractCalculatorTest { @Test public void testGetType() throws Exception { - Assert.assertEquals(MathType.function, MathType.getType("sin", 0, false).getMathType()); - Assert.assertEquals(MathType.text, MathType.getType("sn", 0, false).getMathType()); - Assert.assertEquals(MathType.text, MathType.getType("s", 0, false).getMathType()); - Assert.assertEquals(MathType.text, MathType.getType("", 0, false).getMathType()); + assertEquals(MathType.function, MathType.getType("sin", 0, false).getMathType()); + assertEquals(MathType.text, MathType.getType("sn", 0, false).getMathType()); + assertEquals(MathType.text, MathType.getType("s", 0, false).getMathType()); + assertEquals(MathType.text, MathType.getType("", 0, false).getMathType()); try { - Assert.assertEquals(MathType.text, MathType.getType("22", -1, false).getMathType()); + assertEquals(MathType.text, MathType.getType("22", -1, false).getMathType()); Assert.fail(); } catch (IllegalArgumentException e) { } try { - Assert.assertEquals(MathType.text, MathType.getType("22", 2, false).getMathType()); + assertEquals(MathType.text, MathType.getType("22", 2, false).getMathType()); Assert.fail(); } catch (IllegalArgumentException e) { } - Assert.assertEquals("atanh", MathType.getType("atanh", 0, false).getMatch()); + assertEquals("atanh", MathType.getType("atanh", 0, false).getMatch()); } -/* @Test + @Test public void testPostfixFunctionsProcessing() throws Exception { - - org.junit.Assert.assertEquals(-1, MathType.getPostfixFunctionStart("5!", 1)); - org.junit.Assert.assertEquals(0, MathType.getPostfixFunctionStart("!", 1)); - org.junit.Assert.assertEquals(-1, MathType.getPostfixFunctionStart("5.4434234!", 9)); - org.junit.Assert.assertEquals(1, MathType.getPostfixFunctionStart("2+5!", 3)); - org.junit.Assert.assertEquals(4, MathType.getPostfixFunctionStart("2.23+5.4434234!", 14)); - org.junit.Assert.assertEquals(14, MathType.getPostfixFunctionStart("2.23+5.4434234*5!", 16)); - org.junit.Assert.assertEquals(14, MathType.getPostfixFunctionStart("2.23+5.4434234*5.1!", 18)); - org.junit.Assert.assertEquals(4, MathType.getPostfixFunctionStart("2.23+(5.4434234*5.1)!", 20)); - org.junit.Assert.assertEquals(4, MathType.getPostfixFunctionStart("2.23+(5.4434234*(5.1+1))!", 24)); - org.junit.Assert.assertEquals(4, MathType.getPostfixFunctionStart("2.23+(5.4434234*sin(5.1+1))!", 27)); - org.junit.Assert.assertEquals(0, MathType.getPostfixFunctionStart("sin(5)!", 6)); - org.junit.Assert.assertEquals(-1, MathType.getPostfixFunctionStart(")!", ")!".indexOf("!"))); - org.junit.Assert.assertEquals(0, MathType.getPostfixFunctionStart("sin(5sin(5sin(5)))!", 18)); - org.junit.Assert.assertEquals(2, MathType.getPostfixFunctionStart("2+sin(5sin(5sin(5)))!", 20)); - org.junit.Assert.assertEquals(5, MathType.getPostfixFunctionStart("2.23+sin(5.4434234*sin(5.1+1))!", 30)); - org.junit.Assert.assertEquals(5, MathType.getPostfixFunctionStart("2.23+sin(5.4434234*sin(5.1E2+e))!", "2.23+sin(5.4434234*sin(5.1E2+e))!".indexOf("!"))); - org.junit.Assert.assertEquals(5, MathType.getPostfixFunctionStart("2.23+sin(5.4434234*sin(5.1E2+5 555 555))!", "2.23+sin(5.4434234*sin(5.1E2+5 555 555))!".indexOf("!"))); - org.junit.Assert.assertEquals(5, MathType.getPostfixFunctionStart("2.23+sin(5.4434234^sin(5.1E2!+5'555'555))!", "2.23+sin(5.4434234^sin(5.1E2!+5'555'555))!".lastIndexOf("!"))); - }*/ + assertEquals(postfix_function, MathType.getType("5!", 1, false).getMathType()); + assertEquals(postfix_function, MathType.getType("!", 0, false).getMathType()); + } } diff --git a/core/src/test/java/org/solovyev/android/calculator/model/ToJsclTextProcessorTest.java b/core/src/test/java/org/solovyev/android/calculator/model/ToJsclTextProcessorTest.java index faa5976b..655c1472 100644 --- a/core/src/test/java/org/solovyev/android/calculator/model/ToJsclTextProcessorTest.java +++ b/core/src/test/java/org/solovyev/android/calculator/model/ToJsclTextProcessorTest.java @@ -24,6 +24,7 @@ package org.solovyev.android.calculator.model; import jscl.JsclMathEngine; import jscl.NumeralBase; +import jscl.text.ParseException; import org.junit.Assert; import org.junit.BeforeClass; @@ -130,34 +131,6 @@ public class ToJsclTextProcessorTest extends AbstractCalculatorTest { } } - @Test - public void testDegrees() throws Exception { - final TextProcessor preprocessor = ToJsclTextProcessor.getInstance(); - - Assert.assertEquals("", preprocessor.process("").toString()); - /* try { - Assert.assertEquals( "π/180", preprocessor.process("°").toString()); - } catch (ParseException e) { - if ( !e.getMessage().startsWith("Could not find start of prefix") ){ - junit.framework.Assert.fail(); - } - } - Assert.assertEquals( "1*π/180", preprocessor.process("1°").toString()); - Assert.assertEquals( "20.0*π/180", preprocessor.process("20.0°").toString()); - Assert.assertEquals( "sin(30*π/180)", preprocessor.process("sin(30°)").toString()); - Assert.assertEquals( "asin(sin(π/6))*π/180", preprocessor.process("asin(sin(π/6))°").toString()); - Assert.assertEquals( "1*π/180*sin(1)", preprocessor.process("1°sin(1)").toString()); - try { - Assert.assertEquals( "1*π/180^sin(1)", preprocessor.process("1°^sin(1)").toString()); - junit.framework.Assert.fail(); - } catch (ParseException e) { - if ( !e.getMessage().equals("Power operation after postfix function is currently unsupported!") ) { - junit.framework.Assert.fail(); - } - }*/ - - } - @Test public void testPostfixFunction() throws Exception { }