tests + proguard

This commit is contained in:
serso 2012-10-09 17:21:58 +04:00
parent 213d6fd270
commit 21640c051a
9 changed files with 1758 additions and 1626 deletions

View File

@ -1,132 +1,127 @@
package org.solovyev.android.calculator; package org.solovyev.android.calculator;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
/** /**
* User: Solovyev_S * User: Solovyev_S
* Date: 20.09.12 * Date: 20.09.12
* Time: 16:40 * Time: 16:40
*/ */
public enum CalculatorEventType { public enum CalculatorEventType {
/* /*
********************************************************************** **********************************************************************
* *
* CALCULATION * CALCULATION
* org.solovyev.android.calculator.CalculatorEvaluationEventData * org.solovyev.android.calculator.CalculatorEvaluationEventData
* *
********************************************************************** **********************************************************************
*/ */
// @NotNull CalculatorEditorViewState // @NotNull CalculatorEditorViewState
manual_calculation_requested, manual_calculation_requested,
// @NotNull org.solovyev.android.calculator.CalculatorInput // @NotNull org.solovyev.android.calculator.CalculatorOutput
calculation_started, calculation_result,
// @NotNull org.solovyev.android.calculator.CalculatorOutput calculation_cancelled,
calculation_result,
// @NotNull org.solovyev.android.calculator.CalculatorFailure
calculation_cancelled, calculation_failed,
// @NotNull org.solovyev.android.calculator.CalculatorFailure /*
calculation_failed, **********************************************************************
*
calculation_finished, * CONVERSION
* CalculatorConversionEventData
/* *
********************************************************************** **********************************************************************
* */
* CONVERSION conversion_started,
* CalculatorConversionEventData
* // @NotNull String conversion result
********************************************************************** conversion_result,
*/
conversion_started, // @NotNull ConversionFailure
conversion_failed,
// @NotNull String conversion result
conversion_result, conversion_finished,
// @NotNull ConversionFailure /*
conversion_failed, **********************************************************************
*
conversion_finished, * EDITOR
*
/* **********************************************************************
********************************************************************** */
*
* EDITOR // @NotNull org.solovyev.android.calculator.CalculatorEditorChangeEventData
* editor_state_changed,
**********************************************************************
*/ // @NotNull CalculatorDisplayChangeEventData
display_state_changed,
// @NotNull org.solovyev.android.calculator.CalculatorEditorChangeEventData
editor_state_changed, /*
**********************************************************************
// @NotNull CalculatorDisplayChangeEventData *
display_state_changed, * ENGINE
*
/* **********************************************************************
********************************************************************** */
*
* ENGINE engine_preferences_changed,
*
********************************************************************** /*
*/ **********************************************************************
*
engine_preferences_changed, * HISTORY
*
/* **********************************************************************
********************************************************************** */
*
* HISTORY // @NotNull CalculatorHistoryState
* history_state_added,
**********************************************************************
*/ // @NotNull CalculatorHistoryState
use_history_state,
// @NotNull CalculatorHistoryState
history_state_added, clear_history_requested,
// @NotNull CalculatorHistoryState /*
use_history_state, **********************************************************************
*
clear_history_requested, * MATH ENTITIES
*
/* **********************************************************************
********************************************************************** */
*
* MATH ENTITIES // @NotNull IConstant
* use_constant,
**********************************************************************
*/ // @NotNull Function
use_function,
// @NotNull IConstant
use_constant, // @NotNull Operator
use_operator,
// @NotNull Function
use_function, // @NotNull IConstant
constant_added,
// @NotNull Operator
use_operator, // @NotNull Change<IConstant>
constant_changed,
// @NotNull IConstant
constant_added, // @NotNull IConstant
constant_removed;
// @NotNull Change<IConstant>
constant_changed, public boolean isOfType(@NotNull CalculatorEventType... types) {
for (CalculatorEventType type : types) {
// @NotNull IConstant if ( this == type ) {
constant_removed; return true;
}
public boolean isOfType(@NotNull CalculatorEventType... types) { }
for (CalculatorEventType type : types) {
if ( this == type ) { return false;
return true; }
}
} }
return false;
}
}

View File

@ -1,474 +1,470 @@
package org.solovyev.android.calculator; package org.solovyev.android.calculator;
import jscl.AbstractJsclArithmeticException; import jscl.AbstractJsclArithmeticException;
import jscl.NumeralBase; import jscl.NumeralBase;
import jscl.NumeralBaseException; import jscl.NumeralBaseException;
import jscl.math.Generic; import jscl.math.Generic;
import jscl.math.function.Function; import jscl.math.function.Function;
import jscl.math.function.IConstant; import jscl.math.function.IConstant;
import jscl.math.operator.Operator; import jscl.math.operator.Operator;
import jscl.text.ParseInterruptedException; import jscl.text.ParseInterruptedException;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.solovyev.android.calculator.history.CalculatorHistory; import org.solovyev.android.calculator.history.CalculatorHistory;
import org.solovyev.android.calculator.history.CalculatorHistoryState; import org.solovyev.android.calculator.history.CalculatorHistoryState;
import org.solovyev.android.calculator.jscl.JsclOperation; import org.solovyev.android.calculator.jscl.JsclOperation;
import org.solovyev.android.calculator.text.TextProcessor; import org.solovyev.android.calculator.text.TextProcessor;
import org.solovyev.android.calculator.units.CalculatorNumeralBase; import org.solovyev.android.calculator.units.CalculatorNumeralBase;
import org.solovyev.common.history.HistoryAction; import org.solovyev.common.history.HistoryAction;
import org.solovyev.common.msg.MessageRegistry; import org.solovyev.common.msg.MessageRegistry;
import org.solovyev.common.msg.MessageType; import org.solovyev.common.msg.MessageType;
import org.solovyev.common.text.StringUtils; import org.solovyev.common.text.StringUtils;
import org.solovyev.math.units.ConversionException; import org.solovyev.math.units.ConversionException;
import org.solovyev.math.units.ConversionUtils; import org.solovyev.math.units.ConversionUtils;
import java.util.List; import java.util.List;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
/** /**
* User: Solovyev_S * User: Solovyev_S
* Date: 20.09.12 * Date: 20.09.12
* Time: 16:42 * Time: 16:42
*/ */
public class CalculatorImpl implements Calculator, CalculatorEventListener { public class CalculatorImpl implements Calculator, CalculatorEventListener {
@NotNull @NotNull
private final CalculatorEventContainer calculatorEventContainer = new ListCalculatorEventContainer(); private final CalculatorEventContainer calculatorEventContainer = new ListCalculatorEventContainer();
@NotNull @NotNull
private final AtomicLong counter = new AtomicLong(CalculatorUtils.FIRST_ID); private final AtomicLong counter = new AtomicLong(CalculatorUtils.FIRST_ID);
@NotNull @NotNull
private final TextProcessor<PreparedExpression, String> preprocessor = ToJsclTextProcessor.getInstance(); private final TextProcessor<PreparedExpression, String> preprocessor = ToJsclTextProcessor.getInstance();
@NotNull @NotNull
private final Executor calculationsExecutor = Executors.newFixedThreadPool(10); private final Executor calculationsExecutor = Executors.newFixedThreadPool(10);
// NOTE: only one thread is responsible for events as all events must be done in order of their creating // NOTE: only one thread is responsible for events as all events must be done in order of their creating
@NotNull @NotNull
private final Executor eventExecutor = Executors.newFixedThreadPool(1); private final Executor eventExecutor = Executors.newFixedThreadPool(1);
public CalculatorImpl() { public CalculatorImpl() {
this.addCalculatorEventListener(this); this.addCalculatorEventListener(this);
} }
@NotNull @NotNull
private CalculatorEventData nextEventData() { private CalculatorEventData nextEventData() {
long eventId = counter.incrementAndGet(); long eventId = counter.incrementAndGet();
return CalculatorEventDataImpl.newInstance(eventId, eventId); return CalculatorEventDataImpl.newInstance(eventId, eventId);
} }
@NotNull @NotNull
private CalculatorEventData nextEventData(@NotNull Object source) { private CalculatorEventData nextEventData(@NotNull Object source) {
long eventId = counter.incrementAndGet(); long eventId = counter.incrementAndGet();
return CalculatorEventDataImpl.newInstance(eventId, eventId, source); return CalculatorEventDataImpl.newInstance(eventId, eventId, source);
} }
@NotNull @NotNull
private CalculatorEventData nextEventData(@NotNull Long sequenceId) { private CalculatorEventData nextEventData(@NotNull Long sequenceId) {
long eventId = counter.incrementAndGet(); long eventId = counter.incrementAndGet();
return CalculatorEventDataImpl.newInstance(eventId, sequenceId); return CalculatorEventDataImpl.newInstance(eventId, sequenceId);
} }
/* /*
********************************************************************** **********************************************************************
* *
* CALCULATION * CALCULATION
* *
********************************************************************** **********************************************************************
*/ */
@Override @Override
public void evaluate() { public void evaluate() {
final CalculatorEditorViewState viewState = getEditor().getViewState(); final CalculatorEditorViewState viewState = getEditor().getViewState();
fireCalculatorEvent(CalculatorEventType.manual_calculation_requested, viewState); fireCalculatorEvent(CalculatorEventType.manual_calculation_requested, viewState);
this.evaluate(JsclOperation.numeric, viewState.getText()); this.evaluate(JsclOperation.numeric, viewState.getText());
} }
@Override @Override
public void evaluate(@NotNull Long sequenceId) { public void evaluate(@NotNull Long sequenceId) {
final CalculatorEditorViewState viewState = getEditor().getViewState(); final CalculatorEditorViewState viewState = getEditor().getViewState();
fireCalculatorEvent(CalculatorEventType.manual_calculation_requested, viewState, sequenceId); fireCalculatorEvent(CalculatorEventType.manual_calculation_requested, viewState, sequenceId);
this.evaluate(JsclOperation.numeric, viewState.getText(), sequenceId); this.evaluate(JsclOperation.numeric, viewState.getText(), sequenceId);
} }
@Override @Override
public void simplify() { public void simplify() {
final CalculatorEditorViewState viewState = getEditor().getViewState(); final CalculatorEditorViewState viewState = getEditor().getViewState();
fireCalculatorEvent(CalculatorEventType.manual_calculation_requested, viewState); fireCalculatorEvent(CalculatorEventType.manual_calculation_requested, viewState);
this.evaluate(JsclOperation.simplify, viewState.getText()); this.evaluate(JsclOperation.simplify, viewState.getText());
} }
@NotNull @NotNull
@Override @Override
public CalculatorEventData evaluate(@NotNull final JsclOperation operation, public CalculatorEventData evaluate(@NotNull final JsclOperation operation,
@NotNull final String expression) { @NotNull final String expression) {
final CalculatorEventData eventDataId = nextEventData(); final CalculatorEventData eventDataId = nextEventData();
calculationsExecutor.execute(new Runnable() { calculationsExecutor.execute(new Runnable() {
@Override @Override
public void run() { public void run() {
CalculatorImpl.this.evaluate(eventDataId.getSequenceId(), operation, expression, null); CalculatorImpl.this.evaluate(eventDataId.getSequenceId(), operation, expression, null);
} }
}); });
return eventDataId; return eventDataId;
} }
@NotNull @NotNull
@Override @Override
public CalculatorEventData evaluate(@NotNull final JsclOperation operation, @NotNull final String expression, @NotNull Long sequenceId) { public CalculatorEventData evaluate(@NotNull final JsclOperation operation, @NotNull final String expression, @NotNull Long sequenceId) {
final CalculatorEventData eventDataId = nextEventData(sequenceId); final CalculatorEventData eventDataId = nextEventData(sequenceId);
calculationsExecutor.execute(new Runnable() { calculationsExecutor.execute(new Runnable() {
@Override @Override
public void run() { public void run() {
CalculatorImpl.this.evaluate(eventDataId.getSequenceId(), operation, expression, null); CalculatorImpl.this.evaluate(eventDataId.getSequenceId(), operation, expression, null);
} }
}); });
return eventDataId; return eventDataId;
} }
@Override @Override
public void init() { public void init() {
CalculatorLocatorImpl.getInstance().getEngine().init(); CalculatorLocatorImpl.getInstance().getEngine().init();
CalculatorLocatorImpl.getInstance().getHistory().load(); CalculatorLocatorImpl.getInstance().getHistory().load();
} }
@NotNull @NotNull
private CalculatorConversionEventData newConversionEventData(@NotNull Long sequenceId, private CalculatorConversionEventData newConversionEventData(@NotNull Long sequenceId,
@NotNull Generic value, @NotNull Generic value,
@NotNull NumeralBase from, @NotNull NumeralBase from,
@NotNull NumeralBase to, @NotNull NumeralBase to,
@NotNull CalculatorDisplayViewState displayViewState) { @NotNull CalculatorDisplayViewState displayViewState) {
return CalculatorConversionEventDataImpl.newInstance(nextEventData(sequenceId), value, from, to, displayViewState); return CalculatorConversionEventDataImpl.newInstance(nextEventData(sequenceId), value, from, to, displayViewState);
} }
private void evaluate(@NotNull Long sequenceId, private void evaluate(@NotNull Long sequenceId,
@NotNull JsclOperation operation, @NotNull JsclOperation operation,
@NotNull String expression, @NotNull String expression,
@Nullable MessageRegistry mr) { @Nullable MessageRegistry mr) {
PreparedExpression preparedExpression = null; PreparedExpression preparedExpression = null;
fireCalculatorEvent(newCalculationEventData(operation, expression, sequenceId), CalculatorEventType.calculation_started, new CalculatorInputImpl(expression, operation)); try {
try { expression = expression.trim();
expression = expression.trim(); if (StringUtils.isEmpty(expression)) {
fireCalculatorEvent(newCalculationEventData(operation, expression, sequenceId), CalculatorEventType.calculation_result, CalculatorOutputImpl.newEmptyOutput(operation));
if (StringUtils.isEmpty(expression)) { } else {
fireCalculatorEvent(newCalculationEventData(operation, expression, sequenceId), CalculatorEventType.calculation_result, CalculatorOutputImpl.newEmptyOutput(operation)); preparedExpression = preprocessor.process(expression);
} else {
preparedExpression = preprocessor.process(expression); final String jsclExpression = preparedExpression.toString();
final String jsclExpression = preparedExpression.toString(); try {
try { final Generic result = operation.evaluateGeneric(jsclExpression, CalculatorLocatorImpl.getInstance().getEngine().getMathEngine());
final Generic result = operation.evaluateGeneric(jsclExpression, CalculatorLocatorImpl.getInstance().getEngine().getMathEngine()); // NOTE: toString() method must be called here as ArithmeticOperationException may occur in it (just to avoid later check!)
result.toString();
// NOTE: toString() method must be called here as ArithmeticOperationException may occur in it (just to avoid later check!)
result.toString(); final CalculatorOutput data = CalculatorOutputImpl.newOutput(operation.getFromProcessor().process(result), operation, result);
fireCalculatorEvent(newCalculationEventData(operation, expression, sequenceId), CalculatorEventType.calculation_result, data);
final CalculatorOutput data = CalculatorOutputImpl.newOutput(operation.getFromProcessor().process(result), operation, result);
fireCalculatorEvent(newCalculationEventData(operation, expression, sequenceId), CalculatorEventType.calculation_result, data); } catch (AbstractJsclArithmeticException e) {
handleException(sequenceId, operation, expression, mr, new CalculatorEvalException(e, e, jsclExpression));
} catch (AbstractJsclArithmeticException e) { }
handleException(sequenceId, operation, expression, mr, new CalculatorEvalException(e, e, jsclExpression)); }
}
} } catch (ArithmeticException e) {
handleException(sequenceId, operation, expression, mr, preparedExpression, new CalculatorParseException(expression, new CalculatorMessage(CalculatorMessages.msg_001, MessageType.error, e.getMessage())));
} catch (ArithmeticException e) { } catch (StackOverflowError e) {
handleException(sequenceId, operation, expression, mr, preparedExpression, new CalculatorParseException(expression, new CalculatorMessage(CalculatorMessages.msg_001, MessageType.error, e.getMessage()))); handleException(sequenceId, operation, expression, mr, preparedExpression, new CalculatorParseException(expression, new CalculatorMessage(CalculatorMessages.msg_002, MessageType.error)));
} catch (StackOverflowError e) { } catch (jscl.text.ParseException e) {
handleException(sequenceId, operation, expression, mr, preparedExpression, new CalculatorParseException(expression, new CalculatorMessage(CalculatorMessages.msg_002, MessageType.error))); handleException(sequenceId, operation, expression, mr, preparedExpression, new CalculatorParseException(e));
} catch (jscl.text.ParseException e) { } catch (ParseInterruptedException e) {
handleException(sequenceId, operation, expression, mr, preparedExpression, new CalculatorParseException(e));
} catch (ParseInterruptedException e) { // do nothing - we ourselves interrupt the calculations
fireCalculatorEvent(newCalculationEventData(operation, expression, sequenceId), CalculatorEventType.calculation_cancelled, null);
// do nothing - we ourselves interrupt the calculations
fireCalculatorEvent(newCalculationEventData(operation, expression, sequenceId), CalculatorEventType.calculation_cancelled, null); } catch (CalculatorParseException e) {
handleException(sequenceId, operation, expression, mr, preparedExpression, e);
} catch (CalculatorParseException e) { }
handleException(sequenceId, operation, expression, mr, preparedExpression, e); }
} finally {
fireCalculatorEvent(newCalculationEventData(operation, expression, sequenceId), CalculatorEventType.calculation_finished, null); @NotNull
} private CalculatorEventData newCalculationEventData(@NotNull JsclOperation operation,
} @NotNull String expression,
@NotNull Long calculationId) {
@NotNull return new CalculatorEvaluationEventDataImpl(nextEventData(calculationId), operation, expression);
private CalculatorEventData newCalculationEventData(@NotNull JsclOperation operation, }
@NotNull String expression,
@NotNull Long calculationId) { private void handleException(@NotNull Long sequenceId,
return new CalculatorEvaluationEventDataImpl(nextEventData(calculationId), operation, expression); @NotNull JsclOperation operation,
} @NotNull String expression,
@Nullable MessageRegistry mr,
private void handleException(@NotNull Long sequenceId, @Nullable PreparedExpression preparedExpression,
@NotNull JsclOperation operation, @NotNull CalculatorParseException parseException) {
@NotNull String expression,
@Nullable MessageRegistry mr, if (operation == JsclOperation.numeric
@Nullable PreparedExpression preparedExpression, && preparedExpression != null
@NotNull CalculatorParseException parseException) { && preparedExpression.isExistsUndefinedVar()) {
if (operation == JsclOperation.numeric evaluate(sequenceId, JsclOperation.simplify, expression, mr);
&& preparedExpression != null } else {
&& preparedExpression.isExistsUndefinedVar()) {
fireCalculatorEvent(newCalculationEventData(operation, expression, sequenceId), CalculatorEventType.calculation_failed, new CalculatorFailureImpl(parseException));
evaluate(sequenceId, JsclOperation.simplify, expression, mr); }
} else { }
fireCalculatorEvent(newCalculationEventData(operation, expression, sequenceId), CalculatorEventType.calculation_failed, new CalculatorFailureImpl(parseException)); private void handleException(@NotNull Long calculationId,
} @NotNull JsclOperation operation,
} @NotNull String expression,
@Nullable MessageRegistry mr,
private void handleException(@NotNull Long calculationId, @NotNull CalculatorEvalException evalException) {
@NotNull JsclOperation operation,
@NotNull String expression, if (operation == JsclOperation.numeric && evalException.getCause() instanceof NumeralBaseException) {
@Nullable MessageRegistry mr, evaluate(calculationId, JsclOperation.simplify, expression, mr);
@NotNull CalculatorEvalException evalException) { } else {
fireCalculatorEvent(newCalculationEventData(operation, expression, calculationId), CalculatorEventType.calculation_failed, new CalculatorFailureImpl(evalException));
if (operation == JsclOperation.numeric && evalException.getCause() instanceof NumeralBaseException) { }
evaluate(calculationId, JsclOperation.simplify, expression, mr); }
}
/*
fireCalculatorEvent(newCalculationEventData(operation, expression, calculationId), CalculatorEventType.calculation_failed, new CalculatorFailureImpl(evalException)); **********************************************************************
} *
* CONVERSION
/* *
********************************************************************** **********************************************************************
* */
* CONVERSION
* @NotNull
********************************************************************** @Override
*/ public CalculatorEventData convert(@NotNull final Generic value,
@NotNull final NumeralBase to) {
@NotNull final CalculatorEventData eventDataId = nextEventData();
@Override
public CalculatorEventData convert(@NotNull final Generic value, final CalculatorDisplayViewState displayViewState = CalculatorLocatorImpl.getInstance().getDisplay().getViewState();
@NotNull final NumeralBase to) { final NumeralBase from = CalculatorLocatorImpl.getInstance().getEngine().getNumeralBase();
final CalculatorEventData eventDataId = nextEventData();
calculationsExecutor.execute(new Runnable() {
final CalculatorDisplayViewState displayViewState = CalculatorLocatorImpl.getInstance().getDisplay().getViewState(); @Override
final NumeralBase from = CalculatorLocatorImpl.getInstance().getEngine().getNumeralBase(); public void run() {
final Long sequenceId = eventDataId.getSequenceId();
calculationsExecutor.execute(new Runnable() {
@Override fireCalculatorEvent(newConversionEventData(sequenceId, value, from, to, displayViewState), CalculatorEventType.conversion_started, null);
public void run() { try {
final Long sequenceId = eventDataId.getSequenceId();
final String result = doConversion(value, from, to);
fireCalculatorEvent(newConversionEventData(sequenceId, value, from, to, displayViewState), CalculatorEventType.conversion_started, null);
try { fireCalculatorEvent(newConversionEventData(sequenceId, value, from, to, displayViewState), CalculatorEventType.conversion_result, result);
final String result = doConversion(value, from, to); } catch (ConversionException e) {
fireCalculatorEvent(newConversionEventData(sequenceId, value, from, to, displayViewState), CalculatorEventType.conversion_failed, new ConversionFailureImpl(e));
fireCalculatorEvent(newConversionEventData(sequenceId, value, from, to, displayViewState), CalculatorEventType.conversion_result, result); }
}
} catch (ConversionException e) { });
fireCalculatorEvent(newConversionEventData(sequenceId, value, from, to, displayViewState), CalculatorEventType.conversion_failed, new ConversionFailureImpl(e));
} return eventDataId;
} }
});
@NotNull
return eventDataId; private static String doConversion(@NotNull Generic generic,
} @NotNull NumeralBase from,
@NotNull NumeralBase to) throws ConversionException {
@NotNull final String result;
private static String doConversion(@NotNull Generic generic,
@NotNull NumeralBase from, if (from != to) {
@NotNull NumeralBase to) throws ConversionException { String fromString = generic.toString();
final String result; if (!StringUtils.isEmpty(fromString)) {
try {
if (from != to) { fromString = ToJsclTextProcessor.getInstance().process(fromString).getExpression();
String fromString = generic.toString(); } catch (CalculatorParseException e) {
if (!StringUtils.isEmpty(fromString)) { // ok, problems while processing occurred
try { }
fromString = ToJsclTextProcessor.getInstance().process(fromString).getExpression(); }
} catch (CalculatorParseException e) {
// ok, problems while processing occurred result = ConversionUtils.doConversion(CalculatorNumeralBase.getConverter(), fromString, CalculatorNumeralBase.valueOf(from), CalculatorNumeralBase.valueOf(to));
} } else {
} result = generic.toString();
}
result = ConversionUtils.doConversion(CalculatorNumeralBase.getConverter(), fromString, CalculatorNumeralBase.valueOf(from), CalculatorNumeralBase.valueOf(to));
} else { return result;
result = generic.toString(); }
}
@Override
return result; public boolean isConversionPossible(@NotNull Generic generic, NumeralBase from, @NotNull NumeralBase to) {
} try {
doConversion(generic, from, to);
@Override return true;
public boolean isConversionPossible(@NotNull Generic generic, NumeralBase from, @NotNull NumeralBase to) { } catch (ConversionException e) {
try { return false;
doConversion(generic, from, to); }
return true; }
} catch (ConversionException e) {
return false; /*
} **********************************************************************
} *
* EVENTS
/* *
********************************************************************** **********************************************************************
* */
* EVENTS
* @Override
********************************************************************** public void addCalculatorEventListener(@NotNull CalculatorEventListener calculatorEventListener) {
*/ calculatorEventContainer.addCalculatorEventListener(calculatorEventListener);
}
@Override
public void addCalculatorEventListener(@NotNull CalculatorEventListener calculatorEventListener) { @Override
calculatorEventContainer.addCalculatorEventListener(calculatorEventListener); public void removeCalculatorEventListener(@NotNull CalculatorEventListener calculatorEventListener) {
} calculatorEventContainer.removeCalculatorEventListener(calculatorEventListener);
}
@Override
public void removeCalculatorEventListener(@NotNull CalculatorEventListener calculatorEventListener) { @Override
calculatorEventContainer.removeCalculatorEventListener(calculatorEventListener); public void fireCalculatorEvent(@NotNull final CalculatorEventData calculatorEventData, @NotNull final CalculatorEventType calculatorEventType, @Nullable final Object data) {
} eventExecutor.execute(new Runnable() {
@Override
@Override public void run() {
public void fireCalculatorEvent(@NotNull final CalculatorEventData calculatorEventData, @NotNull final CalculatorEventType calculatorEventType, @Nullable final Object data) { calculatorEventContainer.fireCalculatorEvent(calculatorEventData, calculatorEventType, data);
eventExecutor.execute(new Runnable() { }
@Override });
public void run() { }
calculatorEventContainer.fireCalculatorEvent(calculatorEventData, calculatorEventType, data);
} @Override
}); public void fireCalculatorEvents(@NotNull final List<CalculatorEvent> calculatorEvents) {
} eventExecutor.execute(new Runnable() {
@Override
@Override public void run() {
public void fireCalculatorEvents(@NotNull final List<CalculatorEvent> calculatorEvents) { calculatorEventContainer.fireCalculatorEvents(calculatorEvents);
eventExecutor.execute(new Runnable() { }
@Override });
public void run() { }
calculatorEventContainer.fireCalculatorEvents(calculatorEvents);
} @NotNull
}); @Override
} public CalculatorEventData fireCalculatorEvent(@NotNull final CalculatorEventType calculatorEventType, @Nullable final Object data) {
final CalculatorEventData eventData = nextEventData();
@NotNull
@Override fireCalculatorEvent(eventData, calculatorEventType, data);
public CalculatorEventData fireCalculatorEvent(@NotNull final CalculatorEventType calculatorEventType, @Nullable final Object data) {
final CalculatorEventData eventData = nextEventData(); return eventData;
}
fireCalculatorEvent(eventData, calculatorEventType, data);
@NotNull
return eventData; @Override
} public CalculatorEventData fireCalculatorEvent(@NotNull final CalculatorEventType calculatorEventType, @Nullable final Object data, @NotNull Object source) {
final CalculatorEventData eventData = nextEventData(source);
@NotNull
@Override fireCalculatorEvent(eventData, calculatorEventType, data);
public CalculatorEventData fireCalculatorEvent(@NotNull final CalculatorEventType calculatorEventType, @Nullable final Object data, @NotNull Object source) {
final CalculatorEventData eventData = nextEventData(source); return eventData;
}
fireCalculatorEvent(eventData, calculatorEventType, data);
@NotNull
return eventData; @Override
} public CalculatorEventData fireCalculatorEvent(@NotNull final CalculatorEventType calculatorEventType, @Nullable final Object data, @NotNull Long sequenceId) {
final CalculatorEventData eventData = nextEventData(sequenceId);
@NotNull
@Override fireCalculatorEvent(eventData, calculatorEventType, data);
public CalculatorEventData fireCalculatorEvent(@NotNull final CalculatorEventType calculatorEventType, @Nullable final Object data, @NotNull Long sequenceId) {
final CalculatorEventData eventData = nextEventData(sequenceId); return eventData;
}
fireCalculatorEvent(eventData, calculatorEventType, data);
/*
return eventData; **********************************************************************
} *
* EVENTS HANDLER
/* *
********************************************************************** **********************************************************************
* */
* EVENTS HANDLER
* @Override
********************************************************************** public void onCalculatorEvent(@NotNull CalculatorEventData calculatorEventData, @NotNull CalculatorEventType calculatorEventType, @Nullable Object data) {
*/
switch (calculatorEventType) {
@Override case editor_state_changed:
public void onCalculatorEvent(@NotNull CalculatorEventData calculatorEventData, @NotNull CalculatorEventType calculatorEventType, @Nullable Object data) { final CalculatorEditorChangeEventData changeEventData = (CalculatorEditorChangeEventData) data;
switch (calculatorEventType) { final String newText = changeEventData.getNewValue().getText();
case editor_state_changed: final String oldText = changeEventData.getOldValue().getText();
final CalculatorEditorChangeEventData changeEventData = (CalculatorEditorChangeEventData) data;
if (!newText.equals(oldText)) {
final String newText = changeEventData.getNewValue().getText(); evaluate(JsclOperation.numeric, changeEventData.getNewValue().getText(), calculatorEventData.getSequenceId());
final String oldText = changeEventData.getOldValue().getText(); }
break;
if (!newText.equals(oldText)) {
evaluate(JsclOperation.numeric, changeEventData.getNewValue().getText(), calculatorEventData.getSequenceId()); case engine_preferences_changed:
} evaluate(calculatorEventData.getSequenceId());
break; break;
case engine_preferences_changed: case use_constant:
evaluate(calculatorEventData.getSequenceId()); final IConstant constant = (IConstant)data;
break; CalculatorLocatorImpl.getInstance().getKeyboard().digitButtonPressed(constant.getName());
break;
case use_constant:
final IConstant constant = (IConstant)data; case use_operator:
CalculatorLocatorImpl.getInstance().getKeyboard().digitButtonPressed(constant.getName()); final Operator operator = (Operator)data;
break; CalculatorLocatorImpl.getInstance().getKeyboard().digitButtonPressed(operator.getName());
break;
case use_operator:
final Operator operator = (Operator)data; case use_function:
CalculatorLocatorImpl.getInstance().getKeyboard().digitButtonPressed(operator.getName()); final Function function = (Function)data;
break; CalculatorLocatorImpl.getInstance().getKeyboard().digitButtonPressed(function.getName());
break;
case use_function:
final Function function = (Function)data; }
CalculatorLocatorImpl.getInstance().getKeyboard().digitButtonPressed(function.getName()); }
break;
/*
} **********************************************************************
} *
* HISTORY
/* *
********************************************************************** **********************************************************************
* */
* HISTORY
* @Override
********************************************************************** public void doHistoryAction(@NotNull HistoryAction historyAction) {
*/ final CalculatorHistory history = CalculatorLocatorImpl.getInstance().getHistory();
if (history.isActionAvailable(historyAction)) {
@Override final CalculatorHistoryState newState = history.doAction(historyAction, getCurrentHistoryState());
public void doHistoryAction(@NotNull HistoryAction historyAction) { if (newState != null) {
final CalculatorHistory history = CalculatorLocatorImpl.getInstance().getHistory(); setCurrentHistoryState(newState);
if (history.isActionAvailable(historyAction)) { }
final CalculatorHistoryState newState = history.doAction(historyAction, getCurrentHistoryState()); }
if (newState != null) { }
setCurrentHistoryState(newState);
} @Override
} public void setCurrentHistoryState(@NotNull CalculatorHistoryState editorHistoryState) {
} editorHistoryState.setValuesFromHistory(getEditor(), getDisplay());
}
@Override
public void setCurrentHistoryState(@NotNull CalculatorHistoryState editorHistoryState) { @NotNull
editorHistoryState.setValuesFromHistory(getEditor(), getDisplay()); @Override
} public CalculatorHistoryState getCurrentHistoryState() {
return CalculatorHistoryState.newInstance(getEditor(), getDisplay());
@NotNull }
@Override
public CalculatorHistoryState getCurrentHistoryState() { /*
return CalculatorHistoryState.newInstance(getEditor(), getDisplay()); **********************************************************************
} *
* OTHER
/* *
********************************************************************** **********************************************************************
* */
* OTHER
* @NotNull
********************************************************************** private CalculatorEditor getEditor() {
*/ return CalculatorLocatorImpl.getInstance().getEditor();
}
@NotNull
private CalculatorEditor getEditor() { @NotNull
return CalculatorLocatorImpl.getInstance().getEditor(); private CalculatorDisplay getDisplay() {
} return CalculatorLocatorImpl.getInstance().getDisplay();
}
@NotNull }
private CalculatorDisplay getDisplay() {
return CalculatorLocatorImpl.getInstance().getDisplay();
}
}

View File

@ -1,113 +1,113 @@
package org.solovyev.android.calculator; package org.solovyev.android.calculator;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.solovyev.android.calculator.history.CalculatorHistory; import org.solovyev.android.calculator.history.CalculatorHistory;
/** /**
* User: Solovyev_S * User: Solovyev_S
* Date: 20.09.12 * Date: 20.09.12
* Time: 12:45 * Time: 12:45
*/ */
public class CalculatorLocatorImpl implements CalculatorLocator { public class CalculatorLocatorImpl implements CalculatorLocator {
@NotNull @NotNull
private CalculatorEngine calculatorEngine; private CalculatorEngine calculatorEngine;
@NotNull @NotNull
private Calculator calculator; private Calculator calculator;
@NotNull @NotNull
private CalculatorEditor calculatorEditor; private CalculatorEditor calculatorEditor;
@NotNull @NotNull
private CalculatorDisplay calculatorDisplay; private CalculatorDisplay calculatorDisplay;
@NotNull @NotNull
private CalculatorKeyboard calculatorKeyboard; private CalculatorKeyboard calculatorKeyboard;
@NotNull @NotNull
private CalculatorHistory calculatorHistory; private CalculatorHistory calculatorHistory;
@NotNull @NotNull
private CalculatorNotifier calculatorNotifier = new DummyCalculatorNotifier(); private CalculatorNotifier calculatorNotifier = new DummyCalculatorNotifier();
@NotNull @NotNull
private CalculatorClipboard calculatorClipboard = new DummyCalculatorClipboard(); private CalculatorClipboard calculatorClipboard = new DummyCalculatorClipboard();
@NotNull @NotNull
private static final CalculatorLocator instance = new CalculatorLocatorImpl(); private static final CalculatorLocator instance = new CalculatorLocatorImpl();
private CalculatorLocatorImpl() { public CalculatorLocatorImpl() {
} }
@Override @Override
public void init(@NotNull Calculator calculator, public void init(@NotNull Calculator calculator,
@NotNull CalculatorEngine engine, @NotNull CalculatorEngine engine,
@NotNull CalculatorClipboard clipboard, @NotNull CalculatorClipboard clipboard,
@NotNull CalculatorNotifier notifier, @NotNull CalculatorNotifier notifier,
@NotNull CalculatorHistory history) { @NotNull CalculatorHistory history) {
this.calculator = calculator; this.calculator = calculator;
this.calculatorEngine = engine; this.calculatorEngine = engine;
this.calculatorClipboard = clipboard; this.calculatorClipboard = clipboard;
this.calculatorNotifier = notifier; this.calculatorNotifier = notifier;
this.calculatorHistory = history; this.calculatorHistory = history;
calculatorEditor = new CalculatorEditorImpl(this.calculator); calculatorEditor = new CalculatorEditorImpl(this.calculator);
calculatorDisplay = new CalculatorDisplayImpl(this.calculator); calculatorDisplay = new CalculatorDisplayImpl(this.calculator);
calculatorKeyboard = new CalculatorKeyboardImpl(this.calculator); calculatorKeyboard = new CalculatorKeyboardImpl(this.calculator);
} }
@NotNull @NotNull
public static CalculatorLocator getInstance() { public static CalculatorLocator getInstance() {
return instance; return instance;
} }
@NotNull @NotNull
@Override @Override
public CalculatorEngine getEngine() { public CalculatorEngine getEngine() {
return calculatorEngine; return calculatorEngine;
} }
@NotNull @NotNull
@Override @Override
public Calculator getCalculator() { public Calculator getCalculator() {
return this.calculator; return this.calculator;
} }
@Override @Override
@NotNull @NotNull
public CalculatorDisplay getDisplay() { public CalculatorDisplay getDisplay() {
return calculatorDisplay; return calculatorDisplay;
} }
@NotNull @NotNull
@Override @Override
public CalculatorEditor getEditor() { public CalculatorEditor getEditor() {
return calculatorEditor; return calculatorEditor;
} }
@Override @Override
@NotNull @NotNull
public CalculatorKeyboard getKeyboard() { public CalculatorKeyboard getKeyboard() {
return calculatorKeyboard; return calculatorKeyboard;
} }
@Override @Override
@NotNull @NotNull
public CalculatorClipboard getClipboard() { public CalculatorClipboard getClipboard() {
return calculatorClipboard; return calculatorClipboard;
} }
@Override @Override
@NotNull @NotNull
public CalculatorNotifier getNotifier() { public CalculatorNotifier getNotifier() {
return calculatorNotifier; return calculatorNotifier;
} }
@Override @Override
@NotNull @NotNull
public CalculatorHistory getHistory() { public CalculatorHistory getHistory() {
return calculatorHistory; return calculatorHistory;
} }
} }

View File

@ -21,7 +21,7 @@ import java.util.List;
@Root @Root
public class History { public class History {
@ElementList @ElementList(type = CalculatorHistoryState.class)
private List<CalculatorHistoryState> historyItems = new ArrayList<CalculatorHistoryState>(); private List<CalculatorHistoryState> historyItems = new ArrayList<CalculatorHistoryState>();
public History() { public History() {

View File

@ -1,33 +1,138 @@
package org.solovyev.android.calculator; package org.solovyev.android.calculator;
import jscl.JsclMathEngine; import jscl.JsclMathEngine;
import org.jetbrains.annotations.NotNull; import junit.framework.Assert;
import org.mockito.Mockito; import org.jetbrains.annotations.NotNull;
import org.solovyev.android.calculator.history.CalculatorHistory; import org.jetbrains.annotations.Nullable;
import org.mockito.Mockito;
/** import org.solovyev.android.calculator.history.CalculatorHistory;
* User: serso import org.solovyev.android.calculator.jscl.JsclOperation;
* Date: 10/7/12
* Time: 8:40 PM import java.util.concurrent.CountDownLatch;
*/ import java.util.concurrent.TimeUnit;
public class CalculatorTestUtils {
/**
public static void staticSetUp() throws Exception { * User: serso
CalculatorLocatorImpl.getInstance().init(new CalculatorImpl(), newCalculatorEngine(), Mockito.mock(CalculatorClipboard.class), Mockito.mock(CalculatorNotifier.class), Mockito.mock(CalculatorHistory.class)); * Date: 10/7/12
CalculatorLocatorImpl.getInstance().getEngine().init(); * Time: 8:40 PM
} */
public class CalculatorTestUtils {
@NotNull
static CalculatorEngineImpl newCalculatorEngine() { // in seconds
final MathEntityDao mathEntityDao = Mockito.mock(MathEntityDao.class); public static final int TIMEOUT = 1000;
final JsclMathEngine jsclEngine = JsclMathEngine.getInstance(); public static void staticSetUp() throws Exception {
CalculatorLocatorImpl.getInstance().init(new CalculatorImpl(), newCalculatorEngine(), Mockito.mock(CalculatorClipboard.class), Mockito.mock(CalculatorNotifier.class), Mockito.mock(CalculatorHistory.class));
final CalculatorVarsRegistry varsRegistry = new CalculatorVarsRegistry(jsclEngine.getConstantsRegistry(), mathEntityDao); CalculatorLocatorImpl.getInstance().getEngine().init();
final CalculatorFunctionsMathRegistry functionsRegistry = new CalculatorFunctionsMathRegistry(jsclEngine.getFunctionsRegistry(), mathEntityDao); }
final CalculatorOperatorsMathRegistry operatorsRegistry = new CalculatorOperatorsMathRegistry(jsclEngine.getOperatorsRegistry(), mathEntityDao);
final CalculatorPostfixFunctionsRegistry postfixFunctionsRegistry = new CalculatorPostfixFunctionsRegistry(jsclEngine.getPostfixFunctionsRegistry(), mathEntityDao); @NotNull
static CalculatorEngineImpl newCalculatorEngine() {
return new CalculatorEngineImpl(jsclEngine, varsRegistry, functionsRegistry, operatorsRegistry, postfixFunctionsRegistry, null); final MathEntityDao mathEntityDao = Mockito.mock(MathEntityDao.class);
}
} final JsclMathEngine jsclEngine = JsclMathEngine.getInstance();
final CalculatorVarsRegistry varsRegistry = new CalculatorVarsRegistry(jsclEngine.getConstantsRegistry(), mathEntityDao);
final CalculatorFunctionsMathRegistry functionsRegistry = new CalculatorFunctionsMathRegistry(jsclEngine.getFunctionsRegistry(), mathEntityDao);
final CalculatorOperatorsMathRegistry operatorsRegistry = new CalculatorOperatorsMathRegistry(jsclEngine.getOperatorsRegistry(), mathEntityDao);
final CalculatorPostfixFunctionsRegistry postfixFunctionsRegistry = new CalculatorPostfixFunctionsRegistry(jsclEngine.getPostfixFunctionsRegistry(), mathEntityDao);
return new CalculatorEngineImpl(jsclEngine, varsRegistry, functionsRegistry, operatorsRegistry, postfixFunctionsRegistry, null);
}
public static void assertEval(@NotNull String expected, @NotNull String expression) {
assertEval(expected, expression, JsclOperation.numeric);
}
public static void assertEval(@NotNull String expected, @NotNull String expression, @NotNull JsclOperation operation) {
final Calculator calculator = CalculatorLocatorImpl.getInstance().getCalculator();
CalculatorLocatorImpl.getInstance().getDisplay().setViewState(CalculatorDisplayViewStateImpl.newDefaultInstance());
final CountDownLatch latch = new CountDownLatch(1);
final TestCalculatorEventListener calculatorEventListener = new TestCalculatorEventListener(latch);
try {
calculator.addCalculatorEventListener(calculatorEventListener);
calculatorEventListener.setCalculatorEventData(calculator.evaluate(operation, expression));
if (latch.await(TIMEOUT, TimeUnit.SECONDS)) {
Assert.assertNotNull(calculatorEventListener.getResult());
Assert.assertEquals(expected, calculatorEventListener.getResult().getText());
} else {
Assert.fail("Too long wait for: " + expression);
}
} catch (InterruptedException e) {
throw new RuntimeException(e);
} finally {
calculator.removeCalculatorEventListener(calculatorEventListener);
}
}
public static void assertError(@NotNull String expression) {
assertError(expression, JsclOperation.numeric);
}
private static final class TestCalculatorEventListener implements CalculatorEventListener {
@Nullable
private CalculatorEventData calculatorEventData;
@NotNull
private final CountDownLatch latch;
@Nullable
private volatile CalculatorDisplayViewState result = null;
public TestCalculatorEventListener(@NotNull CountDownLatch latch) {
this.latch = latch;
}
public void setCalculatorEventData(@Nullable CalculatorEventData calculatorEventData) {
this.calculatorEventData = calculatorEventData;
}
@Override
public void onCalculatorEvent(@NotNull CalculatorEventData calculatorEventData, @NotNull CalculatorEventType calculatorEventType, @Nullable Object data) {
if ( this.calculatorEventData != null && calculatorEventData.isSameSequence(this.calculatorEventData) ) {
if ( calculatorEventType == CalculatorEventType.display_state_changed ) {
final CalculatorDisplayChangeEventData displayChange = (CalculatorDisplayChangeEventData)data;
result = displayChange.getNewValue();
latch.countDown();
}
}
}
@Nullable
public CalculatorDisplayViewState getResult() {
return result;
}
}
public static void assertError(@NotNull String expression, @NotNull JsclOperation operation) {
final Calculator calculator = CalculatorLocatorImpl.getInstance().getCalculator();
CalculatorLocatorImpl.getInstance().getDisplay().setViewState(CalculatorDisplayViewStateImpl.newDefaultInstance());
final CountDownLatch latch = new CountDownLatch(1);
final TestCalculatorEventListener calculatorEventListener = new TestCalculatorEventListener(latch);
try {
calculator.addCalculatorEventListener(calculatorEventListener);
calculatorEventListener.setCalculatorEventData(calculator.evaluate(operation, expression));
if (latch.await(TIMEOUT, TimeUnit.SECONDS)) {
Assert.assertNotNull(calculatorEventListener.getResult());
Assert.assertFalse(calculatorEventListener.getResult().isValid());
} else {
Assert.fail("Too long wait for: " + expression);
}
} catch (InterruptedException e) {
throw new RuntimeException(e);
} finally {
calculator.removeCalculatorEventListener(calculatorEventListener);
}
}
}

View File

@ -1,448 +1,426 @@
/* /*
* Copyright (c) 2009-2011. Created by serso aka se.solovyev. * Copyright (c) 2009-2011. Created by serso aka se.solovyev.
* For more information, please, contact se.solovyev@gmail.com * For more information, please, contact se.solovyev@gmail.com
*/ */
package org.solovyev.android.calculator.model; package org.solovyev.android.calculator.model;
import jscl.AngleUnit; import jscl.AngleUnit;
import jscl.JsclMathEngine; import jscl.JsclMathEngine;
import jscl.MathEngine; import jscl.MathEngine;
import jscl.NumeralBase; import jscl.NumeralBase;
import jscl.math.Expression; import jscl.math.Expression;
import jscl.math.Generic; import jscl.math.Generic;
import jscl.math.function.Constant; import jscl.math.function.Constant;
import jscl.math.function.CustomFunction; import jscl.math.function.CustomFunction;
import jscl.text.ParseException; import jscl.text.ParseException;
import junit.framework.Assert; import junit.framework.Assert;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.solovyev.android.calculator.CalculatorEvalException; import org.solovyev.android.calculator.AbstractCalculatorTest;
import org.solovyev.android.calculator.CalculatorLocatorImpl; import org.solovyev.android.calculator.CalculatorEvalException;
import org.solovyev.android.calculator.CalculatorTestUtils; import org.solovyev.android.calculator.CalculatorLocatorImpl;
import org.solovyev.android.calculator.CalculatorTestUtils;
import java.text.DecimalFormatSymbols; import org.solovyev.android.calculator.jscl.JsclOperation;
import java.util.Locale;
import java.text.DecimalFormatSymbols;
import static junit.framework.Assert.fail; import java.util.Locale;
/** import static junit.framework.Assert.fail;
* User: serso
* Date: 9/17/11 /**
* Time: 9:47 PM * User: serso
*/ * Date: 9/17/11
* Time: 9:47 PM
@SuppressWarnings("deprecation") */
public class AndroidCalculatorEngineTest {
@SuppressWarnings("deprecation")
@BeforeClass public class AndroidCalculatorEngineTest extends AbstractCalculatorTest {
public static void setUp() throws Exception {
CalculatorTestUtils.staticSetUp(); @BeforeClass
CalculatorLocatorImpl.getInstance().getEngine().setPrecision(3); public static void staticSetUp() throws Exception {
} CalculatorTestUtils.staticSetUp();
CalculatorLocatorImpl.getInstance().getEngine().setPrecision(3);
}
@Test
public void testDegrees() throws Exception {
final MathEngine cm = CalculatorLocatorImpl.getInstance().getEngine().getMathEngine0(); @Test
public void testDegrees() throws Exception {
final AngleUnit defaultAngleUnit = cm.getAngleUnits(); final MathEngine cm = CalculatorLocatorImpl.getInstance().getEngine().getMathEngine0();
try {
cm.setAngleUnits(AngleUnit.rad); final AngleUnit defaultAngleUnit = cm.getAngleUnits();
cm.setPrecision(3); try {
try { cm.setAngleUnits(AngleUnit.rad);
Assert.assertEquals("0.017", cm.evaluate("°")); cm.setPrecision(3);
fail(); CalculatorTestUtils.assertError("°");
} catch (ParseException e) { CalculatorTestUtils.assertEval("0.017", "");
CalculatorTestUtils.assertEval("0.349", "20.0°");
} CalculatorTestUtils.assertEval("0.5", "sin(30°)");
CalculatorTestUtils.assertEval("0.524", "asin(sin(30°))");
Assert.assertEquals("0.017", cm.evaluate( "")); CalculatorTestUtils.assertEval("∂(cos(t), t, t, 1°)", "∂(cos(t),t,t,1°)");
Assert.assertEquals("0.349", cm.evaluate( "20.0°"));
Assert.assertEquals("0.5", cm.evaluate( "sin(30°)")); CalculatorTestUtils.assertEval("∂(cos(t), t, t, 1°)", "∂(cos(t),t,t,1°)", JsclOperation.simplify);
Assert.assertEquals("0.524", cm.evaluate( "asin(sin(30°))")); } finally {
Assert.assertEquals("∂(cos(t), t, t, 1°)", cm.evaluate( "∂(cos(t),t,t,1°)")); cm.setAngleUnits(defaultAngleUnit);
}
Assert.assertEquals("∂(cos(t), t, t, 1°)", cm.simplify("∂(cos(t),t,t,1°)")); }
} finally {
cm.setAngleUnits(defaultAngleUnit); /* @Test
} public void testLongExecution() throws Exception {
} final MathEngine cm = CalculatorLocatorImpl.getInstance().getEngine().getMathEngine0();
/* @Test try {
public void testLongExecution() throws Exception { cm.evaluate( "3^10^10^10");
final MathEngine cm = CalculatorLocatorImpl.getInstance().getEngine().getMathEngine0(); fail();
} catch (ParseException e) {
try { if (e.getMessageCode().equals(Messages.msg_3)) {
cm.evaluate( "3^10^10^10");
fail(); } else {
} catch (ParseException e) { System.out.print(e.getCause().getMessage());
if (e.getMessageCode().equals(Messages.msg_3)) { fail();
}
} else { }
System.out.print(e.getCause().getMessage());
fail(); try {
} cm.evaluate("9999999!");
} fail();
} catch (ParseException e) {
try { if (e.getMessageCode().equals(Messages.msg_3)) {
cm.evaluate("9999999!");
fail(); } else {
} catch (ParseException e) { System.out.print(e.getCause().getMessage());
if (e.getMessageCode().equals(Messages.msg_3)) { fail();
}
} else { }
System.out.print(e.getCause().getMessage());
fail(); final long start = System.currentTimeMillis();
} try {
} cm.evaluate( "3^10^10^10");
fail();
final long start = System.currentTimeMillis(); } catch (ParseException e) {
try { if (e.getMessage().startsWith("Too long calculation")) {
cm.evaluate( "3^10^10^10"); final long end = System.currentTimeMillis();
fail(); Assert.assertTrue(end - start < 1000);
} catch (ParseException e) { } else {
if (e.getMessage().startsWith("Too long calculation")) { fail();
final long end = System.currentTimeMillis(); }
Assert.assertTrue(end - start < 1000); }
} else {
fail(); }*/
}
} @Test
public void testEvaluate() throws Exception {
}*/ final MathEngine cm = CalculatorLocatorImpl.getInstance().getEngine().getMathEngine0();
@Test CalculatorTestUtils.assertEval("cos(t)+10%", "cos(t)+10%", JsclOperation.simplify);
public void testEvaluate() throws Exception {
final MathEngine cm = CalculatorLocatorImpl.getInstance().getEngine().getMathEngine0(); final Generic expression = cm.simplifyGeneric("cos(t)+10%");
expression.substitute(new Constant("t"), Expression.valueOf(100d));
Assert.assertEquals("cos(t)+10%", cm.simplify( "cos(t)+10%"));
CalculatorTestUtils.assertEval("it", "it", JsclOperation.simplify);
final Generic expression = cm.simplifyGeneric("cos(t)+10%"); CalculatorTestUtils.assertEval("10%", "10%", JsclOperation.simplify);
expression.substitute(new Constant("t"), Expression.valueOf(100d)); CalculatorTestUtils.assertEval("0", "eq(0, 1)");
CalculatorTestUtils.assertEval("1", "eq(1, 1)");
Assert.assertEquals("it", cm.simplify( "it")); CalculatorTestUtils.assertEval("1", "eq( 1, 1)");
Assert.assertEquals("10%", cm.simplify( "10%")); CalculatorTestUtils.assertEval("1", "eq( 1, 1)", JsclOperation.simplify);
Assert.assertEquals("0", cm.evaluate( "eq(0, 1)")); CalculatorTestUtils.assertEval("1", "lg(10)");
Assert.assertEquals("1", cm.evaluate( "eq(1, 1)")); CalculatorTestUtils.assertEval("4", "2+2");
Assert.assertEquals("1", cm.evaluate( "eq( 1, 1)")); final AngleUnit defaultAngleUnit = cm.getAngleUnits();
Assert.assertEquals("1", cm.simplify( "eq( 1, 1)")); try {
Assert.assertEquals("1", cm.evaluate( "lg(10)")); cm.setAngleUnits(AngleUnit.rad);
Assert.assertEquals("4", cm.evaluate( "2+2")); CalculatorTestUtils.assertEval("-0.757", "sin(4)");
final AngleUnit defaultAngleUnit = cm.getAngleUnits(); CalculatorTestUtils.assertEval("0.524", "asin(0.5)");
try { CalculatorTestUtils.assertEval("-0.396", "sin(4)asin(0.5)");
cm.setAngleUnits(AngleUnit.rad); CalculatorTestUtils.assertEval("-0.56", "sin(4)asin(0.5)√(2)");
Assert.assertEquals("-0.757", cm.evaluate( "sin(4)")); CalculatorTestUtils.assertEval("-0.56", "sin(4)asin(0.5)√(2)");
Assert.assertEquals("0.524", cm.evaluate( "asin(0.5)")); } finally {
Assert.assertEquals("-0.396", cm.evaluate( "sin(4)asin(0.5)")); cm.setAngleUnits(defaultAngleUnit);
Assert.assertEquals("-0.56", cm.evaluate( "sin(4)asin(0.5)√(2)")); }
Assert.assertEquals("-0.56", cm.evaluate( "sin(4)asin(0.5)√(2)")); CalculatorTestUtils.assertEval("7.389", "e^2");
} finally { CalculatorTestUtils.assertEval("7.389", "exp(1)^2");
cm.setAngleUnits(defaultAngleUnit); CalculatorTestUtils.assertEval("7.389", "exp(2)");
} CalculatorTestUtils.assertEval("2+i", "2*1+√(-1)");
Assert.assertEquals("7.389", cm.evaluate( "e^2")); try {
Assert.assertEquals("7.389", cm.evaluate( "exp(1)^2")); cm.setAngleUnits(AngleUnit.rad);
Assert.assertEquals("7.389", cm.evaluate( "exp(2)")); CalculatorTestUtils.assertEval("0.921+Πi", "ln(5cosh(38π√(2cos(2))))");
Assert.assertEquals("2+i", cm.evaluate( "2*1+√(-1)")); CalculatorTestUtils.assertEval("-3.41+3.41i", "(5tan(2i)+2i)/(1-i)");
try { } finally {
cm.setAngleUnits(AngleUnit.rad); cm.setAngleUnits(defaultAngleUnit);
Assert.assertEquals("0.921+Πi", cm.evaluate( "ln(5cosh(38π√(2cos(2))))")); }
Assert.assertEquals("-3.41+3.41i", cm.evaluate( "(5tan(2i)+2i)/(1-i)")); CalculatorTestUtils.assertEval("7.389i", "iexp(2)");
} finally { CalculatorTestUtils.assertEval("2+7.389i", "2+iexp(2)");
cm.setAngleUnits(defaultAngleUnit); CalculatorTestUtils.assertEval("2+7.389i", "2+√(-1)exp(2)");
} CalculatorTestUtils.assertEval("2-2.5i", "2-2.5i");
Assert.assertEquals("7.389i", cm.evaluate( "iexp(2)")); CalculatorTestUtils.assertEval("-2-2.5i", "-2-2.5i");
Assert.assertEquals("2+7.389i", cm.evaluate( "2+iexp(2)")); CalculatorTestUtils.assertEval("-2+2.5i", "-2+2.5i");
Assert.assertEquals("2+7.389i", cm.evaluate( "2+√(-1)exp(2)")); CalculatorTestUtils.assertEval("-2+2.1i", "-2+2.1i");
Assert.assertEquals("2-2.5i", cm.evaluate( "2-2.5i")); CalculatorTestUtils.assertEval("-0.1-0.2i", "(1-i)/(2+6i)");
Assert.assertEquals("-2-2.5i", cm.evaluate( "-2-2.5i"));
Assert.assertEquals("-2+2.5i", cm.evaluate( "-2+2.5i")); CalculatorTestUtils.assertEval("24", "4!");
Assert.assertEquals("-2+2.1i", cm.evaluate( "-2+2.1i")); CalculatorTestUtils.assertEval("24", "(2+2)!");
Assert.assertEquals("-0.1-0.2i", cm.evaluate( "(1-i)/(2+6i)")); CalculatorTestUtils.assertEval("120", "(2+2+1)!");
CalculatorTestUtils.assertEval("24", "(2.0+2.0)!");
junit.framework.Assert.assertEquals("24", cm.evaluate( "4!")); CalculatorTestUtils.assertEval("24", "4.0!");
junit.framework.Assert.assertEquals("24", cm.evaluate( "(2+2)!")); CalculatorTestUtils.assertEval("720", "(3!)!");
junit.framework.Assert.assertEquals("120", cm.evaluate( "(2+2+1)!")); CalculatorTestUtils.assertEval("36", Expression.valueOf("3!^2").numeric().toString());
junit.framework.Assert.assertEquals("24", cm.evaluate( "(2.0+2.0)!")); CalculatorTestUtils.assertEval("3", Expression.valueOf("cubic(27)").numeric().toString());
junit.framework.Assert.assertEquals("24", cm.evaluate( "4.0!")); CalculatorTestUtils.assertError("i!");
junit.framework.Assert.assertEquals("720", cm.evaluate( "(3!)!"));
junit.framework.Assert.assertEquals("36", Expression.valueOf("3!^2").numeric().toString()); CalculatorTestUtils.assertEval("1", cm.evaluate( "(π/π)!"));
junit.framework.Assert.assertEquals("3", Expression.valueOf("cubic(27)").numeric().toString());
try { CalculatorTestUtils.assertError("(-1)i!");
junit.framework.Assert.assertEquals("√(-1)!", cm.evaluate( "i!")); CalculatorTestUtils.assertEval("24i", "4!i");
fail();
} catch (ParseException e) { CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("si", 5d));
}
try {
junit.framework.Assert.assertEquals("1", cm.evaluate( "(π/π)!")); cm.setAngleUnits(AngleUnit.rad);
CalculatorTestUtils.assertEval("0.451", "acos(0.8999999999999811)");
try { CalculatorTestUtils.assertEval("-0.959", "sin(5)");
junit.framework.Assert.assertEquals("i", cm.evaluate( "(-1)i!")); CalculatorTestUtils.assertEval("-4.795", "sin(5)si");
fail(); CalculatorTestUtils.assertEval("-23.973", "sisin(5)si");
} catch (ParseException e) { CalculatorTestUtils.assertEval("-23.973", "si*sin(5)si");
CalculatorTestUtils.assertEval("-3.309", "sisin(5si)si");
} } finally {
junit.framework.Assert.assertEquals("24i", cm.evaluate( "4!i")); cm.setAngleUnits(defaultAngleUnit);
}
CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("si", 5d));
CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("s", 1d));
try { CalculatorTestUtils.assertEval("5", cm.evaluate( "si"));
cm.setAngleUnits(AngleUnit.rad);
Assert.assertEquals("0.451", cm.evaluate( "acos(0.8999999999999811)")); CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("k", 3.5d));
Assert.assertEquals("-0.959", cm.evaluate( "sin(5)")); CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("k1", 4d));
Assert.assertEquals("-4.795", cm.evaluate( "sin(5)si")); CalculatorTestUtils.assertEval("4", "k11");
Assert.assertEquals("-23.973", cm.evaluate( "sisin(5)si"));
Assert.assertEquals("-23.973", cm.evaluate( "si*sin(5)si")); CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("t", (String) null));
Assert.assertEquals("-3.309", cm.evaluate( "sisin(5si)si")); CalculatorTestUtils.assertEval("11t", "t11");
} finally { CalculatorTestUtils.assertEval("11et", "t11e");
cm.setAngleUnits(defaultAngleUnit); CalculatorTestUtils.assertEval("", "");
} CalculatorTestUtils.assertEval("", "Infinity");
CalculatorTestUtils.assertEval("11∞t", "t11∞");
CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("s", 1d)); CalculatorTestUtils.assertEval("-t+t^3", "t(t-1)(t+1)");
Assert.assertEquals("5", cm.evaluate( "si"));
CalculatorTestUtils.assertEval("100", "0.1E3");
CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("k", 3.5d)); CalculatorTestUtils.assertEval("3.957", "ln(8)lg(8)+ln(8)");
CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("k1", 4d));
Assert.assertEquals("4", cm.evaluate( "k11")); CalculatorTestUtils.assertEval("0.933", "0x:E/0x:F");
CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("t", (String) null)); try {
Assert.assertEquals("11t", cm.evaluate( "t11")); cm.setNumeralBase(NumeralBase.hex);
Assert.assertEquals("11et", cm.evaluate( "t11e")); CalculatorTestUtils.assertEval("E/F", "0x:E/0x:F");
Assert.assertEquals("", cm.evaluate( "")); CalculatorTestUtils.assertEval("E/F", cm.simplify( "0x:E/0x:F"));
Assert.assertEquals("", cm.evaluate( "Infinity")); CalculatorTestUtils.assertEval("E/F", "E/F");
Assert.assertEquals("11∞t", cm.evaluate( "t11∞")); CalculatorTestUtils.assertEval("E/F", cm.simplify( "E/F"));
Assert.assertEquals("-t+t^3", cm.evaluate( "t(t-1)(t+1)")); } finally {
cm.setNumeralBase(NumeralBase.dec);
Assert.assertEquals("100", cm.evaluate( "0.1E3")); }
Assert.assertEquals("3.957", cm.evaluate( "ln(8)lg(8)+ln(8)"));
CalculatorTestUtils.assertEval("0", "((((((0))))))");
Assert.assertEquals("0.933", cm.evaluate( "0x:E/0x:F")); CalculatorTestUtils.assertEval("0", "((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((0))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))");
try {
cm.setNumeralBase(NumeralBase.hex); /* CalculatorTestUtils.assertEval("0.524", cm.evaluate( "30°").getResult());
Assert.assertEquals("E/F", cm.evaluate( "0x:E/0x:F")); CalculatorTestUtils.assertEval("0.524", cm.evaluate( "(10+20)°").getResult());
Assert.assertEquals("E/F", cm.simplify( "0x:E/0x:F")); CalculatorTestUtils.assertEval("1.047", cm.evaluate( "(10+20)°*2").getResult());
Assert.assertEquals("E/F", cm.evaluate( "E/F")); try {
Assert.assertEquals("E/F", cm.simplify( "E/F")); CalculatorTestUtils.assertEval("0.278", cm.evaluate( "30°^2").getResult());
} finally { fail();
cm.setNumeralBase(NumeralBase.dec); } catch (ParseException e) {
} if ( !e.getMessage().equals("Power operation after postfix function is currently unsupported!") ) {
fail();
Assert.assertEquals("0", cm.evaluate( "((((((0))))))")); }
Assert.assertEquals("0", cm.evaluate( "((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((0))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))")); }*//*
*//* try {
/* Assert.assertEquals("0.524", cm.evaluate( "30°").getResult()); cm.setTimeout(5000);
Assert.assertEquals("0.524", cm.evaluate( "(10+20)°").getResult()); CalculatorTestUtils.assertEval("2", cm.evaluate( "2!").getResult());
Assert.assertEquals("1.047", cm.evaluate( "(10+20)°*2").getResult()); } finally {
try { cm.setTimeout(3000);
Assert.assertEquals("0.278", cm.evaluate( "30°^2").getResult()); }*/
junit.framework.Assert.fail();
} catch (ParseException e) { CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("t", (String) null));
if ( !e.getMessage().equals("Power operation after postfix function is currently unsupported!") ) { CalculatorTestUtils.assertEval("2t", "∂(t^2,t)", JsclOperation.simplify);
junit.framework.Assert.fail(); CalculatorTestUtils.assertEval("2t", "∂(t^2,t)");
} CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("t", "2"));
}*//* CalculatorTestUtils.assertEval("2t", "∂(t^2,t)", JsclOperation.simplify);
CalculatorTestUtils.assertEval("4", "∂(t^2,t)");
*//* try {
cm.setTimeout(5000); CalculatorTestUtils.assertEval("-x+xln(x)", "∫(ln(x), x)", JsclOperation.simplify);
Assert.assertEquals("2", cm.evaluate( "2!").getResult()); CalculatorTestUtils.assertEval("-(x-xln(x))/(ln(2)+ln(5))", "∫(log(10, x), x)", JsclOperation.simplify);
} finally {
cm.setTimeout(3000); CalculatorTestUtils.assertEval("∫((ln(2)+ln(5))/ln(x), x)", "∫(ln(10)/ln(x), x)", JsclOperation.simplify);
}*/ //CalculatorTestUtils.assertEval("∫(ln(10)/ln(x), x)", Expression.valueOf("∫(log(x, 10), x)").expand().toString());
CalculatorTestUtils.assertEval("∫((ln(2)+ln(5))/ln(x), x)", "∫(log(x, 10), x)");
CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("t", (String) null)); CalculatorTestUtils.assertEval("∫((ln(2)+ln(5))/ln(x), x)", "∫(log(x, 10), x)", JsclOperation.simplify);
Assert.assertEquals("2t", cm.simplify( "∂(t^2,t)")); }
Assert.assertEquals("2t", cm.evaluate( "∂(t^2,t)"));
CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("t", "2")); @Test
Assert.assertEquals("2t", cm.simplify( "∂(t^2,t)")); public void testFormatting() throws Exception {
Assert.assertEquals("4", cm.evaluate( "∂(t^2,t)")); final MathEngine ce = CalculatorLocatorImpl.getInstance().getEngine().getMathEngine0();
Assert.assertEquals("-x+x*ln(x)", cm.simplify("∫(ln(x), x)")); CalculatorTestUtils.assertEval("12 345", ce.simplify( "12345"));
Assert.assertEquals("-(x-x*ln(x))/(ln(2)+ln(5))", cm.simplify("∫(log(10, x), x)"));
}
Assert.assertEquals("∫((ln(2)+ln(5))/ln(x), x)", cm.simplify("∫(ln(10)/ln(x), x)"));
Assert.assertEquals("∫(ln(10)/ln(x), x)", Expression.valueOf("∫(log(x, 10), x)").expand().toString()); @Test
Assert.assertEquals("∫((ln(2)+ln(5))/ln(x), x)", cm.simplify("∫(log(x, 10), x)")); public void testI() throws ParseException, CalculatorEvalException {
} final MathEngine cm = CalculatorLocatorImpl.getInstance().getEngine().getMathEngine0();
@Test CalculatorTestUtils.assertEval("-i", cm.evaluate( "i^3"));
public void testFormatting() throws Exception { for (int i = 0; i < 1000; i++) {
final MathEngine ce = CalculatorLocatorImpl.getInstance().getEngine().getMathEngine0(); double real = (Math.random()-0.5) * 1000;
double imag = (Math.random()-0.5) * 1000;
Assert.assertEquals("12 345", ce.simplify( "12345")); int exp = (int)(Math.random() * 10);
} final StringBuilder sb = new StringBuilder();
sb.append(real);
@Test if ( imag > 0 ) {
public void testI() throws ParseException, CalculatorEvalException { sb.append("+");
final MathEngine cm = CalculatorLocatorImpl.getInstance().getEngine().getMathEngine0(); }
sb.append(imag);
Assert.assertEquals("-i", cm.evaluate( "i^3")); sb.append("^").append(exp);
for (int i = 0; i < 1000; i++) { try {
double real = (Math.random()-0.5) * 1000; cm.evaluate( sb.toString());
double imag = (Math.random()-0.5) * 1000; } catch (Throwable e) {
int exp = (int)(Math.random() * 10); fail(sb.toString());
}
final StringBuilder sb = new StringBuilder(); }
sb.append(real); }
if ( imag > 0 ) {
sb.append("+"); @Test
} public void testEmptyFunction() throws Exception {
sb.append(imag); final MathEngine cm = CalculatorLocatorImpl.getInstance().getEngine().getMathEngine0();
sb.append("^").append(exp); try {
try { cm.evaluate( "cos(cos(cos(cos(acos(acos(acos(acos(acos(acos(acos(acos(cos(cos(cos(cos(cosh(acos(cos(cos(cos(cos(cos(acos(acos(acos(acos(acos(acos(acos(acos(cos(cos(cos(cos(cosh(acos(cos())))))))))))))))))))))))))))))))))))))");
cm.evaluate( sb.toString()); Assert.fail();
} catch (Throwable e) { } catch (ParseException e) {
fail(sb.toString()); }
} CalculatorTestUtils.assertEval("0.34+1.382i", "ln(ln(ln(ln(ln(ln(ln(ln(ln(ln(ln(ln(ln(ln(ln(100)))))))))))))))");
} try {
} cm.evaluate( "cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos())))))))))))))))))))))))))))))))))))");
Assert.fail();
@Test } catch (ParseException e) {
public void testEmptyFunction() throws Exception { }
final MathEngine cm = CalculatorLocatorImpl.getInstance().getEngine().getMathEngine0();
try { final AngleUnit defaultAngleUnit = cm.getAngleUnits();
cm.evaluate( "cos(cos(cos(cos(acos(acos(acos(acos(acos(acos(acos(acos(cos(cos(cos(cos(cosh(acos(cos(cos(cos(cos(cos(acos(acos(acos(acos(acos(acos(acos(acos(cos(cos(cos(cos(cosh(acos(cos())))))))))))))))))))))))))))))))))))))"); try {
Assert.fail(); cm.setAngleUnits(AngleUnit.rad);
} catch (ParseException e) { CalculatorTestUtils.assertEval("0.739", cm.evaluate( "cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(1))))))))))))))))))))))))))))))))))))"));
} } finally {
Assert.assertEquals("0.34+1.382i", cm.evaluate( "ln(ln(ln(ln(ln(ln(ln(ln(ln(ln(ln(ln(ln(ln(ln(100)))))))))))))))")); cm.setAngleUnits(defaultAngleUnit);
try { }
cm.evaluate( "cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos())))))))))))))))))))))))))))))))))))");
Assert.fail(); CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("si", 5d));
} catch (ParseException e) { CalculatorTestUtils.assertEval("5", cm.evaluate( "si"));
}
CalculatorTestUtils.assertError("sin");
final AngleUnit defaultAngleUnit = cm.getAngleUnits(); }
try {
cm.setAngleUnits(AngleUnit.rad); @Test
Assert.assertEquals("0.739", cm.evaluate( "cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(cos(1))))))))))))))))))))))))))))))))))))")); public void testRounding() throws Exception {
} finally { final MathEngine cm = CalculatorLocatorImpl.getInstance().getEngine().getMathEngine0();
cm.setAngleUnits(defaultAngleUnit);
} try {
DecimalFormatSymbols decimalGroupSymbols = new DecimalFormatSymbols(Locale.getDefault());
CalculatorLocatorImpl.getInstance().getEngine().getVarsRegistry().add(new Var.Builder("si", 5d)); decimalGroupSymbols.setDecimalSeparator('.');
Assert.assertEquals("5", cm.evaluate( "si")); decimalGroupSymbols.setGroupingSeparator('\'');
cm.setDecimalGroupSymbols(decimalGroupSymbols);
try { cm.setPrecision(2);
cm.evaluate( "sin"); CalculatorTestUtils.assertEval("12'345'678.9", cm.evaluate( "1.23456789E7"));
Assert.fail(); cm.setPrecision(10);
} catch (ParseException e) { CalculatorTestUtils.assertEval("12'345'678.9", cm.evaluate( "1.23456789E7"));
} CalculatorTestUtils.assertEval("123'456'789", cm.evaluate( "1.234567890E8"));
} CalculatorTestUtils.assertEval("1'234'567'890.1", cm.evaluate( "1.2345678901E9"));
} finally {
@Test cm.setPrecision(3);
public void testRounding() throws Exception { DecimalFormatSymbols decimalGroupSymbols = new DecimalFormatSymbols(Locale.getDefault());
final MathEngine cm = CalculatorLocatorImpl.getInstance().getEngine().getMathEngine0(); decimalGroupSymbols.setDecimalSeparator('.');
decimalGroupSymbols.setGroupingSeparator(JsclMathEngine.GROUPING_SEPARATOR_DEFAULT.charAt(0));
try { cm.setDecimalGroupSymbols(decimalGroupSymbols);
DecimalFormatSymbols decimalGroupSymbols = new DecimalFormatSymbols(Locale.getDefault()); }
decimalGroupSymbols.setDecimalSeparator('.'); }
decimalGroupSymbols.setGroupingSeparator('\'');
cm.setDecimalGroupSymbols(decimalGroupSymbols); @Test
cm.setPrecision(2); public void testComparisonFunction() throws Exception {
Assert.assertEquals("12'345'678.9", cm.evaluate( "1.23456789E7")); final MathEngine cm = CalculatorLocatorImpl.getInstance().getEngine().getMathEngine0();
cm.setPrecision(10);
Assert.assertEquals("12'345'678.9", cm.evaluate( "1.23456789E7")); CalculatorTestUtils.assertEval("0", "eq(0, 1)");
Assert.assertEquals("123'456'789", cm.evaluate( "1.234567890E8")); CalculatorTestUtils.assertEval("1", "eq(1, 1)");
Assert.assertEquals("1'234'567'890.1", cm.evaluate( "1.2345678901E9")); CalculatorTestUtils.assertEval("1", "eq(1, 1.0)");
} finally { CalculatorTestUtils.assertEval("0", "eq(1, 1.000000000000001)");
cm.setPrecision(3); CalculatorTestUtils.assertEval("0", "eq(1, 0)");
DecimalFormatSymbols decimalGroupSymbols = new DecimalFormatSymbols(Locale.getDefault());
decimalGroupSymbols.setDecimalSeparator('.'); CalculatorTestUtils.assertEval("1", "lt(0, 1)");
decimalGroupSymbols.setGroupingSeparator(JsclMathEngine.GROUPING_SEPARATOR_DEFAULT.charAt(0)); CalculatorTestUtils.assertEval("0", "lt(1, 1)");
cm.setDecimalGroupSymbols(decimalGroupSymbols); CalculatorTestUtils.assertEval("0", "lt(1, 0)");
}
} CalculatorTestUtils.assertEval("0", "gt(0, 1)");
CalculatorTestUtils.assertEval("0", "gt(1, 1)");
@Test CalculatorTestUtils.assertEval("1", "gt(1, 0)");
public void testComparisonFunction() throws Exception {
final MathEngine cm = CalculatorLocatorImpl.getInstance().getEngine().getMathEngine0(); CalculatorTestUtils.assertEval("1", "ne(0, 1)");
CalculatorTestUtils.assertEval("0", "ne(1, 1)");
Assert.assertEquals("0", cm.evaluate( "eq(0, 1)")); CalculatorTestUtils.assertEval("1", "ne(1, 0)");
Assert.assertEquals("1", cm.evaluate( "eq(1, 1)"));
Assert.assertEquals("1", cm.evaluate( "eq(1, 1.0)")); CalculatorTestUtils.assertEval("1", "le(0, 1)");
Assert.assertEquals("0", cm.evaluate( "eq(1, 1.000000000000001)")); CalculatorTestUtils.assertEval("1", "le(1, 1)");
Assert.assertEquals("0", cm.evaluate( "eq(1, 0)")); CalculatorTestUtils.assertEval("0", "le(1, 0)");
Assert.assertEquals("1", cm.evaluate( "lt(0, 1)")); CalculatorTestUtils.assertEval("0", "ge(0, 1)");
Assert.assertEquals("0", cm.evaluate( "lt(1, 1)")); CalculatorTestUtils.assertEval("1", "ge(1, 1)");
Assert.assertEquals("0", cm.evaluate( "lt(1, 0)")); CalculatorTestUtils.assertEval("1", "ge(1, 0)");
Assert.assertEquals("0", cm.evaluate( "gt(0, 1)")); CalculatorTestUtils.assertEval("0", "ap(0, 1)");
Assert.assertEquals("0", cm.evaluate( "gt(1, 1)")); CalculatorTestUtils.assertEval("1", "ap(1, 1)");
Assert.assertEquals("1", cm.evaluate( "gt(1, 0)")); CalculatorTestUtils.assertEval("0", "ap(1, 0)");
Assert.assertEquals("1", cm.evaluate( "ne(0, 1)")); }
Assert.assertEquals("0", cm.evaluate( "ne(1, 1)"));
Assert.assertEquals("1", cm.evaluate( "ne(1, 0)"));
@Test
Assert.assertEquals("1", cm.evaluate( "le(0, 1)")); public void testNumeralSystems() throws Exception {
Assert.assertEquals("1", cm.evaluate( "le(1, 1)")); final MathEngine cm = CalculatorLocatorImpl.getInstance().getEngine().getMathEngine0();
Assert.assertEquals("0", cm.evaluate( "le(1, 0)"));
CalculatorTestUtils.assertEval("11 259 375", "0x:ABCDEF");
Assert.assertEquals("0", cm.evaluate( "ge(0, 1)")); CalculatorTestUtils.assertEval("30 606 154.462", "0x:ABCDEF*e");
Assert.assertEquals("1", cm.evaluate( "ge(1, 1)")); CalculatorTestUtils.assertEval("30 606 154.462", "e*0x:ABCDEF");
Assert.assertEquals("1", cm.evaluate( "ge(1, 0)")); CalculatorTestUtils.assertEval("e", "e*0x:ABCDEF/0x:ABCDEF");
CalculatorTestUtils.assertEval("30 606 154.462", "0x:ABCDEF*e*0x:ABCDEF/0x:ABCDEF");
Assert.assertEquals("0", cm.evaluate( "ap(0, 1)")); CalculatorTestUtils.assertEval("30 606 154.462", "c+0x:ABCDEF*e*0x:ABCDEF/0x:ABCDEF-c+0x:C-0x:C");
Assert.assertEquals("1", cm.evaluate( "ap(1, 1)")); CalculatorTestUtils.assertEval("1 446 257 064 651.832", "28*28 * sin(28) - 0b:1101 + √(28) + exp ( 28) ");
//Assert.assertEquals("1", cm.evaluate( "ap(1, 1.000000000000001)").getResult()); CalculatorTestUtils.assertEval("13", "0b:1101");
Assert.assertEquals("0", cm.evaluate( "ap(1, 0)"));
CalculatorTestUtils.assertError("0b:π");
}
final NumeralBase defaultNumeralBase = cm.getNumeralBase();
try{
@Test cm.setNumeralBase(NumeralBase.bin);
public void testNumeralSystems() throws Exception { CalculatorTestUtils.assertEval("101", "10+11");
final MathEngine cm = CalculatorLocatorImpl.getInstance().getEngine().getMathEngine0(); CalculatorTestUtils.assertEval("10/11", "10/11");
Assert.assertEquals("11 259 375", cm.evaluate( "0x:ABCDEF")); cm.setNumeralBase(NumeralBase.hex);
Assert.assertEquals("30 606 154.462", cm.evaluate( "0x:ABCDEF*e")); CalculatorTestUtils.assertEval("63 7B", "56CE+CAD");
Assert.assertEquals("30 606 154.462", cm.evaluate( "e*0x:ABCDEF")); CalculatorTestUtils.assertEval("E", "E");
Assert.assertEquals("e", cm.evaluate( "e*0x:ABCDEF/0x:ABCDEF")); } finally {
Assert.assertEquals("30 606 154.462", cm.evaluate( "0x:ABCDEF*e*0x:ABCDEF/0x:ABCDEF")); cm.setNumeralBase(defaultNumeralBase);
Assert.assertEquals("30 606 154.462", cm.evaluate( "c+0x:ABCDEF*e*0x:ABCDEF/0x:ABCDEF-c+0x:C-0x:C")); }
Assert.assertEquals("1 446 257 064 651.832", cm.evaluate( "28*28 * sin(28) - 0b:1101 + √(28) + exp ( 28) ")); }
Assert.assertEquals("13", cm.evaluate( "0b:1101"));
@Test
try { public void testLog() throws Exception {
cm.evaluate( "0b:π"); final MathEngine cm = CalculatorLocatorImpl.getInstance().getEngine().getMathEngine0();
Assert.fail();
} catch (ParseException e) { CalculatorTestUtils.assertEval("", Expression.valueOf("1/0").numeric().toString());
// ok CalculatorTestUtils.assertEval("", Expression.valueOf("ln(10)/ln(1)").numeric().toString());
}
// logarithm
final NumeralBase defaultNumeralBase = cm.getNumeralBase(); CalculatorTestUtils.assertEval("ln(x)/ln(base)", ((CustomFunction) cm.getFunctionsRegistry().get("log")).getContent());
try{ CalculatorTestUtils.assertEval("", "log(1, 10)");
cm.setNumeralBase(NumeralBase.bin); CalculatorTestUtils.assertEval("3.322", "log(2, 10)");
Assert.assertEquals("101", cm.evaluate( "10+11")); CalculatorTestUtils.assertEval("1.431", "log(5, 10)");
Assert.assertEquals("10/11", cm.evaluate( "10/11")); CalculatorTestUtils.assertEval("0.96", "log(11, 10)");
CalculatorTestUtils.assertEval("1/(bln(a))", "∂(log(a, b), b)", JsclOperation.simplify);
cm.setNumeralBase(NumeralBase.hex); CalculatorTestUtils.assertEval("-ln(b)/(aln(a)^2)", "∂(log(a, b), a)", JsclOperation.simplify);
Assert.assertEquals("63 7B", cm.evaluate( "56CE+CAD"));
Assert.assertEquals("E", cm.evaluate( "E")); }
} finally { }
cm.setNumeralBase(defaultNumeralBase);
}
}
@Test
public void testLog() throws Exception {
final MathEngine cm = CalculatorLocatorImpl.getInstance().getEngine().getMathEngine0();
Assert.assertEquals("", Expression.valueOf("1/0").numeric().toString());
Assert.assertEquals("", Expression.valueOf("ln(10)/ln(1)").numeric().toString());
// logarithm
Assert.assertEquals("ln(x)/ln(base)", ((CustomFunction) cm.getFunctionsRegistry().get("log")).getContent());
Assert.assertEquals("", cm.evaluate( "log(1, 10)"));
Assert.assertEquals("3.322", cm.evaluate( "log(2, 10)"));
Assert.assertEquals("1.431", cm.evaluate( "log(5, 10)"));
Assert.assertEquals("0.96", cm.evaluate( "log(11, 10)"));
Assert.assertEquals("1/(bln(a))", cm.simplify( "∂(log(a, b), b)"));
Assert.assertEquals("-ln(b)/(aln(a)^2)", cm.simplify( "∂(log(a, b), a)"));
}
}

View File

@ -1,56 +1,105 @@
-target 1.6 -target 1.6
-dontusemixedcaseclassnames -dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses -dontskipnonpubliclibraryclasses
-dontpreverify -dontpreverify
-repackageclasses '' -repackageclasses ''
-allowaccessmodification -allowaccessmodification
-optimizations !code/simplification/arithmetic -optimizations !code/simplification/arithmetic
-keepattributes *Annotation* -keepattributes *Annotation*
-keep public class * extends android.app.Activity -keep public class * extends android.app.Activity
-keep public class * extends android.app.Application -keep public class * extends android.app.Application
-keep public class * extends android.app.Service -keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver -keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider -keep public class * extends android.content.ContentProvider
-keep public class * extends android.view.View { -keep public class * extends android.view.View {
public <init>(android.content.Context); public <init>(android.content.Context);
public <init>(android.content.Context, android.util.AttributeSet); public <init>(android.content.Context, android.util.AttributeSet);
public <init>(android.content.Context, android.util.AttributeSet, int); public <init>(android.content.Context, android.util.AttributeSet, int);
public void set*(...); public void set*(...);
} }
-keepclasseswithmembers class * { -keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet); public <init>(android.content.Context, android.util.AttributeSet);
} }
-keepclasseswithmembers class * { -keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet, int); public <init>(android.content.Context, android.util.AttributeSet, int);
} }
-keepclassmembers class * extends android.content.Context { -keepclassmembers class * extends android.content.Context {
public void *(android.view.View); public void *(android.view.View);
public void *(android.view.MenuItem); public void *(android.view.MenuItem);
} }
-keepclassmembers class * implements android.os.Parcelable { -keepclassmembers class * implements android.os.Parcelable {
static android.os.Parcelable$Creator CREATOR; static android.os.Parcelable$Creator CREATOR;
} }
-keepclassmembers class **.R$* { -keepclassmembers class **.R$* {
public static <fields>; public static <fields>;
} }
-keepclassmembers enum * { -keepclassmembers enum * {
public static **[] values(); public static **[] values();
public static ** valueOf(java.lang.String); public static ** valueOf(java.lang.String);
} }
-dontwarn javax.xml.stream.** -keep @org.simpleframework.xml.Root public class * {
-dontwarn com.bea.xml.stream.** *;
-dontwarn sun.misc.Unsafe }
-dontwarn android.annotation.TargetApi
-dontwarn javax.xml.stream.**
-keep class org.simpleframework.xml.** { *; } -dontwarn com.bea.xml.stream.**
-keep class com.actionbarsherlock.** { *; } -dontwarn sun.misc.Unsafe
-keep class * implements org.solovyev.android.calculator.model.MathPersistenceEntity -dontwarn android.annotation.TargetApi
-dontwarn org.solovyev.common.math.visualisation.**
-dontwarn org.solovyev.common.math.graph.**
-dontwarn org.solovyev.common.math.algorithms.**
-dontwarn org.solovyev.common.drawing.**
-dontwarn org.joda.**
-dontwarn jscl.mathml.**
-dontwarn com.google.common.collect.MinMaxPriorityQueue
-keep class org.simpleframework.xml.** { *; }
-keep class com.actionbarsherlock.** { *; }
-keep class * implements org.solovyev.android.calculator.model.MathPersistenceEntity
#
#*********************************************************************
#
# ACRA
#
#*********************************************************************
#
# we need line numbers in our stack traces otherwise they are pretty useless
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable
# ACRA needs "annotations" so add this...
-keepattributes *Annotation*
# keep this class so that logging will show 'ACRA' and not a obfuscated name like 'a'.
# Note: if you are removing log messages elsewhere in this file then this isn't necessary
-keep class org.acra.ACRA {
*;
}
# keep this around for some enums that ACRA needs
-keep class org.acra.ReportingInteractionMode {
*;
}
# keep this otherwise it is removed by ProGuard
-keep public class org.acra.ErrorReporter
{
public void addCustomData(java.lang.String,java.lang.String);
}
# keep this otherwise it is removed by ProGuard
-keep public class org.acra.ErrorReporter
{
public org.acra.ErrorReporter$ReportsSenderWorker handleSilentException(java.lang.Throwable);
}

View File

@ -1,95 +1,99 @@
package org.solovyev.android.calculator.model; package org.solovyev.android.calculator.model;
import android.app.Application; import android.app.Application;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.Resources; import android.content.res.Resources;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.simpleframework.xml.Serializer; import org.simpleframework.xml.Serializer;
import org.simpleframework.xml.core.Persister; import org.simpleframework.xml.core.Persister;
import org.solovyev.android.calculator.MathEntityDao; import org.solovyev.android.calculator.CalculatorApplication;
import org.solovyev.android.calculator.MathEntityPersistenceContainer; import org.solovyev.android.calculator.MathEntityDao;
import org.solovyev.android.calculator.MathPersistenceEntity; import org.solovyev.android.calculator.MathEntityPersistenceContainer;
import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.MathPersistenceEntity;
import java.io.StringWriter; import java.io.StringWriter;
/** /**
* User: serso * User: serso
* Date: 10/7/12 * Date: 10/7/12
* Time: 6:46 PM * Time: 6:46 PM
*/ */
public class AndroidMathEntityDao<T extends MathPersistenceEntity> implements MathEntityDao<T> { public class AndroidMathEntityDao<T extends MathPersistenceEntity> implements MathEntityDao<T> {
@Nullable @NotNull
private final Integer preferenceStringId; private static final String TAG = AndroidMathEntityDao.class.getSimpleName();
@NotNull @Nullable
private final Context context; private final Integer preferenceStringId;
@Nullable @NotNull
private final Class<? extends MathEntityPersistenceContainer<T>> persistenceContainerClass; private final Context context;
public AndroidMathEntityDao(@Nullable Integer preferenceStringId, @Nullable
@NotNull Application application, private final Class<? extends MathEntityPersistenceContainer<T>> persistenceContainerClass;
@Nullable Class<? extends MathEntityPersistenceContainer<T>> persistenceContainerClass) {
this.preferenceStringId = preferenceStringId; public AndroidMathEntityDao(@Nullable Integer preferenceStringId,
this.context = application; @NotNull Application application,
this.persistenceContainerClass = persistenceContainerClass; @Nullable Class<? extends MathEntityPersistenceContainer<T>> persistenceContainerClass) {
} this.preferenceStringId = preferenceStringId;
this.context = application;
@Override this.persistenceContainerClass = persistenceContainerClass;
public void save(@NotNull MathEntityPersistenceContainer<T> container) { }
if (preferenceStringId != null) {
final SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context); @Override
final SharedPreferences.Editor editor = settings.edit(); public void save(@NotNull MathEntityPersistenceContainer<T> container) {
if (preferenceStringId != null) {
final StringWriter sw = new StringWriter(); final SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
final Serializer serializer = new Persister(); final SharedPreferences.Editor editor = settings.edit();
try {
serializer.write(container, sw); final StringWriter sw = new StringWriter();
} catch (Exception e) { final Serializer serializer = new Persister();
throw new RuntimeException(e); try {
} serializer.write(container, sw);
} catch (Exception e) {
editor.putString(context.getString(preferenceStringId), sw.toString()); throw new RuntimeException(e);
}
editor.commit();
} editor.putString(context.getString(preferenceStringId), sw.toString());
}
editor.commit();
@Nullable }
@Override }
public MathEntityPersistenceContainer<T> load() {
if (persistenceContainerClass != null && preferenceStringId != null) { @Nullable
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); @Override
public MathEntityPersistenceContainer<T> load() {
if (preferences != null) { if (persistenceContainerClass != null && preferenceStringId != null) {
final String value = preferences.getString(context.getString(preferenceStringId), null); final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
if (value != null) {
final Serializer serializer = new Persister(); if (preferences != null) {
try { final String value = preferences.getString(context.getString(preferenceStringId), null);
return serializer.read(persistenceContainerClass, value); if (value != null) {
} catch (Exception e) { final Serializer serializer = new Persister();
throw new RuntimeException(e); try {
} return serializer.read(persistenceContainerClass, value);
} } catch (Exception e) {
} throw new RuntimeException(e);
} }
}
return null; }
} }
@Nullable return null;
public String getDescription(@NotNull String descriptionId) { }
final Resources resources = context.getResources();
final int stringId = resources.getIdentifier(descriptionId, "string", R.class.getPackage().getName()); @Nullable
try { public String getDescription(@NotNull String descriptionId) {
return resources.getString(stringId); final Resources resources = context.getResources();
} catch (Resources.NotFoundException e) {
return null; final int stringId = resources.getIdentifier(descriptionId, "string", CalculatorApplication.class.getPackage().getName());
} try {
} return resources.getString(stringId);
} } catch (Resources.NotFoundException e) {
return null;
}
}
}

553
pom.xml
View File

@ -1,275 +1,280 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" <project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>org.solovyev.android</groupId> <groupId>org.solovyev.android</groupId>
<artifactId>calculatorpp-parent</artifactId> <artifactId>calculatorpp-parent</artifactId>
<packaging>pom</packaging> <packaging>pom</packaging>
<version>1.3.2</version> <version>1.3.2</version>
<name>Calculator++</name> <name>Calculator++</name>
<modules> <modules>
<module>calculatorpp</module> <module>calculatorpp</module>
<module>calculatorpp-test</module> <module>calculatorpp-test</module>
<module>calculatorpp-core</module> <module>calculatorpp-core</module>
</modules> </modules>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> </properties>
<dependencyManagement> <dependencyManagement>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.solovyev</groupId> <groupId>org.solovyev</groupId>
<artifactId>common-core</artifactId> <artifactId>common-core</artifactId>
<version>1.0.0</version> <version>1.0.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.solovyev</groupId> <groupId>org.solovyev</groupId>
<artifactId>common-text</artifactId> <artifactId>common-text</artifactId>
<version>1.0.1</version> <version>1.0.1</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.solovyev.android</groupId> <groupId>org.solovyev.android</groupId>
<artifactId>android-common-core</artifactId> <artifactId>android-common-core</artifactId>
<type>apklib</type> <type>apklib</type>
<version>1.0.0</version> <version>1.0.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.solovyev.android</groupId> <groupId>org.solovyev.android</groupId>
<artifactId>android-common-ads</artifactId> <artifactId>android-common-ads</artifactId>
<type>apklib</type> <type>apklib</type>
<version>1.0.0</version> <version>1.0.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.solovyev.android</groupId> <groupId>org.solovyev.android</groupId>
<artifactId>android-common-view</artifactId> <artifactId>android-common-view</artifactId>
<type>apklib</type> <type>apklib</type>
<version>1.0.0</version> <version>1.0.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.solovyev.android</groupId> <groupId>org.solovyev.android</groupId>
<artifactId>android-common-preferences</artifactId> <artifactId>android-common-preferences</artifactId>
<type>apklib</type> <type>apklib</type>
<version>1.0.0</version> <version>1.0.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.solovyev.android</groupId> <groupId>org.solovyev.android</groupId>
<artifactId>android-common-menu</artifactId> <artifactId>android-common-menu</artifactId>
<type>apklib</type> <type>apklib</type>
<version>1.0.0</version> <version>1.0.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.solovyev.android</groupId> <groupId>org.solovyev.android</groupId>
<artifactId>android-common-sherlock</artifactId> <artifactId>android-common-sherlock</artifactId>
<version>1.0.0</version> <version>1.0.0</version>
<type>apklib</type> <type>apklib</type>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.actionbarsherlock</groupId> <groupId>com.actionbarsherlock</groupId>
<artifactId>library</artifactId> <artifactId>library</artifactId>
<version>4.1.0</version> <version>4.1.0</version>
<type>apklib</type> <type>apklib</type>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.solovyev</groupId> <groupId>org.solovyev</groupId>
<artifactId>jscl</artifactId> <artifactId>jscl</artifactId>
<version>0.0.3</version> <version>0.0.3</version>
<exclusions> <exclusions>
<exclusion> <exclusion>
<artifactId>xercesImpl</artifactId> <artifactId>xercesImpl</artifactId>
<groupId>xerces</groupId> <groupId>xerces</groupId>
</exclusion> </exclusion>
</exclusions>
</dependency> <exclusion>
<groupId>jgraphx</groupId>
<dependency> <artifactId>jgraphx</artifactId>
<groupId>org.solovyev.android</groupId> </exclusion>
<artifactId>android-common-other</artifactId> </exclusions>
<type>apklib</type> </dependency>
<version>1.0.0</version>
</dependency> <dependency>
<groupId>org.solovyev.android</groupId>
<dependency> <artifactId>android-common-other</artifactId>
<groupId>junit</groupId> <type>apklib</type>
<artifactId>junit</artifactId> <version>1.0.0</version>
<version>4.8.2</version> </dependency>
</dependency>
<dependency>
<dependency> <groupId>junit</groupId>
<groupId>com.intellij</groupId> <artifactId>junit</artifactId>
<artifactId>annotations</artifactId> <version>4.8.2</version>
<version>7.0.3</version> </dependency>
</dependency>
<dependency>
<dependency> <groupId>com.intellij</groupId>
<groupId>com.google.android</groupId> <artifactId>annotations</artifactId>
<artifactId>android</artifactId> <version>7.0.3</version>
<version>4.0.1.2</version> </dependency>
<scope>provided</scope>
</dependency> <dependency>
<groupId>com.google.android</groupId>
<dependency> <artifactId>android</artifactId>
<groupId>com.google.android</groupId> <version>4.0.1.2</version>
<artifactId>support-v4</artifactId> <scope>provided</scope>
<version>r7</version> </dependency>
</dependency>
<dependency>
<dependency> <groupId>com.google.android</groupId>
<groupId>com.google.android</groupId> <artifactId>support-v4</artifactId>
<artifactId>android-test</artifactId> <version>r7</version>
<version>2.3.1</version> </dependency>
</dependency>
<dependency>
<dependency> <groupId>com.google.android</groupId>
<groupId>com.google.guava</groupId> <artifactId>android-test</artifactId>
<artifactId>guava</artifactId> <version>2.3.1</version>
<version>11.0.2</version> </dependency>
</dependency>
<dependency>
<dependency> <groupId>com.google.guava</groupId>
<groupId>org.simpleframework</groupId> <artifactId>guava</artifactId>
<artifactId>simple-xml</artifactId> <version>11.0.2</version>
<version>2.6.1</version> </dependency>
<exclusions>
<exclusion> <dependency>
<artifactId>stax-api</artifactId> <groupId>org.simpleframework</groupId>
<groupId>stax</groupId> <artifactId>simple-xml</artifactId>
</exclusion> <version>2.6.1</version>
<exclusion> <exclusions>
<artifactId>xpp3</artifactId> <exclusion>
<groupId>xpp3</groupId> <artifactId>stax-api</artifactId>
</exclusion> <groupId>stax</groupId>
</exclusions> </exclusion>
</dependency> <exclusion>
<artifactId>xpp3</artifactId>
</dependencies> <groupId>xpp3</groupId>
</dependencyManagement> </exclusion>
</exclusions>
<build> </dependency>
<plugins> </dependencies>
</dependencyManagement>
<plugin>
<groupId>com.electriccloud</groupId> <build>
<artifactId>javac2-maven-plugin</artifactId>
<version>1.0.1</version> <plugins>
<executions>
<execution> <plugin>
<id>@NotNull Instrumentation</id> <groupId>com.electriccloud</groupId>
<goals> <artifactId>javac2-maven-plugin</artifactId>
<goal>instrument</goal> <version>1.0.1</version>
</goals> <executions>
<!--compile phase instead of process-classes because of proguard. <execution>
@NotNull instrumentation will be done now after compilation and before proguard--> <id>@NotNull Instrumentation</id>
<phase>compile</phase> <goals>
</execution> <goal>instrument</goal>
</executions> </goals>
</plugin> <!--compile phase instead of process-classes because of proguard.
@NotNull instrumentation will be done now after compilation and before proguard-->
<!-- as some classes are singletons we must run each test in separate JVM--> <phase>compile</phase>
<plugin> </execution>
<groupId>org.apache.maven.plugins</groupId> </executions>
<artifactId>maven-surefire-plugin</artifactId> </plugin>
<version>2.12.3</version>
<configuration> <!-- as some classes are singletons we must run each test in separate JVM-->
<forkMode>perTest</forkMode> <plugin>
</configuration> <groupId>org.apache.maven.plugins</groupId>
</plugin> <artifactId>maven-surefire-plugin</artifactId>
<version>2.12.3</version>
</plugins> <configuration>
<forkMode>perTest</forkMode>
<pluginManagement> </configuration>
<plugins> </plugin>
<plugin> </plugins>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jarsigner-plugin</artifactId> <pluginManagement>
<version>1.2</version> <plugins>
</plugin>
<plugin>
<plugin> <groupId>org.apache.maven.plugins</groupId>
<groupId>com.jayway.maven.plugins.android.generation2</groupId> <artifactId>maven-jarsigner-plugin</artifactId>
<artifactId>android-maven-plugin</artifactId> <version>1.2</version>
<version>3.1.1</version> </plugin>
<configuration>
<plugin>
<sourceDirectories> <groupId>com.jayway.maven.plugins.android.generation2</groupId>
<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory> <artifactId>android-maven-plugin</artifactId>
</sourceDirectories> <version>3.1.1</version>
<configuration>
<sdk>
<platform>15</platform> <sourceDirectories>
</sdk> <sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
</sourceDirectories>
<emulator>
<avd>23</avd> <sdk>
<wait>10000</wait> <platform>15</platform>
<!--<options>-no-skin</options>--> </sdk>
</emulator>
<emulator>
<zipalign> <avd>23</avd>
<verbose>true</verbose> <wait>10000</wait>
</zipalign> <!--<options>-no-skin</options>-->
</emulator>
<undeployBeforeDeploy>true</undeployBeforeDeploy>
<zipalign>
</configuration> <verbose>true</verbose>
</zipalign>
</plugin>
<undeployBeforeDeploy>true</undeployBeforeDeploy>
<plugin>
<groupId>com.pyx4me</groupId> </configuration>
<artifactId>proguard-maven-plugin</artifactId>
<version>2.0.4</version> </plugin>
</plugin>
<plugin>
<plugin> <groupId>com.pyx4me</groupId>
<groupId>org.codehaus.mojo</groupId> <artifactId>proguard-maven-plugin</artifactId>
<artifactId>build-helper-maven-plugin</artifactId> <version>2.0.4</version>
<version>1.5</version> </plugin>
</plugin>
<plugin>
</plugins> <groupId>org.codehaus.mojo</groupId>
</pluginManagement> <artifactId>build-helper-maven-plugin</artifactId>
<version>1.5</version>
</build> </plugin>
<profiles> </plugins>
</pluginManagement>
<profile>
<!-- the standard profile runs instrumentation tests --> </build>
<id>standard</id>
</profile> <profiles>
<profile> <profile>
<!-- the release profile does sign, proguard, zipalign --> <!-- the standard profile runs instrumentation tests -->
<id>release</id> <id>standard</id>
<!-- via this activation the profile is automatically used when the release is done with the maven release </profile>
plugin -->
<activation> <profile>
<property> <!-- the release profile does sign, proguard, zipalign -->
<name>performRelease</name> <id>release</id>
<value>true</value> <!-- via this activation the profile is automatically used when the release is done with the maven release
</property> plugin -->
</activation> <activation>
<property>
</profile> <name>performRelease</name>
</profiles> <value>true</value>
</property>
</activation>
</profile>
</profiles>
</project> </project>