Display refactored
This commit is contained in:
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013 serso aka se.solovyev
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
* Contact details
|
||||
*
|
||||
* Email: se.solovyev@gmail.com
|
||||
* Site: http://se.solovyev.org
|
||||
*/
|
||||
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.solovyev.android.calculator.jscl.JsclOperation;
|
||||
|
||||
import jscl.math.Expression;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 10/20/12
|
||||
* Time: 12:24 PM
|
||||
*/
|
||||
public class CalculatorDisplayViewStateImplTest {
|
||||
|
||||
@Test
|
||||
public void testSerializable() throws Exception {
|
||||
CalculatorTestUtils.testSerialization(DisplayState.createValid(JsclOperation.numeric, null, "test", 3));
|
||||
CalculatorTestUtils.testSerialization(DisplayState.createValid(JsclOperation.numeric, Expression.valueOf("3"), "test", 3));
|
||||
CalculatorTestUtils.testSerialization(DisplayState.createValid(JsclOperation.simplify, Expression.valueOf("3+3"), "test", 3));
|
||||
CalculatorTestUtils.testSerialization(DisplayState.empty());
|
||||
CalculatorTestUtils.testSerialization(DisplayState.createError(JsclOperation.numeric, "ertert"));
|
||||
}
|
||||
|
||||
}
|
@@ -23,28 +23,20 @@
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import jscl.JsclMathEngine;
|
||||
import org.junit.Assert;
|
||||
import org.mockito.Mockito;
|
||||
import org.solovyev.android.calculator.history.CalculatorHistory;
|
||||
import org.solovyev.android.calculator.jscl.JsclOperation;
|
||||
import org.solovyev.android.calculator.plot.CalculatorPlotter;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.Serializable;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.*;
|
||||
import java.text.DecimalFormatSymbols;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import jscl.JsclMathEngine;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 10/7/12
|
||||
@@ -75,12 +67,8 @@ public class CalculatorTestUtils {
|
||||
}
|
||||
|
||||
public static void initViews(@Nonnull Context context) {
|
||||
final EditorView editor = new EditorView(context);
|
||||
Locator.getInstance().getEditor().setView(editor);
|
||||
|
||||
final AndroidCalculatorDisplayView display = new AndroidCalculatorDisplayView(context);
|
||||
display.init(context);
|
||||
Locator.getInstance().getDisplay().setView(display);
|
||||
Locator.getInstance().getEditor().setView(new EditorView(context));
|
||||
Locator.getInstance().getDisplay().setView(new DisplayView(context));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@@ -104,7 +92,7 @@ public class CalculatorTestUtils {
|
||||
public static void assertEval(@Nonnull String expected, @Nonnull String expression, @Nonnull JsclOperation operation) {
|
||||
final Calculator calculator = Locator.getInstance().getCalculator();
|
||||
|
||||
Locator.getInstance().getDisplay().setViewState(DisplayState.empty());
|
||||
Locator.getInstance().getDisplay().setState(DisplayState.empty());
|
||||
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
final TestCalculatorEventListener calculatorEventListener = new TestCalculatorEventListener(latch);
|
||||
@@ -160,7 +148,7 @@ public class CalculatorTestUtils {
|
||||
public static void assertError(@Nonnull String expression, @Nonnull JsclOperation operation) {
|
||||
final Calculator calculator = Locator.getInstance().getCalculator();
|
||||
|
||||
Locator.getInstance().getDisplay().setViewState(DisplayState.empty());
|
||||
Locator.getInstance().getDisplay().setState(DisplayState.empty());
|
||||
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
final TestCalculatorEventListener calculatorEventListener = new TestCalculatorEventListener(latch);
|
||||
@@ -204,10 +192,10 @@ public class CalculatorTestUtils {
|
||||
waitForEventData();
|
||||
|
||||
if (calculatorEventData.isSameSequence(this.calculatorEventData)) {
|
||||
if (calculatorEventType == CalculatorEventType.display_state_changed) {
|
||||
final CalculatorDisplayChangeEventData displayChange = (CalculatorDisplayChangeEventData) data;
|
||||
/*if (calculatorEventType == CalculatorEventType.display_state_changed) {
|
||||
final Display.ChangedEvent displayChange = (Display.ChangedEvent) data;
|
||||
|
||||
result = displayChange.getNewValue();
|
||||
result = displayChange.newState;
|
||||
|
||||
try {
|
||||
// need to sleep a little bit as await
|
||||
@@ -215,7 +203,7 @@ public class CalculatorTestUtils {
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
latch.countDown();
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -137,7 +137,7 @@ public class HistoryUtilsTest {
|
||||
|
||||
HistoryHelper<HistoryState> history = SimpleHistoryHelper.newInstance();
|
||||
|
||||
DisplayState calculatorDisplay = DisplayState.createError(JsclOperation.simplify, "Error");
|
||||
DisplayState calculatorDisplay = DisplayState.createError(JsclOperation.simplify, "Error", EditorState.NO_SEQUENCE);
|
||||
|
||||
EditorState calculatorEditor = EditorState.create("1+1", 3);
|
||||
|
||||
@@ -152,7 +152,7 @@ public class HistoryUtilsTest {
|
||||
|
||||
assertEquals(toXml1, createHistory(history).toXml());
|
||||
|
||||
calculatorDisplay = DisplayState.createValid(JsclOperation.numeric, null, "5/6", 3);
|
||||
calculatorDisplay = DisplayState.createValid(JsclOperation.numeric, null, "5/6", 3, EditorState.NO_SEQUENCE);
|
||||
|
||||
calculatorEditor = EditorState.create("5/6", 2);
|
||||
|
||||
@@ -161,7 +161,7 @@ public class HistoryUtilsTest {
|
||||
state.setTime(date.getTime());
|
||||
history.addState(state);
|
||||
|
||||
calculatorDisplay = DisplayState.createError(JsclOperation.elementary, "Error");
|
||||
calculatorDisplay = DisplayState.createError(JsclOperation.elementary, "Error", EditorState.NO_SEQUENCE);
|
||||
|
||||
calculatorEditor = EditorState.create("", 1);
|
||||
|
||||
@@ -170,7 +170,7 @@ public class HistoryUtilsTest {
|
||||
state.setTime(date.getTime());
|
||||
history.addState(state);
|
||||
|
||||
calculatorDisplay = DisplayState.createValid(JsclOperation.numeric, null, "4+5/35sin(41)+dfdsfsdfs", 1);
|
||||
calculatorDisplay = DisplayState.createValid(JsclOperation.numeric, null, "4+5/35sin(41)+dfdsfsdfs", 1, EditorState.NO_SEQUENCE);
|
||||
|
||||
calculatorEditor = EditorState.create("4+5/35sin(41)+dfdsfsdfs", 0);
|
||||
|
||||
|
Reference in New Issue
Block a user