1.1 --- a/isac-java/src/java-tests/isac/gui/mawen/TestWorksheetForMawen.java Thu Apr 21 14:00:43 2016 +0200
1.2 +++ b/isac-java/src/java-tests/isac/gui/mawen/TestWorksheetForMawen.java Tue Apr 26 17:18:09 2016 +0200
1.3 @@ -16,18 +16,22 @@
1.4 import isac.gui.IToWorksheetUser;
1.5 import isac.gui.Worksheet;
1.6 import isac.interfaces.ICalcElement;
1.7 +import isac.interfaces.ICalcIterator;
1.8 import isac.useractions.EUIContext;
1.9 import isac.useractions.EUIElement;
1.10 import isac.useractions.IUIAction;
1.11 import isac.useractions.UIAction;
1.12 import isac.useractions.UIActionOnCalcElement;
1.13 import isac.users.UserLanguage;
1.14 +import isac.util.CalcChanged;
1.15 import isac.util.formulae.CalcElement;
1.16 import isac.util.formulae.CalcFormula;
1.17 import isac.util.formulae.Formula;
1.18 import isac.util.formulae.Position;
1.19 +import isac.wsdialog.DialogIterator;
1.20 import isac.wsdialog.DialogProtocolException;
1.21 import isac.wsdialog.IWorksheetDialog;
1.22 +import isac.wsdialog.MockDialogIteratorSIMPLIFY;
1.23 import isac.wsdialog.WorksheetDialog;
1.24
1.25 import java.awt.BorderLayout;
1.26 @@ -45,6 +49,7 @@
1.27 import java.beans.PropertyVetoException;
1.28 import java.rmi.RemoteException;
1.29 import java.util.HashMap;
1.30 +import java.util.Vector;
1.31
1.32 import javax.swing.JButton;
1.33 import javax.swing.JDesktopPane;
1.34 @@ -252,9 +257,103 @@
1.35 frame_.setCursor(Cursor.getDefaultCursor());
1.36 }
1.37
1.38 - /* TODO */
1.39 + /* protocol of building testWorksheetIsac (below): getFormulaeFromTo */
1.40 + public void testModDialogIterator1() {
1.41 + System.out.println("/--BEGIN isac.gui.mawen.testModDialogIterator1");
1.42 +
1.43 + Vector<Integer> p = new Vector<Integer>(); p.add(1);
1.44 + Position pos = new Position(p, "Res");
1.45 + ICalcIterator from = new MockDialogIteratorSIMPLIFY(pos);
1.46 + p = new Vector<Integer>(); p.add(2);
1.47 + pos = new Position(p, "Res");
1.48 + ICalcIterator to = new MockDialogIteratorSIMPLIFY(pos);
1.49 +
1.50 + Vector<CalcFormula> fs = null;
1.51 + try { // in the test NO rmi is involved
1.52 + fs = from.getFormulaeFromTo(to, 0, false);
1.53 + } catch (RemoteException e) {
1.54 + e.printStackTrace();
1.55 + }
1.56 + assertEquals(fs.get(0).getPosition().toSMLString(), "([2],Res)");
1.57 +
1.58 + // -------------------------------------------------------------------
1.59 + p = new Vector<Integer>(); p.add(1);
1.60 + pos = new Position(p, "Frm");
1.61 + from = new MockDialogIteratorSIMPLIFY(pos);
1.62 + p = new Vector<Integer>(); p.add(2);
1.63 + pos = new Position(p, "Res");
1.64 + to = new MockDialogIteratorSIMPLIFY(pos);
1.65 +
1.66 + fs = null;
1.67 + try { // in the test NO rmi is involved
1.68 + fs = from.getFormulaeFromTo(to, 0, false);
1.69 + } catch (RemoteException e) {
1.70 + e.printStackTrace();
1.71 + }
1.72 + assertEquals(fs.get(0).getPosition().toSMLString(), "([1],Res)");
1.73 + assertEquals(fs.get(1).getPosition().toSMLString(), "([2],Res)");
1.74 +
1.75 + System.out.println("\\--END isac.gui.mawen.testModDialogIterator1");
1.76 + }
1.77 +
1.78 + /* protocol of building testWorksheetIsac (below): CalcChanged */
1.79 + public void testModDialogIterator2() {
1.80 + System.out.println("/--BEGIN isac.gui.mawen.testModDialogIterator2");
1.81 +
1.82 + Vector<Integer> p = new Vector<Integer>();
1.83 + Position pos = new Position(p, "Pbl");
1.84 + ICalcIterator ci = new MockDialogIteratorSIMPLIFY(pos);
1.85 +
1.86 + CalcChanged e = new CalcChanged(4711, false, ci, ci, ci);
1.87 + ICalcIterator from = e.getLastUnchangedFormula();
1.88 + ICalcIterator del = e.getLastDeletedFormula();
1.89 + ICalcIterator to = e.getLastGeneratedFormula();
1.90 +
1.91 + Vector<CalcFormula> fs = null;
1.92 + try {
1.93 + fs = from.getFormulaeFromTo(to, 0, false);
1.94 + } catch (RemoteException e1) {
1.95 + // TODO Auto-generated catch block
1.96 + e1.printStackTrace();
1.97 + }
1.98 + assertEquals(fs.size(), 1);
1.99 + assertEquals(fs.get(0).getPosition().toSMLString(), "([],Pbl)");
1.100 + assertEquals(fs.get(0).getFormula().toSMLString(), "Simplify (1 + (2 * x * (y + 3)) / (4 * z * (y + 3)) + 5)");
1.101 +
1.102 + // -------------------------------------------------------------------
1.103 + p = new Vector<Integer>(); p.add(1);
1.104 + pos = new Position(p, "Res");
1.105 + ICalcIterator unc = new MockDialogIteratorSIMPLIFY(pos);
1.106 + p = new Vector<Integer>(); p.add(2);
1.107 + pos = new Position(p, "Res");
1.108 + ICalcIterator gen = new MockDialogIteratorSIMPLIFY(pos);
1.109 +
1.110 + e = new CalcChanged(4711, false, unc, unc, gen);
1.111 + from = e.getLastUnchangedFormula();
1.112 + del = e.getLastDeletedFormula();
1.113 + to = e.getLastGeneratedFormula();
1.114 +
1.115 + fs = null;
1.116 + try {
1.117 + fs = from.getFormulaeFromTo(to, 0, false);
1.118 + } catch (RemoteException e1) {
1.119 + e1.printStackTrace();
1.120 + }
1.121 + System.out.println(fs.size());
1.122 + System.out.println(fs.get(0).getPosition().toSMLString());
1.123 + System.out.println(fs.get(0).getFormula().toSMLString());
1.124 +
1.125 + assertEquals(fs.size(), 1);
1.126 + assertEquals(fs.get(0).getPosition().toSMLString(), "([2],Res)");
1.127 + assertEquals(fs.get(0).getFormula().toSMLString(), "1 + x / (2 * z) + 5");
1.128 +
1.129 +
1.130 + System.out.println("\\--END isac.gui.mawen.testModDialogIterator2");
1.131 + }
1.132 +
1.133 + /* display example for reference in a Worksheet */
1.134 public void testWorksheetIsac() {
1.135 - System.out.println("/--BEGIN isac.gui.mawen.testWorksheetIsac");
1.136 + System.out.println("/--BEGIN isac.gui.mawen.testWorksheetIsac");
1.137
1.138 frame_ = constructorWindowApplication();
1.139 startApplication(/* windowApplication */);
1.140 @@ -282,4 +381,5 @@
1.141 }
1.142 System.out.println("\\--END isac.gui.mawen.testWorksheetIsac");
1.143 }
1.144 +
1.145 }
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/isac-java/src/java-tests/isac/wsdialog/MockCalcTreeSIMPLIFY.java Tue Apr 26 17:18:09 2016 +0200
2.3 @@ -0,0 +1,74 @@
2.4 +package isac.wsdialog;
2.5 +
2.6 +import isac.util.formulae.CalcFormula;
2.7 +import isac.util.formulae.Formula;
2.8 +import isac.util.formulae.Position;
2.9 +
2.10 +import java.util.HashMap;
2.11 +import java.util.Vector;
2.12 +
2.13 +/*
2.14 + * a specific calculation ("example for reference")
2.15 + * for retrieval by <code>MockDialogIteratorSIMPLIFY</code>.
2.16 + */
2.17 +public class MockCalcTreeSIMPLIFY {
2.18 +
2.19 + Vector<CalcFormula> calc_tree_ = new Vector();
2.20 +
2.21 + public MockCalcTreeSIMPLIFY() {
2.22 + // INVARIANT ON THE SEQUENCE BELOW: pos.compareTo(next_pos) = -1
2.23 +
2.24 + //-->ISA: getFormulaeFromTo 1 ([],Pbl) ([],Pbl) 0 false;
2.25 + //<--ISA: "Simplify (1 + (2 * x * (y + 3)) / (4 * z * (y + 3)) + 5)"
2.26 + Vector<Integer> p = new Vector<Integer>();
2.27 + Position pos = new Position(p, "Pbl");
2.28 + Formula form = new Formula("Simplify (1 + (2 * x * (y + 3)) / (4 * z * (y + 3)) + 5)");
2.29 + calc_tree_.add(new CalcFormula(pos, form));
2.30 +
2.31 + // getFormulaeFromTo will need ([],Met):
2.32 + p = new Vector<Integer>();
2.33 + pos = new Position(p, "Met");
2.34 + form = new Formula("Simplify (1 + (2 * x * (y + 3)) / (4 * z * (y + 3)) + 5)");
2.35 + calc_tree_.add(new CalcFormula(pos, form));
2.36 +
2.37 + //-->ISA: getFormulaeFromTo 1 ([],Met) ([1],Frm) 0 false;
2.38 + //<--ISA: "1 + (2 * x * (y + 3)) / (4 * z * (y + 3)) + 5"
2.39 + p = new Vector<Integer>(); p.add(1);
2.40 + pos = new Position(p, "Frm");
2.41 + form = new Formula("1 + (2 * x * (y + 3)) / (4 * z * (y + 3)) + 5");
2.42 + calc_tree_.add(new CalcFormula(pos, form));
2.43 +
2.44 + //-->ISA: getFormulaeFromTo 1 ([1],Frm) ([1],Res) 0 false;
2.45 + //<--ISA: "1 + (2 * x) / (4 * z) + 5"
2.46 + p = new Vector<Integer>(); p.add(1);
2.47 + pos = new Position(p, "Res");
2.48 + form = new Formula("1 + (2 * x) / (4 * z) + 5");
2.49 + calc_tree_.add(new CalcFormula(pos, form));
2.50 +
2.51 + //-->ISA: getFormulaeFromTo 1 ([1],Res) ([2],Res) 0 false;
2.52 + //<--ISA: "1 + x / (2 * z) + 5"
2.53 + p = new Vector<Integer>(); p.add(2);
2.54 + pos = new Position(p, "Res");
2.55 + form = new Formula("1 + x / (2 * z) + 5");
2.56 + calc_tree_.add(new CalcFormula(pos, form));
2.57 +
2.58 + //-->ISA: getFormulaeFromTo 1 ([2],Res) ([3],Res) 0 false;
2.59 + //<--ISA: "6 + x / (2 * z)"
2.60 + p = new Vector<Integer>(); p.add(3);
2.61 + pos = new Position(p, "Res");
2.62 + form = new Formula("6 + x / (2 * z)");
2.63 + calc_tree_.add(new CalcFormula(pos, form));
2.64 + }
2.65 +
2.66 + public Formula get(Position pos) {
2.67 + int i = 0;
2.68 + while (calc_tree_.elementAt(i).getPosition().compareTo(pos) != 0) {
2.69 + i = i + 1;
2.70 + }
2.71 + return calc_tree_.elementAt(i).getFormula();
2.72 + }
2.73 +
2.74 + public Vector<CalcFormula> getTree() {
2.75 + return calc_tree_;
2.76 + }
2.77 +}
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/isac-java/src/java-tests/isac/wsdialog/MockDialogIteratorSIMPLIFY.java Tue Apr 26 17:18:09 2016 +0200
3.3 @@ -0,0 +1,266 @@
3.4 +package isac.wsdialog;
3.5 +
3.6 +import java.rmi.RemoteException;
3.7 +import java.util.HashMap;
3.8 +import java.util.Iterator;
3.9 +import java.util.Map;
3.10 +import java.util.Vector;
3.11 +
3.12 +import isac.interfaces.ICalcElement;
3.13 +import isac.interfaces.ICalcIterator;
3.14 +import isac.util.formulae.Assumptions;
3.15 +import isac.util.formulae.CalcFormula;
3.16 +import isac.util.formulae.CalcHead;
3.17 +import isac.util.formulae.Context;
3.18 +import isac.util.formulae.ContextMethod;
3.19 +import isac.util.formulae.ContextProblem;
3.20 +import isac.util.formulae.ContextTheory;
3.21 +import isac.util.formulae.Formula;
3.22 +import isac.util.formulae.Match;
3.23 +import isac.util.formulae.MethodID;
3.24 +import isac.util.formulae.Position;
3.25 +import isac.util.formulae.ProblemID;
3.26 +import isac.util.tactics.Tactic;
3.27 +import isac.wsdialog.IContextProvider.ContextType;
3.28 +
3.29 +public class MockDialogIteratorSIMPLIFY implements ICalcIterator {
3.30 +
3.31 + Position pos_;
3.32 +
3.33 + public MockDialogIteratorSIMPLIFY(Position pos) {
3.34 + pos_ = pos;
3.35 + }
3.36 +
3.37 + @Override
3.38 + public Position getPosition() throws RemoteException {
3.39 + return pos_;
3.40 + }
3.41 +
3.42 + @Override
3.43 + public boolean moveRoot() throws RemoteException {
3.44 + // TODO Auto-generated method stub
3.45 + return false;
3.46 + }
3.47 +
3.48 + @Override
3.49 + public boolean moveCalcHead() throws RemoteException {
3.50 + // TODO Auto-generated method stub
3.51 + return false;
3.52 + }
3.53 +
3.54 + @Override
3.55 + public boolean moveUp() throws RemoteException {
3.56 + // TODO Auto-generated method stub
3.57 + return false;
3.58 + }
3.59 +
3.60 + @Override
3.61 + public boolean moveDown() throws RemoteException {
3.62 + // TODO Auto-generated method stub
3.63 + return false;
3.64 + }
3.65 +
3.66 + @Override
3.67 + public boolean moveLevelUp() throws RemoteException {
3.68 + // TODO Auto-generated method stub
3.69 + return false;
3.70 + }
3.71 +
3.72 + @Override
3.73 + public boolean moveLevelDown() throws RemoteException {
3.74 + // TODO Auto-generated method stub
3.75 + return false;
3.76 + }
3.77 +
3.78 + @Override
3.79 + public boolean moveFormula() throws RemoteException {
3.80 + // TODO Auto-generated method stub
3.81 + return false;
3.82 + }
3.83 +
3.84 + @Override
3.85 + public boolean isLast() throws RemoteException {
3.86 + // TODO Auto-generated method stub
3.87 + return false;
3.88 + }
3.89 +
3.90 + @Override
3.91 + public boolean onCalcHead() throws RemoteException {
3.92 + // TODO Auto-generated method stub
3.93 + return false;
3.94 + }
3.95 +
3.96 + @Override
3.97 + public boolean onEndOfCalculation() throws RemoteException {
3.98 + // TODO Auto-generated method stub
3.99 + return false;
3.100 + }
3.101 +
3.102 + @Override
3.103 + public boolean switchToGuard() throws RemoteException {
3.104 + // TODO Auto-generated method stub
3.105 + return false;
3.106 + }
3.107 +
3.108 + @Override
3.109 + public boolean switchToModel() throws RemoteException {
3.110 + // TODO Auto-generated method stub
3.111 + return false;
3.112 + }
3.113 +
3.114 + @Override
3.115 + public ICalcElement getElement() throws RemoteException {
3.116 + // TODO Auto-generated method stub
3.117 + return null;
3.118 + }
3.119 +
3.120 + @Override
3.121 + public Vector<CalcFormula> getFormulaeFromTo(ICalcIterator iterator_to, Integer level,
3.122 + boolean result_includes_tactics) throws RemoteException {
3.123 +
3.124 + MockCalcTreeSIMPLIFY c = new MockCalcTreeSIMPLIFY();
3.125 + Vector<CalcFormula> ct = c.getTree();
3.126 + Vector<CalcFormula> from_to = new Vector();
3.127 +
3.128 + Position pfrom = this.getPosition();
3.129 + Position pto = iterator_to.getPosition();
3.130 +
3.131 + CalcFormula f = null; int i = 0;
3.132 + if (pto.getIntList().size() != 0) {
3.133 + // iterate to start Position
3.134 + while (ct.elementAt(i).getPosition().compareTo(pfrom) != 1) {
3.135 + i = i + 1;
3.136 + }
3.137 + }
3.138 + // iterate from start Position to iterator_to
3.139 + while (ct.elementAt(i).getPosition().compareTo(pto) == -1) {
3.140 + from_to.add(ct.elementAt(i));
3.141 + i = i + 1;
3.142 + }
3.143 + from_to.add(ct.elementAt(i));
3.144 + return from_to;
3.145 + }
3.146 +
3.147 + @Override
3.148 + public ICalcElement getFormula() throws RemoteException {
3.149 + // TODO Auto-generated method stub
3.150 + return null;
3.151 + }
3.152 +
3.153 + @Override
3.154 + public Tactic getTactic() throws RemoteException {
3.155 + // TODO Auto-generated method stub
3.156 + return null;
3.157 + }
3.158 +
3.159 + @Override
3.160 + public Vector getApplicableTactics(int scope) throws RemoteException {
3.161 + // TODO Auto-generated method stub
3.162 + return null;
3.163 + }
3.164 +
3.165 + @Override
3.166 + public Assumptions getAssumptions() throws RemoteException {
3.167 + // TODO Auto-generated method stub
3.168 + return null;
3.169 + }
3.170 +
3.171 + @Override
3.172 + public Assumptions getAccumulatedAssumptions() throws RemoteException {
3.173 + // TODO Auto-generated method stub
3.174 + return null;
3.175 + }
3.176 +
3.177 + @Override
3.178 + public int getLevel() throws RemoteException {
3.179 + // TODO Auto-generated method stub
3.180 + return 0;
3.181 + }
3.182 +
3.183 + @Override
3.184 + public ICalcIterator cloneIterator() throws RemoteException {
3.185 + // TODO Auto-generated method stub
3.186 + return null;
3.187 + }
3.188 +
3.189 + @Override
3.190 + public int compareToIterator(ICalcIterator compare) throws RemoteException {
3.191 + // TODO Auto-generated method stub
3.192 + return 0;
3.193 + }
3.194 +
3.195 + @Override
3.196 + public String toSMLString() throws RemoteException {
3.197 + // TODO Auto-generated method stub
3.198 + return null;
3.199 + }
3.200 +
3.201 + @Override
3.202 + public Match initMatchProblem() throws RemoteException {
3.203 + // TODO Auto-generated method stub
3.204 + return null;
3.205 + }
3.206 +
3.207 + @Override
3.208 + public Match tryMatchProblem(ProblemID problemID) throws RemoteException {
3.209 + // TODO Auto-generated method stub
3.210 + return null;
3.211 + }
3.212 +
3.213 + @Override
3.214 + public Match tryRefineProblem(ProblemID problemID) throws RemoteException {
3.215 + // TODO Auto-generated method stub
3.216 + return null;
3.217 + }
3.218 +
3.219 + @Override
3.220 + public Match initMatchMethod() throws RemoteException {
3.221 + // TODO Auto-generated method stub
3.222 + return null;
3.223 + }
3.224 +
3.225 + @Override
3.226 + public Match tryMatchMethod(MethodID methodID) throws RemoteException {
3.227 + // TODO Auto-generated method stub
3.228 + return null;
3.229 + }
3.230 +
3.231 + @Override
3.232 + public Context initContext(ContextType type) throws RemoteException {
3.233 + // TODO Auto-generated method stub
3.234 + return null;
3.235 + }
3.236 +
3.237 + @Override
3.238 + public Context checkContext(Context context2check) throws RemoteException {
3.239 + // TODO Auto-generated method stub
3.240 + return null;
3.241 + }
3.242 +
3.243 + @Override
3.244 + public Context refineProblem(Context context2refine) throws RemoteException {
3.245 + // TODO Auto-generated method stub
3.246 + return null;
3.247 + }
3.248 +
3.249 + @Override
3.250 + public CalcHead setContext(ContextProblem context2set)
3.251 + throws RemoteException {
3.252 + // TODO Auto-generated method stub
3.253 + return null;
3.254 + }
3.255 +
3.256 + @Override
3.257 + public CalcHead setContext(ContextMethod context2set)
3.258 + throws RemoteException {
3.259 + // TODO Auto-generated method stub
3.260 + return null;
3.261 + }
3.262 +
3.263 + @Override
3.264 + public void setContext(ContextTheory context2set) throws RemoteException {
3.265 + // TODO Auto-generated method stub
3.266 +
3.267 + }
3.268 +
3.269 +}
4.1 --- a/isac-java/src/java/isac/util/formulae/Position.java Thu Apr 21 14:00:43 2016 +0200
4.2 +++ b/isac-java/src/java/isac/util/formulae/Position.java Tue Apr 26 17:18:09 2016 +0200
4.3 @@ -103,6 +103,10 @@
4.4 /*
4.5 * WN040909 surprising complicated order for isac's tree-structure as impl.
4.6 * in SML
4.7 + * WN160426 order on Position:
4.8 + * pos1.compareTo(pos2) --> 1: pos1 > pos2
4.9 + * pos1.compareTo(pos2) --> 0: pos1 = pos2
4.10 + * pos1.compareTo(pos2) --> -1: pos1 < pos2
4.11 *
4.12 * @see java.lang.Comparable#compareTo(java.lang.Object) Position is used as
4.13 * key in ...
5.1 --- a/isac-java/src/java/isac/wsdialog/DialogIterator.java Thu Apr 21 14:00:43 2016 +0200
5.2 +++ b/isac-java/src/java/isac/wsdialog/DialogIterator.java Tue Apr 26 17:18:09 2016 +0200
5.3 @@ -15,6 +15,7 @@
5.4 import isac.interfaces.ICalcElement;
5.5 import isac.interfaces.ICalcIterator;
5.6 import isac.util.formulae.Assumptions;
5.7 +import isac.util.formulae.CalcFormula;
5.8 import isac.util.formulae.CalcHead;
5.9 import isac.util.formulae.Context;
5.10 import isac.util.formulae.ContextMethod;
5.11 @@ -247,7 +248,7 @@
5.12 * @see isac.interfaces.ICalcIterator#getFormulaeFromTo(ICalcIterator,
5.13 * ICalcIterator, Integer, boolean)
5.14 */
5.15 - public Vector getFormulaeFromTo(ICalcIterator to, Integer level,
5.16 + public Vector<CalcFormula> getFormulaeFromTo(ICalcIterator to, Integer level,
5.17 boolean tacs_too) {
5.18 Vector elems = null;
5.19 try {