Test modules
This commit is contained in:
@@ -83,12 +83,14 @@
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="Maven Android API 17 Platform" jdkType="Android SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" exported="" name="acra-4.3.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="android-common-db-1.1.18" level="project" />
|
||||
<orderEntry type="library" exported="" name="support-v4-21.0.3" level="project" />
|
||||
<orderEntry type="library" exported="" name="common-security-1.0.7" level="project" />
|
||||
<orderEntry type="library" exported="" name="admob-6.4.1-r11.0.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="acra-4.5.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="android-common-core-1.1.18" level="project" />
|
||||
<orderEntry type="library" exported="" name="android-common-billing-1.1.18" level="project" />
|
||||
<orderEntry type="library" exported="" name="android-common-security-1.1.18" level="project" />
|
||||
<orderEntry type="library" exported="" name="annotations-2.0.1" level="project" />
|
||||
<orderEntry type="library" exported="" name="android-common-other-1.1.18" level="project" />
|
||||
<orderEntry type="library" exported="" name="android-common-wizard-1.1.18" level="project" />
|
||||
|
@@ -40,12 +40,15 @@ android {
|
||||
zipAlignEnabled true
|
||||
}
|
||||
}
|
||||
lintOptions {
|
||||
abortOnError false
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile fileTree(dir: 'libs', include: ['*.jar'])
|
||||
compile 'com.android.support:support-v4:21.0.3'
|
||||
compile ('ch.acra:acra:4.3.0') {
|
||||
compile ('ch.acra:acra:4.5.0') {
|
||||
exclude group: 'org.json'
|
||||
}
|
||||
compile 'org.solovyev.android:android-common-ads:1.1.18@aar'
|
||||
@@ -56,6 +59,7 @@ dependencies {
|
||||
compile 'org.solovyev.android:android-common-core:1.1.18@aar'
|
||||
compile 'org.solovyev.android:android-common-other:1.1.18@aar'
|
||||
compile 'org.solovyev.android:android-common-db:1.1.18@aar'
|
||||
compile 'org.solovyev.android:android-common-security:1.1.18@aar'
|
||||
compile project(':android-app-core')
|
||||
compile project(':android-app-widget')
|
||||
compile project(':android-app-onscreen')
|
||||
|
@@ -62,6 +62,8 @@
|
||||
-dontwarn jscl.mathml.**
|
||||
-dontwarn com.google.common.collect.MinMaxPriorityQueue
|
||||
-dontwarn com.google.ads.**
|
||||
-dontwarn com.sun.org.apache.xerces.internal.impl.dv.util.Base64
|
||||
-dontwarn com.actionbarsherlock.BuildConfig
|
||||
|
||||
-keep class org.simpleframework.xml.** { *; }
|
||||
-keep class * implements org.solovyev.android.calculator.model.MathPersistenceEntity
|
||||
|
@@ -139,7 +139,9 @@ public class CalculatorApplication extends android.app.Application implements Sh
|
||||
public void onCreate() {
|
||||
ACRA.init(this);
|
||||
|
||||
App.init(this);
|
||||
if (!App.isInitialized()) {
|
||||
App.init(this);
|
||||
}
|
||||
|
||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
CalculatorPreferences.setDefaultValues(preferences);
|
||||
|
@@ -26,16 +26,13 @@ import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.solovyev.android.calculator.Calculator;
|
||||
import org.solovyev.android.calculator.CalculatorEventData;
|
||||
import org.solovyev.android.calculator.CalculatorEventType;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.common.history.HistoryAction;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -60,7 +57,7 @@ public class AndroidCalculatorHistory implements CalculatorHistory {
|
||||
public void load() {
|
||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
if (preferences != null) {
|
||||
final String value = preferences.getString(context.getString(R.string.p_calc_history), null);
|
||||
final String value = preferences.getString("org.solovyev.android.calculator.CalculatorModel_history", null);
|
||||
if (value != null) {
|
||||
calculatorHistory.fromXml(value);
|
||||
}
|
||||
@@ -71,7 +68,7 @@ public class AndroidCalculatorHistory implements CalculatorHistory {
|
||||
final SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
final SharedPreferences.Editor editor = settings.edit();
|
||||
|
||||
editor.putString(context.getString(R.string.p_calc_history), calculatorHistory.toXml());
|
||||
editor.putString("org.solovyev.android.calculator.CalculatorModel_history", calculatorHistory.toXml());
|
||||
|
||||
editor.commit();
|
||||
}
|
||||
|
@@ -1,97 +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;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.solovyev.android.calculator.units.CalculatorNumeralBase;
|
||||
import org.solovyev.common.units.Unit;
|
||||
import org.solovyev.common.units.UnitConverter;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Random;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 4/21/12
|
||||
* Time: 8:24 PM
|
||||
*/
|
||||
public class AndroidNumeralBaseTest {
|
||||
|
||||
@Nonnull
|
||||
private final UnitConverter<String> c = CalculatorNumeralBase.getConverter();
|
||||
|
||||
@Test
|
||||
public void testIsSupported() throws Exception {
|
||||
assertTrue(c.isSupported(CalculatorNumeralBase.bin, CalculatorNumeralBase.dec));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertFromDec() throws Exception {
|
||||
|
||||
Assert.assertEquals("101", c.convert(CalculatorNumeralBase.dec.createUnit("5"), CalculatorNumeralBase.bin).getValue());
|
||||
Assert.assertEquals("1", c.convert(CalculatorNumeralBase.dec.createUnit("1"), CalculatorNumeralBase.bin).getValue());
|
||||
Assert.assertEquals("0", c.convert(CalculatorNumeralBase.dec.createUnit("0"), CalculatorNumeralBase.bin).getValue());
|
||||
Assert.assertEquals("1111100111", c.convert(CalculatorNumeralBase.dec.createUnit("999"), CalculatorNumeralBase.bin).getValue());
|
||||
|
||||
Assert.assertEquals("A23", c.convert(CalculatorNumeralBase.dec.createUnit("2595"), CalculatorNumeralBase.hex).getValue());
|
||||
Assert.assertEquals("AEE", c.convert(CalculatorNumeralBase.dec.createUnit("2798"), CalculatorNumeralBase.hex).getValue());
|
||||
Assert.assertEquals("15", c.convert(CalculatorNumeralBase.dec.createUnit("21"), CalculatorNumeralBase.hex).getValue());
|
||||
Assert.assertEquals("0", c.convert(CalculatorNumeralBase.dec.createUnit("0"), CalculatorNumeralBase.hex).getValue());
|
||||
Assert.assertEquals("3E7", c.convert(CalculatorNumeralBase.dec.createUnit("999"), CalculatorNumeralBase.hex).getValue());
|
||||
|
||||
Assert.assertEquals("76", c.convert(CalculatorNumeralBase.dec.createUnit("62"), CalculatorNumeralBase.oct).getValue());
|
||||
Assert.assertEquals("12", c.convert(CalculatorNumeralBase.dec.createUnit("10"), CalculatorNumeralBase.oct).getValue());
|
||||
Assert.assertEquals("15", c.convert(CalculatorNumeralBase.dec.createUnit("13"), CalculatorNumeralBase.oct).getValue());
|
||||
Assert.assertEquals("0", c.convert(CalculatorNumeralBase.dec.createUnit("0"), CalculatorNumeralBase.oct).getValue());
|
||||
Assert.assertEquals("10445", c.convert(CalculatorNumeralBase.dec.createUnit("4389"), CalculatorNumeralBase.oct).getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRandomConvert() throws Exception {
|
||||
final Random random = new Random(new Date().getTime());
|
||||
for (int i = 0; i < 100000; i++) {
|
||||
final String value = String.valueOf(random.nextInt());
|
||||
Assert.assertEquals(value, convertChain(value, CalculatorNumeralBase.dec, CalculatorNumeralBase.oct, CalculatorNumeralBase.oct, CalculatorNumeralBase.bin, CalculatorNumeralBase.dec));
|
||||
Assert.assertEquals(value, convertChain(value, CalculatorNumeralBase.dec, CalculatorNumeralBase.bin, CalculatorNumeralBase.hex, CalculatorNumeralBase.dec, CalculatorNumeralBase.dec));
|
||||
Assert.assertEquals(value, convertChain(value, CalculatorNumeralBase.dec, CalculatorNumeralBase.dec, CalculatorNumeralBase.hex, CalculatorNumeralBase.oct, CalculatorNumeralBase.dec));
|
||||
Assert.assertEquals(value, convertChain(value, CalculatorNumeralBase.dec, CalculatorNumeralBase.hex, CalculatorNumeralBase.bin, CalculatorNumeralBase.oct, CalculatorNumeralBase.dec));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private String convertChain(@Nonnull String value, @Nonnull CalculatorNumeralBase baseAndroid, @Nonnull CalculatorNumeralBase... typeAndroids) {
|
||||
Unit<String> unit = baseAndroid.createUnit(value);
|
||||
|
||||
for (CalculatorNumeralBase typeAndroid : typeAndroids) {
|
||||
unit = CalculatorNumeralBase.getConverter().convert(unit, typeAndroid);
|
||||
}
|
||||
|
||||
return unit.getValue();
|
||||
}
|
||||
}
|
@@ -1,111 +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 java.util.Date;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.solovyev.common.text.Strings;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 10/13/12
|
||||
* Time: 1:11 PM
|
||||
*/
|
||||
@RunWith(value = RobolectricTestRunner.class)
|
||||
public class AndroidCalculatorEditorViewTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void staticSetUp() throws Exception {
|
||||
/*CalculatorTestUtils.staticSetUp(null);*/
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
/* CalculatorActivity context = new CalculatorActivity();
|
||||
CalculatorTestUtils.initViews(context);*/
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreation() throws Exception {
|
||||
new AndroidCalculatorEditorView(CalculatorApplication.getInstance());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAsyncWork() throws Exception {
|
||||
final int threadNum = 10;
|
||||
final int count = 10;
|
||||
final int maxTextLength = 100;
|
||||
|
||||
final Random random = new Random(new Date().getTime());
|
||||
final CountDownLatch startLatchLatch = new CountDownLatch(threadNum);
|
||||
final CountDownLatch finishLatch = new CountDownLatch(threadNum * count);
|
||||
final AtomicBoolean error = new AtomicBoolean(false);
|
||||
|
||||
for (int i = 0; i < threadNum; i++) {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
startLatchLatch.await();
|
||||
} catch (InterruptedException e) {
|
||||
System.out.println(e);
|
||||
error.set(true);
|
||||
for (int j = 0; j < count; j++) {
|
||||
finishLatch.countDown();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
for (int j = 0; j < count; j++) {
|
||||
try {
|
||||
int textLength = random.nextInt(maxTextLength);
|
||||
Locator.getInstance().getEditor().insert(Strings.generateRandomString(textLength), textLength);
|
||||
} catch (Throwable e) {
|
||||
System.out.println(e);
|
||||
error.set(true);
|
||||
} finally {
|
||||
finishLatch.countDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
startLatchLatch.countDown();
|
||||
}
|
||||
|
||||
if (finishLatch.await(60, TimeUnit.SECONDS)) {
|
||||
Assert.assertFalse(error.get());
|
||||
} else {
|
||||
Assert.fail("Too long execution!");
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,79 +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 android.content.Context;
|
||||
import jscl.JsclMathEngine;
|
||||
|
||||
import org.mockito.Mockito;
|
||||
import org.solovyev.android.calculator.history.CalculatorHistory;
|
||||
import org.solovyev.android.calculator.plot.CalculatorPlotter;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 10/7/12
|
||||
* Time: 8:56 PM
|
||||
*/
|
||||
public class CalculatorTestUtils {
|
||||
|
||||
public static void staticSetUp(@Nullable Context context) throws Exception {
|
||||
Locator.getInstance().init(new CalculatorImpl(), newCalculatorEngine(), Mockito.mock(CalculatorClipboard.class), Mockito.mock(CalculatorNotifier.class), Mockito.mock(CalculatorHistory.class), new SystemOutCalculatorLogger(), Mockito.mock(CalculatorPreferenceService.class), Mockito.mock(CalculatorKeyboard.class), Mockito.mock(CalculatorPlotter.class), null);
|
||||
Locator.getInstance().getEngine().init();
|
||||
|
||||
if (context != null) {
|
||||
initViews(context);
|
||||
}
|
||||
}
|
||||
|
||||
public static void initViews(@Nonnull Context context) {
|
||||
final AndroidCalculatorEditorView editor = new AndroidCalculatorEditorView(context);
|
||||
editor.init();
|
||||
Locator.getInstance().getEditor().setView(editor);
|
||||
|
||||
final AndroidCalculatorDisplayView display = new AndroidCalculatorDisplayView(context);
|
||||
display.init(context);
|
||||
Locator.getInstance().getDisplay().setView(display);
|
||||
}
|
||||
|
||||
public static void staticSetUp() throws Exception {
|
||||
staticSetUp(null);
|
||||
}
|
||||
|
||||
|
||||
@Nonnull
|
||||
static CalculatorEngineImpl newCalculatorEngine() {
|
||||
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);
|
||||
}
|
||||
}
|
@@ -1,47 +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;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 6/18/13
|
||||
* Time: 8:45 PM
|
||||
*/
|
||||
public class TestCalculatorApplication extends CalculatorApplication {
|
||||
|
||||
private static volatile boolean initialized = false;
|
||||
|
||||
public TestCalculatorApplication() {
|
||||
super(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
synchronized (TestCalculatorApplication.class) {
|
||||
if (!initialized) {
|
||||
super.onCreate();
|
||||
initialized = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,179 +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 android.graphics.Color;
|
||||
import jscl.MathEngine;
|
||||
import jscl.NumeralBase;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.solovyev.android.calculator.text.TextProcessor;
|
||||
import org.solovyev.android.calculator.view.TextHighlighter;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Random;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 10/12/11
|
||||
* Time: 10:07 PM
|
||||
*/
|
||||
public class TextHighlighterTest {
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
CalculatorTestUtils.staticSetUp();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProcess() throws Exception {
|
||||
TextProcessor<?, String> textHighlighter = new TextHighlighter(0, false);
|
||||
|
||||
final Random random = new Random(new Date().getTime());
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
for (int j = 0; j < 1000; j++) {
|
||||
sb.append(random.nextBoolean() ? "(" : ")");
|
||||
}
|
||||
try {
|
||||
textHighlighter.process(sb.toString());
|
||||
} catch (Exception e) {
|
||||
System.out.println(sb.toString());
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals("<font color=\"#000000\"></font>)(((())())", textHighlighter.process(")(((())())").toString());
|
||||
assertEquals(")", textHighlighter.process(")").toString());
|
||||
assertEquals(")()(", textHighlighter.process(")()(").toString());
|
||||
|
||||
textHighlighter = new TextHighlighter(0, true);
|
||||
assertEquals("1 000 000", textHighlighter.process("1000000").toString());
|
||||
assertEquals("1 000 000", textHighlighter.process("1000000").toString());
|
||||
assertEquals("0.1E3", textHighlighter.process("0.1E3").toString());
|
||||
assertEquals("1E3", textHighlighter.process("1E3").toString());
|
||||
assertEquals("2<b>0x:</b>", textHighlighter.process("20x:").toString());
|
||||
assertEquals("20g", textHighlighter.process("20g").toString());
|
||||
assertEquals("22g", textHighlighter.process("22g").toString());
|
||||
assertEquals("20ю", textHighlighter.process("20ю").toString());
|
||||
assertEquals("20ъ", textHighlighter.process("20ъ").toString());
|
||||
assertEquals("3!!", textHighlighter.process("3!!").toString());
|
||||
assertEquals("2", textHighlighter.process("2").toString());
|
||||
assertEquals("21", textHighlighter.process("21").toString());
|
||||
assertEquals("214", textHighlighter.process("214").toString());
|
||||
assertEquals("2 145", textHighlighter.process("2 145").toString());
|
||||
assertEquals("1 000 000E3", textHighlighter.process("1000000E3").toString());
|
||||
assertEquals("-1 000 000E3", textHighlighter.process("-1000000E3").toString());
|
||||
assertEquals("-1 000 000E-3", textHighlighter.process("-1000000E-3").toString());
|
||||
assertEquals("-1 000 000E-30000", textHighlighter.process("-1000000E-30000").toString());
|
||||
textHighlighter = new TextHighlighter(0, false);
|
||||
|
||||
textHighlighter.process("cannot calculate 3^10^10 !!!\n" +
|
||||
" unable to enter 0. FIXED\n" +
|
||||
" empty display in Xperia Rayo\n" +
|
||||
" check привиденная FIXED\n" +
|
||||
" set display result only if text in editor was not changed FIXED\n" +
|
||||
" shift M text to the left\n" +
|
||||
" do not show SYNTAX ERROR always (may be show send clock?q) FIXED\n" +
|
||||
" ln(8)*log(8) => ln(8)*og(8) FIXED\n" +
|
||||
" copy/paste ln(8)*log(8)\n" +
|
||||
" 6!^2 ERROR");
|
||||
|
||||
assertEquals("<font color=\"#000000\"><i>sin</i>(</font><font color=\"#ffff9a\">2</font><font color=\"#000000\">)</font>", textHighlighter.process("sin(2)").toString());
|
||||
assertEquals("<font color=\"#000000\"><i>atanh</i>(</font><font color=\"#ffff9a\">2</font><font color=\"#000000\">)</font>", textHighlighter.process("atanh(2)").toString());
|
||||
|
||||
|
||||
assertEquals("<b>0x:</b>E", textHighlighter.process("0x:E").toString());
|
||||
assertEquals("<b>0x:</b>6F", textHighlighter.process("0x:6F").toString());
|
||||
assertEquals("<b>0x:</b>6F.", textHighlighter.process("0x:6F.").toString());
|
||||
assertEquals("<b>0x:</b>6F.2", textHighlighter.process("0x:6F.2").toString());
|
||||
assertEquals("<b>0x:</b>6F.B", textHighlighter.process("0x:6F.B").toString());
|
||||
assertEquals("<b>0x:</b>006F.B", textHighlighter.process("0x:006F.B").toString());
|
||||
assertEquals("<b>0x:</b>0", textHighlighter.process("0x:0").toString());
|
||||
assertEquals("<b>0x:</b>FF33233FFE", textHighlighter.process("0x:FF33233FFE").toString());
|
||||
assertEquals("<b>0x:</b>FF33 233 FFE", textHighlighter.process("0x:FF33 233 FFE").toString());
|
||||
|
||||
final MathEngine me = Locator.getInstance().getEngine().getMathEngine0();
|
||||
try {
|
||||
me.setNumeralBase(NumeralBase.hex);
|
||||
assertEquals("E", textHighlighter.process("E").toString());
|
||||
assertEquals(".E", textHighlighter.process(".E").toString());
|
||||
assertEquals("E+", textHighlighter.process("E+").toString());
|
||||
assertEquals("E.", textHighlighter.process("E.").toString());
|
||||
assertEquals(".E.", textHighlighter.process(".E.").toString());
|
||||
assertEquals("6F", textHighlighter.process("6F").toString());
|
||||
assertEquals("6F", textHighlighter.process("6F").toString());
|
||||
assertEquals("6F.", textHighlighter.process("6F.").toString());
|
||||
assertEquals("6F.2", textHighlighter.process("6F.2").toString());
|
||||
assertEquals("6F.B", textHighlighter.process("6F.B").toString());
|
||||
assertEquals("006F.B", textHighlighter.process("006F.B").toString());
|
||||
} finally {
|
||||
me.setNumeralBase(NumeralBase.dec);
|
||||
}
|
||||
|
||||
assertEquals("<b>0b:</b>110101", textHighlighter.process("0b:110101").toString());
|
||||
assertEquals("<b>0b:</b>110101.", textHighlighter.process("0b:110101.").toString());
|
||||
assertEquals("<b>0b:</b>110101.101", textHighlighter.process("0b:110101.101").toString());
|
||||
assertEquals("<b>0b:</b>11010100.1", textHighlighter.process("0b:11010100.1").toString());
|
||||
assertEquals("<b>0b:</b>110101.0", textHighlighter.process("0b:110101.0").toString());
|
||||
assertEquals("<b>0b:</b>0", textHighlighter.process("0b:0").toString());
|
||||
assertEquals("<b>0b:</b>1010100101111010101001", textHighlighter.process("0b:1010100101111010101001").toString());
|
||||
assertEquals("<b>0b:</b>101 010 01 0 111 1 0 10101001", textHighlighter.process("0b:101 010 01 0 111 1 0 10101001").toString());
|
||||
|
||||
try {
|
||||
me.setNumeralBase(NumeralBase.bin);
|
||||
assertEquals("110101", textHighlighter.process("110101").toString());
|
||||
assertEquals("110101.", textHighlighter.process("110101.").toString());
|
||||
assertEquals("110101.101", textHighlighter.process("110101.101").toString());
|
||||
assertEquals("11010100.1", textHighlighter.process("11010100.1").toString());
|
||||
assertEquals("110101.0", textHighlighter.process("110101.0").toString());
|
||||
assertEquals("0", textHighlighter.process("0").toString());
|
||||
assertEquals("1010100101111010101001", textHighlighter.process("1010100101111010101001").toString());
|
||||
assertEquals("101 010 01 0 111 1 0 10101001", textHighlighter.process("101 010 01 0 111 1 0 10101001").toString());
|
||||
} finally {
|
||||
me.setNumeralBase(NumeralBase.dec);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTime() throws Exception {
|
||||
final TextProcessor<?, String> textHighlighter = new TextHighlighter(Color.WHITE, false);
|
||||
|
||||
final int count = 1000;
|
||||
final String subExpression = "cos(acos(t8ln(t5t85tln(8ln(5t55tln(5))))))+tln(88cos(tln(t)))+t√(ln(t))";
|
||||
final StringBuilder expression = new StringBuilder(subExpression.length() * count);
|
||||
for (int i = 0; i < count; i++) {
|
||||
expression.append(subExpression);
|
||||
expression.append("+");
|
||||
}
|
||||
expression.append(subExpression);
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
textHighlighter.process(expression.toString());
|
||||
long endTime = System.currentTimeMillis();
|
||||
System.out.println("Total time, ms: " + (endTime - startTime));
|
||||
}
|
||||
}
|
@@ -1,209 +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.history;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.solovyev.android.calculator.CalculatorDisplayViewState;
|
||||
import org.solovyev.android.calculator.CalculatorDisplayViewStateImpl;
|
||||
import org.solovyev.android.calculator.CalculatorEditorViewState;
|
||||
import org.solovyev.android.calculator.CalculatorEditorViewStateImpl;
|
||||
import org.solovyev.android.calculator.jscl.JsclOperation;
|
||||
import org.solovyev.common.Objects;
|
||||
import org.solovyev.common.equals.CollectionEqualizer;
|
||||
import org.solovyev.common.history.HistoryHelper;
|
||||
import org.solovyev.common.history.SimpleHistoryHelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 12/17/11
|
||||
* Time: 10:01 PM
|
||||
*/
|
||||
public class HistoryUtilsTest {
|
||||
|
||||
@Test
|
||||
public void testFromXml() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
private static final String emptyHistory = "<history>\n" +
|
||||
" <historyItems class=\"java.util.ArrayList\"/>\n" +
|
||||
"</history>";
|
||||
|
||||
private static final String toXml1 = "<history>\n" +
|
||||
" <historyItems class=\"java.util.ArrayList\">\n" +
|
||||
" <calculatorHistoryState>\n" +
|
||||
" <time>100000000</time>\n" +
|
||||
" <editorState>\n" +
|
||||
" <cursorPosition>3</cursorPosition>\n" +
|
||||
" <text>1+1</text>\n" +
|
||||
" </editorState>\n" +
|
||||
" <displayState>\n" +
|
||||
" <editorState>\n" +
|
||||
" <cursorPosition>0</cursorPosition>\n" +
|
||||
" <text>Error</text>\n" +
|
||||
" </editorState>\n" +
|
||||
" <jsclOperation>simplify</jsclOperation>\n" +
|
||||
" </displayState>\n" +
|
||||
" </calculatorHistoryState>\n" +
|
||||
" </historyItems>\n" +
|
||||
"</history>";
|
||||
|
||||
private static final String toXml2 = "<history>\n" +
|
||||
" <historyItems class=\"java.util.ArrayList\">\n" +
|
||||
" <calculatorHistoryState>\n" +
|
||||
" <time>100000000</time>\n" +
|
||||
" <editorState>\n" +
|
||||
" <cursorPosition>3</cursorPosition>\n" +
|
||||
" <text>1+1</text>\n" +
|
||||
" </editorState>\n" +
|
||||
" <displayState>\n" +
|
||||
" <editorState>\n" +
|
||||
" <cursorPosition>0</cursorPosition>\n" +
|
||||
" <text>Error</text>\n" +
|
||||
" </editorState>\n" +
|
||||
" <jsclOperation>simplify</jsclOperation>\n" +
|
||||
" </displayState>\n" +
|
||||
" </calculatorHistoryState>\n" +
|
||||
" <calculatorHistoryState>\n" +
|
||||
" <time>100000000</time>\n" +
|
||||
" <editorState>\n" +
|
||||
" <cursorPosition>2</cursorPosition>\n" +
|
||||
" <text>5/6</text>\n" +
|
||||
" </editorState>\n" +
|
||||
" <displayState>\n" +
|
||||
" <editorState>\n" +
|
||||
" <cursorPosition>3</cursorPosition>\n" +
|
||||
" <text>5/6</text>\n" +
|
||||
" </editorState>\n" +
|
||||
" <jsclOperation>numeric</jsclOperation>\n" +
|
||||
" </displayState>\n" +
|
||||
" </calculatorHistoryState>\n" +
|
||||
" <calculatorHistoryState>\n" +
|
||||
" <time>100000000</time>\n" +
|
||||
" <editorState>\n" +
|
||||
" <cursorPosition>1</cursorPosition>\n" +
|
||||
" <text></text>\n" +
|
||||
" </editorState>\n" +
|
||||
" <displayState>\n" +
|
||||
" <editorState>\n" +
|
||||
" <cursorPosition>0</cursorPosition>\n" +
|
||||
" <text>Error</text>\n" +
|
||||
" </editorState>\n" +
|
||||
" <jsclOperation>elementary</jsclOperation>\n" +
|
||||
" </displayState>\n" +
|
||||
" </calculatorHistoryState>\n" +
|
||||
" <calculatorHistoryState>\n" +
|
||||
" <time>100000000</time>\n" +
|
||||
" <editorState>\n" +
|
||||
" <cursorPosition>0</cursorPosition>\n" +
|
||||
" <text>4+5/35sin(41)+dfdsfsdfs</text>\n" +
|
||||
" </editorState>\n" +
|
||||
" <displayState>\n" +
|
||||
" <editorState>\n" +
|
||||
" <cursorPosition>1</cursorPosition>\n" +
|
||||
" <text>4+5/35sin(41)+dfdsfsdfs</text>\n" +
|
||||
" </editorState>\n" +
|
||||
" <jsclOperation>numeric</jsclOperation>\n" +
|
||||
" </displayState>\n" +
|
||||
" </calculatorHistoryState>\n" +
|
||||
" </historyItems>\n" +
|
||||
"</history>";
|
||||
|
||||
@Test
|
||||
public void testToXml() throws Exception {
|
||||
final Date date = new Date(100000000);
|
||||
|
||||
HistoryHelper<CalculatorHistoryState> history = SimpleHistoryHelper.newInstance();
|
||||
|
||||
CalculatorDisplayViewState calculatorDisplay = CalculatorDisplayViewStateImpl.newErrorState(JsclOperation.simplify, "Error");
|
||||
|
||||
CalculatorEditorViewState calculatorEditor = CalculatorEditorViewStateImpl.newInstance("1+1", 3);
|
||||
|
||||
CalculatorHistoryState state = CalculatorHistoryState.newInstance(calculatorEditor, calculatorDisplay);
|
||||
state.setTime(date.getTime());
|
||||
history.addState(state);
|
||||
|
||||
assertEquals(emptyHistory, HistoryUtils.toXml(history.getStates()));
|
||||
|
||||
|
||||
state.setSaved(true);
|
||||
|
||||
assertEquals(toXml1, HistoryUtils.toXml(history.getStates()));
|
||||
|
||||
calculatorDisplay = CalculatorDisplayViewStateImpl.newValidState(JsclOperation.numeric, null, "5/6", 3);
|
||||
|
||||
calculatorEditor = CalculatorEditorViewStateImpl.newInstance("5/6", 2);
|
||||
|
||||
state = CalculatorHistoryState.newInstance(calculatorEditor, calculatorDisplay);
|
||||
state.setSaved(true);
|
||||
state.setTime(date.getTime());
|
||||
history.addState(state);
|
||||
|
||||
calculatorDisplay = CalculatorDisplayViewStateImpl.newErrorState(JsclOperation.elementary, "Error");
|
||||
|
||||
calculatorEditor = CalculatorEditorViewStateImpl.newInstance("", 1);
|
||||
|
||||
state = CalculatorHistoryState.newInstance(calculatorEditor, calculatorDisplay);
|
||||
state.setSaved(true);
|
||||
state.setTime(date.getTime());
|
||||
history.addState(state);
|
||||
|
||||
calculatorDisplay = CalculatorDisplayViewStateImpl.newValidState(JsclOperation.numeric, null, "4+5/35sin(41)+dfdsfsdfs", 1);
|
||||
|
||||
calculatorEditor = CalculatorEditorViewStateImpl.newInstance("4+5/35sin(41)+dfdsfsdfs", 0);
|
||||
|
||||
state = CalculatorHistoryState.newInstance(calculatorEditor, calculatorDisplay);
|
||||
state.setSaved(true);
|
||||
state.setTime(date.getTime());
|
||||
history.addState(state);
|
||||
|
||||
String xml = HistoryUtils.toXml(history.getStates());
|
||||
assertEquals(toXml2, xml);
|
||||
|
||||
final List<CalculatorHistoryState> fromXml = new ArrayList<CalculatorHistoryState>();
|
||||
final HistoryHelper<CalculatorHistoryState> historyFromXml = SimpleHistoryHelper.newInstance();
|
||||
HistoryUtils.fromXml(xml, fromXml);
|
||||
for (CalculatorHistoryState historyState : fromXml) {
|
||||
historyFromXml.addState(historyState);
|
||||
}
|
||||
|
||||
assertEquals(history.getStates().size(), historyFromXml.getStates().size());
|
||||
|
||||
for (CalculatorHistoryState historyState : history.getStates()) {
|
||||
historyState.setId(0);
|
||||
historyState.setSaved(true);
|
||||
}
|
||||
for (CalculatorHistoryState historyState : historyFromXml.getStates()) {
|
||||
historyState.setId(0);
|
||||
historyState.setSaved(true);
|
||||
}
|
||||
Assert.assertTrue(Objects.areEqual(history.getStates(), historyFromXml.getStates(), new CollectionEqualizer<CalculatorHistoryState>(null)));
|
||||
}
|
||||
}
|
@@ -1,9 +0,0 @@
|
||||
package org.solovyev.android.calculator.matrix;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 7/11/13
|
||||
* Time: 4:56 PM
|
||||
*/
|
||||
public class MatrixViewTest {
|
||||
}
|
@@ -1,86 +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.model;
|
||||
|
||||
import jscl.math.function.IConstant;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.simpleframework.xml.Serializer;
|
||||
import org.simpleframework.xml.core.Persister;
|
||||
|
||||
import java.io.StringWriter;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 11/7/11
|
||||
* Time: 7:52 PM
|
||||
*/
|
||||
public class VarTest {
|
||||
|
||||
private static final String xml = "<vars>\n" +
|
||||
" <vars class=\"java.util.ArrayList\">\n" +
|
||||
" <var>\n" +
|
||||
" <name>e</name>\n" +
|
||||
" <value>2.718281828459045</value>\n" +
|
||||
" <system>true</system>\n" +
|
||||
" <description>description</description>\n" +
|
||||
" </var>\n" +
|
||||
" <var>\n" +
|
||||
" <name>;</name>\n" +
|
||||
" <value>3.0</value>\n" +
|
||||
" <system>true</system>\n" +
|
||||
" </var>\n" +
|
||||
" </vars>\n" +
|
||||
"</vars>";
|
||||
|
||||
@Test
|
||||
public void testXml() throws Exception {
|
||||
final Vars vars = new Vars();
|
||||
Var first = new Var.Builder("e", Math.E).setDescription("description").setSystem(true).create();
|
||||
vars.getEntities().add(first);
|
||||
Var second = new Var.Builder(";", 3d).setSystem(true).create();
|
||||
vars.getEntities().add(second);
|
||||
|
||||
final StringWriter sw = new StringWriter();
|
||||
final Serializer serializer = new Persister();
|
||||
serializer.write(vars, sw);
|
||||
|
||||
assertEquals(xml, sw.toString());
|
||||
|
||||
final Vars result = serializer.read(Vars.class, xml);
|
||||
final IConstant actualFirst = result.getEntities().get(0);
|
||||
final IConstant actualSecond = result.getEntities().get(1);
|
||||
|
||||
areEqual(first, actualFirst);
|
||||
areEqual(second, actualSecond);
|
||||
|
||||
}
|
||||
|
||||
private void areEqual(IConstant expected, IConstant actual) {
|
||||
assertEquals(expected.getName(), actual.getName());
|
||||
assertEquals(expected.getDescription(), actual.getDescription());
|
||||
assertEquals(expected.getValue(), actual.getValue());
|
||||
}
|
||||
}
|
@@ -1,63 +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.plot;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.DecimalFormatSymbols;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 1/15/13
|
||||
* Time: 9:58 PM
|
||||
*/
|
||||
public class CalculatorGraph2dViewTest {
|
||||
|
||||
@Test
|
||||
public void testFormatTick() throws Exception {
|
||||
assertEquals("23324", CalculatorGraph2dView.formatTick(23324.0f, 0));
|
||||
|
||||
final DecimalFormat format = (DecimalFormat) DecimalFormat.getInstance();
|
||||
final DecimalFormatSymbols decimalFormatSymbols = format.getDecimalFormatSymbols();
|
||||
if (',' == decimalFormatSymbols.getDecimalSeparator()) {
|
||||
assertEquals("23324,1", CalculatorGraph2dView.formatTick(23324.1f, 1));
|
||||
} else if ('.' == decimalFormatSymbols.getDecimalSeparator()) {
|
||||
assertEquals("23324.1", CalculatorGraph2dView.formatTick(23324.1f, 1));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCountTickDigits() throws Exception {
|
||||
assertEquals(0, CalculatorGraph2dView.countTickDigits(1));
|
||||
assertEquals(0, CalculatorGraph2dView.countTickDigits(10));
|
||||
assertEquals(0, CalculatorGraph2dView.countTickDigits(100));
|
||||
assertEquals(1, CalculatorGraph2dView.countTickDigits(0.9f));
|
||||
assertEquals(1, CalculatorGraph2dView.countTickDigits(0.2f));
|
||||
assertEquals(1, CalculatorGraph2dView.countTickDigits(0.1f));
|
||||
assertEquals(2, CalculatorGraph2dView.countTickDigits(0.099f));
|
||||
assertEquals(3, CalculatorGraph2dView.countTickDigits(0.009f));
|
||||
}
|
||||
}
|
@@ -1,220 +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.wizard;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.shadows.ShadowActivity;
|
||||
import org.robolectric.util.ActivityController;
|
||||
import org.solovyev.android.wizard.BaseWizardActivity;
|
||||
import org.solovyev.android.wizard.Wizard;
|
||||
import org.solovyev.android.wizard.WizardUi;
|
||||
import org.solovyev.android.wizard.Wizards;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import static android.view.View.GONE;
|
||||
import static android.view.View.VISIBLE;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.solovyev.android.calculator.wizard.CalculatorWizardStep.choose_mode;
|
||||
|
||||
@RunWith(value = RobolectricTestRunner.class)
|
||||
public class CalculatorWizardActivityTest {
|
||||
|
||||
private ActivityController<CalculatorWizardActivity> controller;
|
||||
private CalculatorWizardActivity activity;
|
||||
private Wizards wizards;
|
||||
private Field uiField;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
controller = Robolectric.buildActivity(CalculatorWizardActivity.class);
|
||||
activity = controller.get();
|
||||
wizards = new CalculatorWizards(Robolectric.application);
|
||||
activity.setWizards(wizards);
|
||||
controller.attach();
|
||||
controller.create();
|
||||
|
||||
uiField = BaseWizardActivity.class.getDeclaredField("ui");
|
||||
uiField.setAccessible(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldBeFirstTimeWizardByDefault() throws Exception {
|
||||
assertEquals(CalculatorWizards.FIRST_TIME_WIZARD, getWizardUi().getWizard().getName());
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private WizardUi getWizardUi() throws IllegalAccessException {
|
||||
return (WizardUi) uiField.get(activity);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldBeFirstStep() throws Exception {
|
||||
assertNotNull(getWizardUi().getStep());
|
||||
assertEquals(getWizardUi().getFlow().getFirstStep(), getWizardUi().getStep());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldSaveState() throws Exception {
|
||||
getWizardUi().setStep(choose_mode);
|
||||
|
||||
final Bundle outState = new Bundle();
|
||||
controller.saveInstanceState(outState);
|
||||
|
||||
controller = Robolectric.buildActivity(CalculatorWizardActivity.class);
|
||||
controller.create(outState);
|
||||
|
||||
activity = controller.get();
|
||||
assertNotNull(getWizardUi().getFlow());
|
||||
assertEquals(CalculatorWizards.FIRST_TIME_WIZARD, getWizardUi().getWizard().getName());
|
||||
assertNotNull(getWizardUi().getStep());
|
||||
assertEquals(choose_mode, getWizardUi().getStep());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreate() throws Exception {
|
||||
final Intent intent = new Intent();
|
||||
intent.setClass(activity, CalculatorWizardActivity.class);
|
||||
intent.putExtra("flow", CalculatorWizards.DEFAULT_WIZARD_FLOW);
|
||||
controller = Robolectric.buildActivity(CalculatorWizardActivity.class).withIntent(intent);
|
||||
controller.create();
|
||||
activity = controller.get();
|
||||
assertEquals(CalculatorWizards.DEFAULT_WIZARD_FLOW, getWizardUi().getWizard().getName());
|
||||
assertEquals(getWizardUi().getFlow().getFirstStep(), getWizardUi().getStep());
|
||||
|
||||
final Bundle outState1 = new Bundle();
|
||||
controller.saveInstanceState(outState1);
|
||||
|
||||
controller = Robolectric.buildActivity(CalculatorWizardActivity.class);
|
||||
activity = controller.get();
|
||||
controller.create(outState1);
|
||||
assertEquals(CalculatorWizards.DEFAULT_WIZARD_FLOW, getWizardUi().getWizard().getName());
|
||||
assertEquals(getWizardUi().getFlow().getFirstStep(), getWizardUi().getStep());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldAddFirstFragment() throws Exception {
|
||||
controller.start().resume();
|
||||
|
||||
final FragmentManager fm = activity.getSupportFragmentManager();
|
||||
final Fragment f = fm.findFragmentByTag(CalculatorWizardStep.welcome.getFragmentTag());
|
||||
assertNotNull(f);
|
||||
assertTrue(f.isAdded());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldAddStepFragment() throws Exception {
|
||||
controller.start().resume();
|
||||
|
||||
final FragmentManager fm = activity.getSupportFragmentManager();
|
||||
|
||||
getWizardUi().setStep(choose_mode);
|
||||
|
||||
final Fragment f = fm.findFragmentByTag(choose_mode.getFragmentTag());
|
||||
assertNotNull(f);
|
||||
assertTrue(f.isAdded());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetStep() throws Exception {
|
||||
getWizardUi().setStep(choose_mode);
|
||||
assertEquals(choose_mode, getWizardUi().getStep());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldStartWizardActivityAfterStart() throws Exception {
|
||||
final ShadowActivity shadowActivity = Robolectric.shadowOf(controller.get());
|
||||
WizardUi.startWizard(activity.getWizards(), CalculatorWizards.DEFAULT_WIZARD_FLOW, shadowActivity.getApplicationContext());
|
||||
assertNotNull(shadowActivity.getNextStartedActivity());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTitleShouldBeSet() throws Exception {
|
||||
getWizardUi().setStep(choose_mode);
|
||||
assertEquals(activity.getString(choose_mode.getTitleResId()), activity.getTitle().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNextButtonShouldBeShownAtTheEnd() throws Exception {
|
||||
setLastStep();
|
||||
assertEquals(VISIBLE, getWizardUi().getPrevButton().getVisibility());
|
||||
assertEquals(VISIBLE, getWizardUi().getNextButton().getVisibility());
|
||||
}
|
||||
|
||||
private void setLastStep() throws IllegalAccessException {
|
||||
getWizardUi().setStep(CalculatorWizardStep.values()[CalculatorWizardStep.values().length - 1]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrevButtonShouldNotBeShownAtTheStart() throws Exception {
|
||||
setFirstStep();
|
||||
assertEquals(VISIBLE, getWizardUi().getNextButton().getVisibility());
|
||||
assertEquals(GONE, getWizardUi().getPrevButton().getVisibility());
|
||||
}
|
||||
|
||||
private void setFirstStep() throws IllegalAccessException {
|
||||
getWizardUi().setStep(CalculatorWizardStep.values()[0]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldSaveLastWizardStateOnPause() throws Exception {
|
||||
final Wizard wizard = wizards.getWizard(getWizardUi().getWizard().getName());
|
||||
assertNull(wizard.getLastSavedStepName());
|
||||
getWizardUi().setStep(CalculatorWizardStep.drag_button);
|
||||
activity.onPause();
|
||||
assertEquals(CalculatorWizardStep.drag_button.getName(), wizard.getLastSavedStepName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldSaveFinishedIfLastStep() throws Exception {
|
||||
final Wizard wizard = wizards.getWizard(getWizardUi().getWizard().getName());
|
||||
assertFalse(wizard.isFinished());
|
||||
setLastStep();
|
||||
getWizardUi().finishWizard();
|
||||
assertTrue(wizard.isFinished());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldNotSaveFinishedIfNotLastStep() throws Exception {
|
||||
final Wizard wizard = wizards.getWizard(getWizardUi().getWizard().getName());
|
||||
assertFalse(wizard.isFinished());
|
||||
setFirstStep();
|
||||
getWizardUi().finishWizard();
|
||||
assertFalse(wizard.isFinished());
|
||||
}
|
||||
}
|
@@ -1,101 +0,0 @@
|
||||
package org.solovyev.android.calculator.wizard;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.solovyev.android.wizard.Wizard;
|
||||
import org.solovyev.android.wizard.WizardFlow;
|
||||
import org.solovyev.android.wizard.Wizards;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.solovyev.android.calculator.wizard.CalculatorWizardStep.choose_mode;
|
||||
import static org.solovyev.android.calculator.wizard.CalculatorWizardStep.last;
|
||||
import static org.solovyev.android.calculator.wizard.CalculatorWizardStep.welcome;
|
||||
|
||||
@RunWith(value = RobolectricTestRunner.class)
|
||||
public class CalculatorWizardTest {
|
||||
|
||||
@Nonnull
|
||||
private Wizards wizards;
|
||||
|
||||
@Nonnull
|
||||
private Wizard wizard;
|
||||
|
||||
@Nonnull
|
||||
private Wizard defaultWizard;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
wizards = new CalculatorWizards(Robolectric.application);
|
||||
wizard = wizards.getWizard(null);
|
||||
defaultWizard = wizards.getWizard(CalculatorWizards.DEFAULT_WIZARD_FLOW);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultFlowShouldNotContainWelcomeAndLastSteps() throws Exception {
|
||||
final WizardFlow flow = defaultWizard.getFlow();
|
||||
assertNull(flow.getStepByName(welcome.getName()));
|
||||
assertNull(flow.getStepByName(last.getName()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFirstTimeFlowShouldContainWelcomeAndLastSteps() throws Exception {
|
||||
final WizardFlow flow = wizard.getFlow();
|
||||
assertNotNull(flow.getStepByName(welcome.getName()));
|
||||
assertNotNull(flow.getStepByName(last.getName()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldThrowExceptionIfUnknownWizard() throws Exception {
|
||||
try {
|
||||
wizards.getWizard("testtesttesttesttest");
|
||||
fail();
|
||||
} catch (IllegalArgumentException e) {
|
||||
// ok
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldReturnWizard() throws Exception {
|
||||
assertNotNull(wizards.getWizard(CalculatorWizards.FIRST_TIME_WIZARD));
|
||||
assertNotNull(wizards.getWizard(CalculatorWizards.DEFAULT_WIZARD_FLOW));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldSaveWizardIsFinishedWhenNotLastStepAndForce() throws Exception {
|
||||
assertFalse(wizard.isFinished());
|
||||
wizard.saveFinished(CalculatorWizardStep.drag_button, true);
|
||||
|
||||
assertTrue(wizard.isFinished());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldNotSaveWizardIsFinishedWhenNotLastStepAndNotForce() throws Exception {
|
||||
assertFalse(wizard.isFinished());
|
||||
wizard.saveFinished(CalculatorWizardStep.drag_button, false);
|
||||
|
||||
assertFalse(wizard.isFinished());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldSaveWizardIsFinishedWhenLastStep() throws Exception {
|
||||
assertFalse(wizard.isFinished());
|
||||
wizard.saveFinished(CalculatorWizardStep.last, false);
|
||||
|
||||
assertTrue(wizard.isFinished());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldSaveLastWizardStep() throws Exception {
|
||||
assertFalse(wizard.isStarted());
|
||||
assertNull(wizard.getLastSavedStepName());
|
||||
|
||||
wizard.saveLastStep(choose_mode);
|
||||
assertTrue(wizard.isStarted());
|
||||
assertEquals(choose_mode.name(), wizard.getLastSavedStepName());
|
||||
}
|
||||
}
|
@@ -1,112 +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.wizard;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.util.ActivityController;
|
||||
import org.solovyev.android.calculator.CalculatorPreferences;
|
||||
import org.solovyev.android.wizard.BaseWizardActivity;
|
||||
import org.solovyev.android.wizard.WizardUi;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class OnScreenCalculatorWizardStepTest {
|
||||
|
||||
@Nonnull
|
||||
private OnScreenCalculatorWizardStep fragment;
|
||||
|
||||
@Nonnull
|
||||
private CalculatorWizardActivity activity;
|
||||
|
||||
@Nonnull
|
||||
private ActivityController<CalculatorWizardActivity> controller;
|
||||
private Field uiField;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
uiField = BaseWizardActivity.class.getDeclaredField("ui");
|
||||
uiField.setAccessible(true);
|
||||
|
||||
createActivity();
|
||||
setFragment();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private WizardUi getWizardUi() throws IllegalAccessException {
|
||||
return (WizardUi) uiField.get(activity);
|
||||
}
|
||||
|
||||
private void createActivity() {
|
||||
controller = Robolectric.buildActivity(CalculatorWizardActivity.class).create().start().resume();
|
||||
activity = controller.get();
|
||||
}
|
||||
|
||||
private void setFragment() throws IllegalAccessException {
|
||||
getWizardUi().setStep(CalculatorWizardStep.on_screen_calculator);
|
||||
activity.getSupportFragmentManager().executePendingTransactions();
|
||||
fragment = (OnScreenCalculatorWizardStep) activity.getSupportFragmentManager().findFragmentByTag(CalculatorWizardStep.on_screen_calculator.getFragmentTag());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldRestoreStateOnRestart() throws Exception {
|
||||
fragment.getOnscreenCalculatorCheckbox().setChecked(true);
|
||||
controller.restart();
|
||||
assertTrue(fragment.getOnscreenCalculatorCheckbox().isChecked());
|
||||
|
||||
fragment.getOnscreenCalculatorCheckbox().setChecked(false);
|
||||
controller.restart();
|
||||
assertFalse(fragment.getOnscreenCalculatorCheckbox().isChecked());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldBeEnabledIfIconIsShown() throws Exception {
|
||||
testShouldBeEqualsToIconState(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldBeDisabledIfIconIsNotShown() throws Exception {
|
||||
testShouldBeEqualsToIconState(false);
|
||||
}
|
||||
|
||||
private void testShouldBeEqualsToIconState(boolean iconEnabled) throws IllegalAccessException {
|
||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(Robolectric.application);
|
||||
CalculatorPreferences.OnscreenCalculator.showAppIcon.putPreference(preferences, iconEnabled);
|
||||
createActivity();
|
||||
setFragment();
|
||||
assertEquals(iconEnabled, fragment.isOnscreenCalculatorEnabled());
|
||||
}
|
||||
}
|
@@ -1,183 +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.wizard;
|
||||
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.solovyev.android.calculator.CalculatorPreferences;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.solovyev.android.calculator.CalculatorApplication.getPreferences;
|
||||
import static org.solovyev.android.calculator.CalculatorPreferences.Gui.Layout.main_calculator;
|
||||
import static org.solovyev.android.calculator.CalculatorPreferences.Gui.Layout.main_calculator_mobile;
|
||||
import static org.solovyev.android.calculator.CalculatorPreferences.OnscreenCalculator.showAppIcon;
|
||||
import static org.solovyev.android.calculator.wizard.CalculatorLayout.big_buttons;
|
||||
import static org.solovyev.android.calculator.wizard.CalculatorLayout.optimized;
|
||||
import static org.solovyev.android.calculator.wizard.CalculatorMode.engineer;
|
||||
import static org.solovyev.android.calculator.wizard.CalculatorMode.simple;
|
||||
import static org.solovyev.android.calculator.wizard.ChooseLayoutWizardStep.LAYOUT;
|
||||
import static org.solovyev.android.calculator.wizard.ChooseModeWizardStep.MODE;
|
||||
import static org.solovyev.android.calculator.wizard.OnScreenCalculatorWizardStep.ONSCREEN_CALCULATOR_ENABLED;
|
||||
import static org.solovyev.android.calculator.wizard.CalculatorWizardStep.choose_layout;
|
||||
import static org.solovyev.android.calculator.wizard.CalculatorWizardStep.choose_mode;
|
||||
import static org.solovyev.android.calculator.wizard.CalculatorWizardStep.on_screen_calculator;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class WizardStepTest {
|
||||
|
||||
private FragmentActivity activity;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
activity = Robolectric.buildActivity(FragmentActivity.class).create().get();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFragmentsShouldBeInstantiated() throws Exception {
|
||||
for (CalculatorWizardStep wizardStep : CalculatorWizardStep.values()) {
|
||||
Fragment.instantiate(Robolectric.application, wizardStep.getFragmentClass().getName());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldBeMainMobileLayout() throws Exception {
|
||||
chooseLayout(big_buttons);
|
||||
chooseMode(engineer);
|
||||
|
||||
assertUiLayoutEquals(main_calculator_mobile);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldBeMainLayout() throws Exception {
|
||||
chooseLayout(optimized);
|
||||
chooseMode(engineer);
|
||||
|
||||
assertUiLayoutEquals(main_calculator);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldBeSimpleLayout() throws Exception {
|
||||
chooseLayout(optimized);
|
||||
chooseMode(simple);
|
||||
|
||||
assertUiLayoutEquals(CalculatorPreferences.Gui.Layout.simple);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldBeSimpleMobileLayout() throws Exception {
|
||||
chooseLayout(big_buttons);
|
||||
chooseMode(simple);
|
||||
|
||||
assertUiLayoutEquals(CalculatorPreferences.Gui.Layout.simple_mobile);
|
||||
}
|
||||
|
||||
private void assertUiLayoutEquals(CalculatorPreferences.Gui.Layout uiLayout) {
|
||||
Assert.assertEquals(uiLayout, CalculatorPreferences.Gui.layout.getPreference(PreferenceManager.getDefaultSharedPreferences(Robolectric.application)));
|
||||
}
|
||||
|
||||
private void chooseMode(CalculatorMode mode) {
|
||||
final ChooseModeWizardStep modeFragment = mock(ChooseModeWizardStep.class);
|
||||
when(modeFragment.getSelectedMode()).thenReturn(mode);
|
||||
when(modeFragment.getActivity()).thenReturn(activity);
|
||||
CalculatorWizardStep.choose_mode.onNext(modeFragment);
|
||||
}
|
||||
|
||||
private void chooseLayout(CalculatorLayout layout) {
|
||||
final ChooseLayoutWizardStep layoutFragment = mock(ChooseLayoutWizardStep.class);
|
||||
when(layoutFragment.getSelectedLayout()).thenReturn(layout);
|
||||
when(layoutFragment.getActivity()).thenReturn(activity);
|
||||
choose_layout.onNext(layoutFragment);
|
||||
}
|
||||
|
||||
/* @Config(qualifiers = "large")
|
||||
@Test
|
||||
public void testChooseLayoutShouldBeVisibleForTablet() throws Exception {
|
||||
assertTrue(CalculatorWizardStep.choose_layout.isVisible());
|
||||
}*/
|
||||
|
||||
@Config(qualifiers = "normal")
|
||||
@Test
|
||||
public void testChooseLayoutShouldNotBeVisibleForMobile() throws Exception {
|
||||
assertFalse(choose_layout.isVisible());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnscreenCalculatorShouldNotBeShown() throws Exception {
|
||||
doOnscreenStep(false);
|
||||
assertFalse(showAppIcon.getPreference(getPreferences()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnscreenCalculatorShouldBeShown() throws Exception {
|
||||
doOnscreenStep(true);
|
||||
assertTrue(showAppIcon.getPreference(getPreferences()));
|
||||
}
|
||||
|
||||
|
||||
private void doOnscreenStep(boolean onscreenCalculatorEnabled) {
|
||||
final OnScreenCalculatorWizardStep f = mock(OnScreenCalculatorWizardStep.class);
|
||||
when(f.isOnscreenCalculatorEnabled()).thenReturn(onscreenCalculatorEnabled);
|
||||
when(f.getActivity()).thenReturn(activity);
|
||||
CalculatorWizardStep.on_screen_calculator.onNext(f);
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
@Test
|
||||
public void testChooseLayoutFragmentArgs() throws Exception {
|
||||
CalculatorPreferences.Gui.layout.putPreference(getPreferences(), CalculatorPreferences.Gui.Layout.simple);
|
||||
assertEquals(CalculatorLayout.optimized, choose_layout.getFragmentArgs().getSerializable(LAYOUT));
|
||||
|
||||
CalculatorPreferences.Gui.layout.putPreference(getPreferences(), CalculatorPreferences.Gui.Layout.simple_mobile);
|
||||
assertEquals(CalculatorLayout.big_buttons, choose_layout.getFragmentArgs().getSerializable(LAYOUT));
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
@Test
|
||||
public void testChooseModeFragmentArgs() throws Exception {
|
||||
CalculatorPreferences.Gui.layout.putPreference(getPreferences(), CalculatorPreferences.Gui.Layout.main_calculator);
|
||||
assertEquals(CalculatorMode.engineer, choose_mode.getFragmentArgs().getSerializable(MODE));
|
||||
|
||||
CalculatorPreferences.Gui.layout.putPreference(getPreferences(), CalculatorPreferences.Gui.Layout.simple_mobile);
|
||||
assertEquals(CalculatorMode.simple, choose_mode.getFragmentArgs().getSerializable(MODE));
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
@Test
|
||||
public void testOnscreenFragmentArgs() throws Exception {
|
||||
CalculatorPreferences.OnscreenCalculator.showAppIcon.putPreference(getPreferences(), true);
|
||||
assertTrue(on_screen_calculator.getFragmentArgs().getBoolean(ONSCREEN_CALCULATOR_ENABLED));
|
||||
|
||||
CalculatorPreferences.OnscreenCalculator.showAppIcon.putPreference(getPreferences(), false);
|
||||
assertFalse(on_screen_calculator.getFragmentArgs().getBoolean(ONSCREEN_CALCULATOR_ENABLED));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user