tests fixed

This commit is contained in:
Solovyev_S 2013-07-01 13:15:01 +04:00
parent cba364f036
commit 617e0a21d1
4 changed files with 24 additions and 58 deletions

View File

@ -22,8 +22,11 @@
package org.solovyev.android.calculator; package org.solovyev.android.calculator;
import jscl.math.function.IConstant;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.solovyev.android.calculator.model.Var;
/** /**
* User: Solovyev_S * User: Solovyev_S
@ -39,8 +42,6 @@ public class CalculatorImplTest extends AbstractCalculatorTest {
@Test @Test
public void testAnsVariable() throws Exception { public void testAnsVariable() throws Exception {
CalculatorTestUtils.assertError("ans");
CalculatorTestUtils.assertError("ans");
CalculatorTestUtils.assertEval("2", "2"); CalculatorTestUtils.assertEval("2", "2");
CalculatorTestUtils.assertEval("2", "ans"); CalculatorTestUtils.assertEval("2", "ans");
CalculatorTestUtils.assertEval("4", "ans^2"); CalculatorTestUtils.assertEval("4", "ans^2");

View File

@ -34,6 +34,7 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.io.*; import java.io.*;
import java.text.DecimalFormatSymbols;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -50,6 +51,11 @@ public class CalculatorTestUtils {
public static void staticSetUp() throws Exception { 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().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(); Locator.getInstance().getEngine().init();
final DecimalFormatSymbols decimalGroupSymbols = new DecimalFormatSymbols();
decimalGroupSymbols.setDecimalSeparator('.');
decimalGroupSymbols.setGroupingSeparator(' ');
Locator.getInstance().getEngine().setDecimalGroupSymbols(decimalGroupSymbols);
} }
@Nonnull @Nonnull

View File

@ -28,6 +28,9 @@ import org.junit.Test;
import org.solovyev.android.calculator.AbstractCalculatorTest; import org.solovyev.android.calculator.AbstractCalculatorTest;
import org.solovyev.android.calculator.CalculatorTestUtils; import org.solovyev.android.calculator.CalculatorTestUtils;
import static org.junit.Assert.assertEquals;
import static org.solovyev.android.calculator.math.MathType.postfix_function;
/** /**
* User: serso * User: serso
* Date: 10/5/11 * Date: 10/5/11
@ -42,46 +45,29 @@ public class MathTypeTest extends AbstractCalculatorTest {
@Test @Test
public void testGetType() throws Exception { public void testGetType() throws Exception {
Assert.assertEquals(MathType.function, MathType.getType("sin", 0, false).getMathType()); assertEquals(MathType.function, MathType.getType("sin", 0, false).getMathType());
Assert.assertEquals(MathType.text, MathType.getType("sn", 0, false).getMathType()); assertEquals(MathType.text, MathType.getType("sn", 0, false).getMathType());
Assert.assertEquals(MathType.text, MathType.getType("s", 0, false).getMathType()); assertEquals(MathType.text, MathType.getType("s", 0, false).getMathType());
Assert.assertEquals(MathType.text, MathType.getType("", 0, false).getMathType()); assertEquals(MathType.text, MathType.getType("", 0, false).getMathType());
try { try {
Assert.assertEquals(MathType.text, MathType.getType("22", -1, false).getMathType()); assertEquals(MathType.text, MathType.getType("22", -1, false).getMathType());
Assert.fail(); Assert.fail();
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
} }
try { try {
Assert.assertEquals(MathType.text, MathType.getType("22", 2, false).getMathType()); assertEquals(MathType.text, MathType.getType("22", 2, false).getMathType());
Assert.fail(); Assert.fail();
} catch (IllegalArgumentException e) { } 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 { public void testPostfixFunctionsProcessing() throws Exception {
assertEquals(postfix_function, MathType.getType("5!", 1, false).getMathType());
org.junit.Assert.assertEquals(-1, MathType.getPostfixFunctionStart("5!", 1)); assertEquals(postfix_function, MathType.getType("!", 0, false).getMathType());
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("!")));
}*/
} }

View File

@ -24,6 +24,7 @@ package org.solovyev.android.calculator.model;
import jscl.JsclMathEngine; import jscl.JsclMathEngine;
import jscl.NumeralBase; import jscl.NumeralBase;
import jscl.text.ParseException;
import org.junit.Assert; import org.junit.Assert;
import org.junit.BeforeClass; import org.junit.BeforeClass;
@ -130,34 +131,6 @@ public class ToJsclTextProcessorTest extends AbstractCalculatorTest {
} }
} }
@Test
public void testDegrees() throws Exception {
final TextProcessor<PreparedExpression, String> 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("").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 @Test
public void testPostfixFunction() throws Exception { public void testPostfixFunction() throws Exception {
} }