This commit is contained in:
Sergey Solovyev 2013-06-23 21:46:25 +04:00
parent 03965333c2
commit 0e9d791a6a
5 changed files with 109 additions and 92 deletions

View File

@ -1,11 +1,12 @@
package org.solovyev.android.calculator.matrix;
import android.app.ActionBar;
import android.os.Bundle;
import org.solovyev.android.calculator.CalculatorFragmentActivity;
import org.solovyev.android.calculator.CalculatorFragmentType;
import org.solovyev.android.calculator.R;
import static com.actionbarsherlock.app.ActionBar.NAVIGATION_MODE_STANDARD;
/**
* User: Solovyev_S
* Date: 12.10.12
@ -17,7 +18,7 @@ public class CalculatorMatrixActivity extends CalculatorFragmentActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
getSupportActionBar().setNavigationMode(NAVIGATION_MODE_STANDARD);
getActivityHelper().setFragment(this, CalculatorFragmentType.matrix_edit, null, R.id.main_layout);
}
}

View File

@ -1,14 +1,16 @@
package org.solovyev.android.calculator.plot;
import android.app.ActionBar;
import android.content.Intent;
import android.os.Bundle;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.solovyev.android.calculator.CalculatorFragmentActivity;
import org.solovyev.android.calculator.CalculatorFragmentType;
import org.solovyev.android.calculator.R;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import static com.actionbarsherlock.app.ActionBar.NAVIGATION_MODE_STANDARD;
/**
* User: serso
* Date: 9/30/12
@ -29,7 +31,7 @@ public class CalculatorPlotActivity extends CalculatorFragmentActivity {
arguments = null;
}
getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
getSupportActionBar().setNavigationMode(NAVIGATION_MODE_STANDARD);
getActivityHelper().setFragment(this, getPlotterFragmentType(), arguments, R.id.main_layout);
}

View File

@ -9,8 +9,6 @@ package org.solovyev.android.calculator;
import android.graphics.Color;
import jscl.MathEngine;
import jscl.NumeralBase;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.solovyev.android.calculator.text.TextProcessor;
@ -19,6 +17,8 @@ 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
@ -49,29 +49,29 @@ public class TextHighlighterTest {
}
}
Assert.assertEquals("<font color=\"#000000\"></font>)(((())())", textHighlighter.process(")(((())())").toString());
Assert.assertEquals(")", textHighlighter.process(")").toString());
Assert.assertEquals(")()(", textHighlighter.process(")()(").toString());
assertEquals("<font color=\"#000000\"></font>)(((())())", textHighlighter.process(")(((())())").toString());
assertEquals(")", textHighlighter.process(")").toString());
assertEquals(")()(", textHighlighter.process(")()(").toString());
textHighlighter = new TextHighlighter(0, true);
Assert.assertEquals("1 000 000", textHighlighter.process("1000000").toString());
Assert.assertEquals("1 000 000", textHighlighter.process("1000000").toString());
Assert.assertEquals("0.1E3", textHighlighter.process("0.1E3").toString());
Assert.assertEquals("1E3", textHighlighter.process("1E3").toString());
Assert.assertEquals("2<b>0x:</b>", textHighlighter.process("20x:").toString());
Assert.assertEquals("20g", textHighlighter.process("20g").toString());
Assert.assertEquals("22g", textHighlighter.process("22g").toString());
Assert.assertEquals("20ю", textHighlighter.process("20ю").toString());
Assert.assertEquals("20ъ", textHighlighter.process("20ъ").toString());
Assert.assertEquals("3!!", textHighlighter.process("3!!").toString());
Assert.assertEquals("2", textHighlighter.process("2").toString());
Assert.assertEquals("21", textHighlighter.process("21").toString());
Assert.assertEquals("214", textHighlighter.process("214").toString());
Assert.assertEquals("2 145", textHighlighter.process("2 145").toString());
Assert.assertEquals("1 000 000E3", textHighlighter.process("1000000E3").toString());
Assert.assertEquals("-1 000 000E3", textHighlighter.process("-1000000E3").toString());
Assert.assertEquals("-1 000 000E-3", textHighlighter.process("-1000000E-3").toString());
Assert.assertEquals("-1 000 000E-30000", textHighlighter.process("-1000000E-30000").toString());
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" +
@ -85,57 +85,57 @@ public class TextHighlighterTest {
" copy/paste ln(8)*log(8)\n" +
" 6!^2 ERROR");
Assert.assertEquals("<font color=\"#000000\"><i>sin</i>(</font><font color=\"#ffff9a\">2</font><font color=\"#000000\">)</font>", textHighlighter.process("sin(2)").toString());
Assert.assertEquals("<font color=\"#000000\"><i>atanh</i>(</font><font color=\"#ffff9a\">2</font><font color=\"#000000\">)</font>", textHighlighter.process("atanh(2)").toString());
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());
Assert.assertEquals("<b>0x:</b>E", textHighlighter.process("0x:E").toString());
Assert.assertEquals("<b>0x:</b>6F", textHighlighter.process("0x:6F").toString());
Assert.assertEquals("<b>0x:</b>6F.", textHighlighter.process("0x:6F.").toString());
Assert.assertEquals("<b>0x:</b>6F.2", textHighlighter.process("0x:6F.2").toString());
Assert.assertEquals("<b>0x:</b>6F.B", textHighlighter.process("0x:6F.B").toString());
Assert.assertEquals("<b>0x:</b>006F.B", textHighlighter.process("0x:006F.B").toString());
Assert.assertEquals("<b>0x:</b>0", textHighlighter.process("0x:0").toString());
Assert.assertEquals("<b>0x:</b>FF33233FFE", textHighlighter.process("0x:FF33233FFE").toString());
Assert.assertEquals("<b>0x:</b>FF33 233 FFE", textHighlighter.process("0x:FF33 233 FFE").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);
Assert.assertEquals("E", textHighlighter.process("E").toString());
Assert.assertEquals(".E", textHighlighter.process(".E").toString());
Assert.assertEquals("E+", textHighlighter.process("E+").toString());
Assert.assertEquals("E.", textHighlighter.process("E.").toString());
Assert.assertEquals(".E.", textHighlighter.process(".E.").toString());
Assert.assertEquals("6F", textHighlighter.process("6F").toString());
Assert.assertEquals("6F", textHighlighter.process("6F").toString());
Assert.assertEquals("6F.", textHighlighter.process("6F.").toString());
Assert.assertEquals("6F.2", textHighlighter.process("6F.2").toString());
Assert.assertEquals("6F.B", textHighlighter.process("6F.B").toString());
Assert.assertEquals("006F.B", textHighlighter.process("006F.B").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(".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);
}
Assert.assertEquals("<b>0b:</b>110101", textHighlighter.process("0b:110101").toString());
Assert.assertEquals("<b>0b:</b>110101.", textHighlighter.process("0b:110101.").toString());
Assert.assertEquals("<b>0b:</b>110101.101", textHighlighter.process("0b:110101.101").toString());
Assert.assertEquals("<b>0b:</b>11010100.1", textHighlighter.process("0b:11010100.1").toString());
Assert.assertEquals("<b>0b:</b>110101.0", textHighlighter.process("0b:110101.0").toString());
Assert.assertEquals("<b>0b:</b>0", textHighlighter.process("0b:0").toString());
Assert.assertEquals("<b>0b:</b>1010100101111010101001", textHighlighter.process("0b:1010100101111010101001").toString());
Assert.assertEquals("<b>0b:</b>101 010 01 0 111 1 0 10101001", textHighlighter.process("0b:101 010 01 0 111 1 0 10101001").toString());
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);
Assert.assertEquals("110101", textHighlighter.process("110101").toString());
Assert.assertEquals("110101.", textHighlighter.process("110101.").toString());
Assert.assertEquals("110101.101", textHighlighter.process("110101.101").toString());
Assert.assertEquals("11010100.1", textHighlighter.process("11010100.1").toString());
Assert.assertEquals("110101.0", textHighlighter.process("110101.0").toString());
Assert.assertEquals("0", textHighlighter.process("0").toString());
Assert.assertEquals("1010100101111010101001", textHighlighter.process("1010100101111010101001").toString());
Assert.assertEquals("101 010 01 0 111 1 0 10101001", textHighlighter.process("101 010 01 0 111 1 0 10101001").toString());
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);
}

View File

@ -4,8 +4,6 @@ import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -14,8 +12,9 @@ import org.robolectric.RobolectricTestRunner;
import org.robolectric.shadows.ShadowActivity;
import org.robolectric.util.ActivityController;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.*;
import static org.solovyev.android.calculator.wizard.CalculatorWizardActivity.startWizard;
import static org.solovyev.android.calculator.wizard.WizardStep.choose_mode;
/**
* User: serso
@ -31,20 +30,25 @@ public class CalculatorWizardActivityTest {
@Before
public void setUp() throws Exception {
controller = Robolectric.buildActivity(CalculatorWizardActivity.class);
controller.attach();
controller.create();
activity = controller.get();
}
@Test
public void testCreate() throws Exception {
controller.attach();
controller.create();
assertNotNull(activity.getFlow());
public void testShouldBeFirstTimeWizardByDefault() throws Exception {
assertEquals(Wizard.FIRST_TIME_WIZARD, activity.getFlow().getName());
}
@Test
public void testShouldBeFirstStep() throws Exception {
assertNotNull(activity.getStep());
assertEquals(activity.getFlow().getFirstStep(), activity.getStep());
}
activity.setStep(WizardStep.choose_mode);
@Test
public void testShouldSaveState() throws Exception {
activity.setStep(choose_mode);
final Bundle outState = new Bundle();
controller.saveInstanceState(outState);
@ -56,8 +60,11 @@ public class CalculatorWizardActivityTest {
assertNotNull(activity.getFlow());
assertEquals(Wizard.FIRST_TIME_WIZARD, activity.getFlow().getName());
assertNotNull(activity.getStep());
assertEquals(WizardStep.choose_mode, activity.getStep());
assertEquals(choose_mode, activity.getStep());
}
@Test
public void testCreate() throws Exception {
final Intent intent = new Intent();
intent.setClass(activity, CalculatorWizardActivity.class);
intent.putExtra(CalculatorWizardActivity.FLOW, Wizard.DEFAULT_WIZARD_FLOW);
@ -78,31 +85,38 @@ public class CalculatorWizardActivityTest {
}
@Test
public void testFragment() throws Exception {
public void testShouldAddFirstFragment() throws Exception {
controller.create().start().resume();
final FragmentManager fm = activity.getSupportFragmentManager();
Fragment f = fm.findFragmentByTag(WizardStep.welcome.getFragmentTag());
Assert.assertNotNull(f);
Assert.assertTrue(f.isAdded());
final Fragment f = fm.findFragmentByTag(WizardStep.welcome.getFragmentTag());
assertNotNull(f);
assertTrue(f.isAdded());
}
activity.setStep(WizardStep.choose_mode);
@Test
public void testShouldAddStepFragment() throws Exception {
controller.create().start().resume();
f = fm.findFragmentByTag(WizardStep.choose_mode.getFragmentTag());
Assert.assertNotNull(f);
Assert.assertTrue(f.isAdded());
final FragmentManager fm = activity.getSupportFragmentManager();
activity.setStep(choose_mode);
final Fragment f = fm.findFragmentByTag(choose_mode.getFragmentTag());
assertNotNull(f);
assertTrue(f.isAdded());
}
@Test
public void testSetStep() throws Exception {
controller.create();
activity.setStep(WizardStep.choose_mode);
activity.setStep(choose_mode);
assertEquals(choose_mode, activity.getStep());
}
@Test
public void testStartWizard() throws Exception {
public void testShouldStartWizardActivityAfterStart() throws Exception {
final ShadowActivity shadowActivity = Robolectric.shadowOf(controller.get());
CalculatorWizardActivity.startWizard(Wizard.DEFAULT_WIZARD_FLOW, shadowActivity.getApplicationContext());
Assert.assertNotNull(shadowActivity.getNextStartedActivity());
startWizard(Wizard.DEFAULT_WIZARD_FLOW, shadowActivity.getApplicationContext());
assertNotNull(shadowActivity.getNextStartedActivity());
}
}

View File

@ -191,7 +191,7 @@
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>4.0.1.2</version>
<version>4.1.1.4</version>
<scope>provided</scope>
</dependency>