Tests
This commit is contained in:
parent
abb67a9b0b
commit
dd74c3a231
@ -16,4 +16,13 @@ public abstract class BaseCalculationEvent {
|
|||||||
this.expression = expression;
|
this.expression = expression;
|
||||||
this.sequence = sequence;
|
this.sequence = sequence;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "BaseCalculationEvent{" +
|
||||||
|
"operation=" + operation +
|
||||||
|
", expression='" + expression + '\'' +
|
||||||
|
", sequence=" + sequence +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,4 +30,14 @@ public final class CalculationFinishedEvent extends BaseCalculationEvent {
|
|||||||
this.stringResult = stringResult;
|
this.stringResult = stringResult;
|
||||||
this.messages = messages;
|
this.messages = messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "CalculationFinishedEvent{" +
|
||||||
|
"super=" + super.toString() +
|
||||||
|
", result=" + result +
|
||||||
|
", stringResult='" + stringResult + '\'' +
|
||||||
|
", messages=" + messages +
|
||||||
|
"}";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,16 +3,12 @@ package org.solovyev.android.calculator;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import com.squareup.otto.Bus;
|
import com.squareup.otto.Bus;
|
||||||
import jscl.JsclMathEngine;
|
|
||||||
import org.hamcrest.Description;
|
import org.hamcrest.Description;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.mockito.ArgumentMatcher;
|
import org.mockito.ArgumentMatcher;
|
||||||
import org.solovyev.android.calculator.calculations.CalculationFailedEvent;
|
import org.solovyev.android.calculator.calculations.CalculationFailedEvent;
|
||||||
import org.solovyev.android.calculator.calculations.CalculationFinishedEvent;
|
import org.solovyev.android.calculator.calculations.CalculationFinishedEvent;
|
||||||
import org.solovyev.android.calculator.functions.FunctionsRegistry;
|
|
||||||
import org.solovyev.android.calculator.jscl.JsclOperation;
|
import org.solovyev.android.calculator.jscl.JsclOperation;
|
||||||
import org.solovyev.android.calculator.operators.OperatorsRegistry;
|
|
||||||
import org.solovyev.android.calculator.operators.PostfixFunctionsRegistry;
|
|
||||||
|
|
||||||
import static org.mockito.Matchers.argThat;
|
import static org.mockito.Matchers.argThat;
|
||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
@ -27,13 +23,8 @@ public abstract class BaseCalculatorTest {
|
|||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
bus = mock(Bus.class);
|
bus = mock(Bus.class);
|
||||||
calculator = new Calculator(mock(SharedPreferences.class), bus, Tests.sameThreadExecutor());
|
calculator = new Calculator(mock(SharedPreferences.class), bus, Tests.sameThreadExecutor());
|
||||||
final JsclMathEngine mathEngine = JsclMathEngine.getInstance();
|
engine = Tests.makeEngine();
|
||||||
engine = new Engine(mathEngine);
|
|
||||||
engine.postfixFunctionsRegistry = new PostfixFunctionsRegistry(mathEngine);
|
|
||||||
engine.functionsRegistry = new FunctionsRegistry(mathEngine);
|
|
||||||
engine.variablesRegistry = new VariablesRegistry(mathEngine);
|
|
||||||
engine.variablesRegistry.bus = bus;
|
engine.variablesRegistry.bus = bus;
|
||||||
engine.operatorsRegistry = new OperatorsRegistry(mathEngine);
|
|
||||||
calculator.engine = engine;
|
calculator.engine = engine;
|
||||||
calculator.preferredPreferences = mock(PreferredPreferences.class);
|
calculator.preferredPreferences = mock(PreferredPreferences.class);
|
||||||
final ToJsclTextProcessor processor = new ToJsclTextProcessor();
|
final ToJsclTextProcessor processor = new ToJsclTextProcessor();
|
||||||
|
@ -23,19 +23,27 @@
|
|||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import jscl.JsclMathEngine;
|
import android.os.Build;
|
||||||
|
import com.squareup.otto.Bus;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mockito.Mockito;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.robolectric.RobolectricGradleTestRunner;
|
||||||
|
import org.robolectric.annotation.Config;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
|
@Config(constants = BuildConfig.class, sdk = Build.VERSION_CODES.LOLLIPOP)
|
||||||
|
@RunWith(value = RobolectricGradleTestRunner.class)
|
||||||
public class EditorTest {
|
public class EditorTest {
|
||||||
|
|
||||||
private Editor editor;
|
private Editor editor;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
this.editor = new Editor(Mockito.mock(SharedPreferences.class), new Engine(new JsclMathEngine()));
|
editor = new Editor(mock(SharedPreferences.class), Tests.makeEngine());
|
||||||
|
editor.bus = mock(Bus.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -22,7 +22,6 @@
|
|||||||
|
|
||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
import jscl.JsclMathEngine;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.solovyev.android.calculator.text.FromJsclSimplifyTextProcessor;
|
import org.solovyev.android.calculator.text.FromJsclSimplifyTextProcessor;
|
||||||
import org.solovyev.android.calculator.variables.CppVariable;
|
import org.solovyev.android.calculator.variables.CppVariable;
|
||||||
@ -35,7 +34,7 @@ public class FromJsclSimplifyTextProcessorTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testProcess() throws Exception {
|
public void testProcess() throws Exception {
|
||||||
final Engine engine = new Engine(new JsclMathEngine());
|
final Engine engine = Tests.makeEngine();
|
||||||
FromJsclSimplifyTextProcessor tp = new FromJsclSimplifyTextProcessor(engine);
|
FromJsclSimplifyTextProcessor tp = new FromJsclSimplifyTextProcessor(engine);
|
||||||
//Assert.assertEquals("(e)", tp.process("(2.718281828459045)"));
|
//Assert.assertEquals("(e)", tp.process("(2.718281828459045)"));
|
||||||
//Assert.assertEquals("ee", tp.process("2.718281828459045*2.718281828459045"));
|
//Assert.assertEquals("ee", tp.process("2.718281828459045*2.718281828459045"));
|
||||||
|
@ -1,17 +1,13 @@
|
|||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import org.solovyev.android.calculator.calculations.CalculationFailedEvent;
|
import jscl.JsclMathEngine;
|
||||||
import org.solovyev.android.calculator.calculations.CalculationFinishedEvent;
|
import org.solovyev.android.calculator.functions.FunctionsRegistry;
|
||||||
import org.solovyev.common.msg.Message;
|
import org.solovyev.android.calculator.operators.OperatorsRegistry;
|
||||||
|
import org.solovyev.android.calculator.operators.PostfixFunctionsRegistry;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
import static org.mockito.Matchers.refEq;
|
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
import static org.solovyev.android.calculator.jscl.JsclOperation.numeric;
|
|
||||||
|
|
||||||
public class Tests {
|
public class Tests {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@ -24,13 +20,16 @@ public class Tests {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static void assertError(@NonNull Calculator calculator, @NonNull String expression) {
|
@NonNull
|
||||||
calculator.evaluate(numeric, expression);
|
public static Engine makeEngine() {
|
||||||
verify(calculator.bus).post(refEq(new CalculationFailedEvent(numeric, expression, 0, new Exception()), "exception", "sequence"));
|
final JsclMathEngine mathEngine = JsclMathEngine.getInstance();
|
||||||
}
|
mathEngine.setUseGroupingSeparator(true);
|
||||||
|
mathEngine.setGroupingSeparator(' ');
|
||||||
static void assertEval(@NonNull Calculator calculator, @NonNull String expression, @NonNull String expected) {
|
final Engine engine = new Engine(mathEngine);
|
||||||
calculator.evaluate(numeric, expression);
|
engine.postfixFunctionsRegistry = new PostfixFunctionsRegistry(mathEngine);
|
||||||
verify(calculator.bus).post(refEq(new CalculationFinishedEvent(numeric, expression, 0, null, expected, new ArrayList<Message>()), "result", "sequence"));
|
engine.functionsRegistry = new FunctionsRegistry(mathEngine);
|
||||||
|
engine.variablesRegistry = new VariablesRegistry(mathEngine);
|
||||||
|
engine.operatorsRegistry = new OperatorsRegistry(mathEngine);
|
||||||
|
return engine;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,11 +23,14 @@
|
|||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import jscl.JsclMathEngine;
|
import android.os.Build;
|
||||||
import jscl.MathEngine;
|
import jscl.MathEngine;
|
||||||
import jscl.NumeralBase;
|
import jscl.NumeralBase;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.robolectric.RobolectricGradleTestRunner;
|
||||||
|
import org.robolectric.annotation.Config;
|
||||||
import org.solovyev.android.calculator.text.TextProcessor;
|
import org.solovyev.android.calculator.text.TextProcessor;
|
||||||
import org.solovyev.android.calculator.view.TextHighlighter;
|
import org.solovyev.android.calculator.view.TextHighlighter;
|
||||||
|
|
||||||
@ -36,13 +39,15 @@ import java.util.Random;
|
|||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
@Config(constants = BuildConfig.class, sdk = Build.VERSION_CODES.LOLLIPOP)
|
||||||
|
@RunWith(value = RobolectricGradleTestRunner.class)
|
||||||
public class TextHighlighterTest {
|
public class TextHighlighterTest {
|
||||||
|
|
||||||
private Engine engine;
|
private Engine engine;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
engine = new Engine(new JsclMathEngine());
|
engine = Tests.makeEngine();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -35,7 +35,7 @@ public class ToJsclTextProcessorTest {
|
|||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
preprocessor = new ToJsclTextProcessor();
|
preprocessor = new ToJsclTextProcessor();
|
||||||
preprocessor.engine = new Engine(new JsclMathEngine());
|
preprocessor.engine = Tests.makeEngine();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -37,6 +37,7 @@ public class FromJsclNumericTextProcessorTest {
|
|||||||
final FromJsclNumericTextProcessor cm = new FromJsclNumericTextProcessor();
|
final FromJsclNumericTextProcessor cm = new FromJsclNumericTextProcessor();
|
||||||
|
|
||||||
final JsclMathEngine me = JsclMathEngine.getInstance();
|
final JsclMathEngine me = JsclMathEngine.getInstance();
|
||||||
|
me.setGroupingSeparator(' ');
|
||||||
final AngleUnit defaultAngleUnits = me.getAngleUnits();
|
final AngleUnit defaultAngleUnits = me.getAngleUnits();
|
||||||
|
|
||||||
assertEquals("1.22133+23 123i", cm.process(Expression.valueOf("1.22133232+23123*i").numeric()));
|
assertEquals("1.22133+23 123i", cm.process(Expression.valueOf("1.22133232+23123*i").numeric()));
|
||||||
|
@ -22,11 +22,11 @@
|
|||||||
|
|
||||||
package org.solovyev.android.calculator.math;
|
package org.solovyev.android.calculator.math;
|
||||||
|
|
||||||
import jscl.JsclMathEngine;
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.solovyev.android.calculator.Engine;
|
import org.solovyev.android.calculator.Engine;
|
||||||
|
import org.solovyev.android.calculator.Tests;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.solovyev.android.calculator.math.MathType.postfix_function;
|
import static org.solovyev.android.calculator.math.MathType.postfix_function;
|
||||||
@ -37,7 +37,7 @@ public class MathTypeTest {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
engine = new Engine(new JsclMathEngine());
|
engine = Tests.makeEngine();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
Reference in New Issue
Block a user