1.1 --- a/src/java-tests/isac/bridge/TestModel.java Mon Jun 27 15:01:06 2005 +0200
1.2 +++ b/src/java-tests/isac/bridge/TestModel.java Mon Jun 27 18:12:55 2005 +0200
1.3 @@ -21,6 +21,7 @@
1.4 import isac.util.interfaces.IToCalc;
1.5 import isac.util.interfaces.IToUser;
1.6 import isac.util.parser.FormalizationDigest;
1.7 +import isac.util.tactics.SimpleTactic;
1.8 import isac.util.tactics.StringListTactic;
1.9 import isac.util.tactics.Tactic;
1.10
1.11 @@ -40,187 +41,259 @@
1.12 */
1.13 public class TestModel extends TestCase {
1.14
1.15 - /**
1.16 - * test match and refine with x^^^2 + 4*x + 5 = 2
1.17 - * sml/systest/FE-interface.sml --- tryMatchProblem, tryRefineProblem ---
1.18 + Formalization fmz_;
1.19 +
1.20 + MathEngine me_;
1.21 +
1.22 + /*
1.23 + * @see TestCase#setUp()
1.24 */
1.25 - public void testMatchRefine() throws Exception {
1.26 - System.out.println("---BEGIN isac.bridge.TestModel#testMatchRefine");
1.27 -
1.28 + protected void setUp() throws Exception {
1.29 + super.setUp();
1.30 //load the file of the example,
1.31 //see TestKEStoreServices#testLoadContentMinisubpbl
1.32 KEStoreServices ks = new KEStoreServices("isac/xmldata");
1.33 - Vector vec = ks.loadContent("exp", "exp_IsacCore_Tests_1d.xml");
1.34 + Vector vec = ks.loadContent("exp", "exp_IsacCore_Tests_7a.xml");
1.35 + //parse out the Formalization
1.36 + //see TestFormalizationDigest#testParseExplMini
1.37 + String xmlstr = (String) vec.firstElement();
1.38 + FormalizationDigest fd = new FormalizationDigest();
1.39 + fmz_ = fd.parseFormalization((String) xmlstr);
1.40 +
1.41 + MathEngine.init("localhost");
1.42 + me_ = MathEngine.getMathEngine();
1.43 + }
1.44 +
1.45 + /**
1.46 + * interactively complete the Model by using the <NEXT>button;; direct calls
1.47 + * of the math-engine
1.48 + */
1.49 + public void testAddItems() throws Exception {
1.50 + System.out.println("---BEGIN isac.bridge.TestModel#testAddItems");
1.51 +
1.52 + //start the calculation
1.53 + IToCalc ct = me_.startCalculation(fmz_);
1.54 + IToUser user = new MockIToUser();
1.55 + ct.addDataChangeListener(user);
1.56 + CalcChangedEvent cce = null;
1.57 + ICalcIterator ci = ct.getActiveFormula();
1.58 + CalcHead ch = null;
1.59 + System.out.println(".end step_a-----");
1.60 + //end step_a ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1.61 +
1.62 + //fill the Models Items with Descriptions for userguidance:
1.63 + //tac = Model_Problem ...
1.64 + ct.autoCalculate(IToCalc.SCOPE_CALCULATION, 1);
1.65 + ch = (CalcHead) ci.getElement();
1.66 + assertEquals(ch.getModel().getGiven().toString(),
1.67 + "[\"incomplete fixedValues []\"]");
1.68 + System.out.println(".end step_b-----");
1.69 + //end step_b ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1.70 +
1.71 + //fill the Models Items stepwise with the <Next>-button
1.72 + ct.autoCalculate(IToCalc.SCOPE_CALCULATION, 1);
1.73 + ch = (CalcHead) ci.getElement();
1.74 + assertEquals(ch.getModel().getGiven().toString(),
1.75 + "[\"correct fixedValues [r = Arbfix]\"]");
1.76 + //and so on...
1.77 + ct.autoCalculate(IToCalc.SCOPE_CALCULATION, 1);
1.78 + ct.autoCalculate(IToCalc.SCOPE_CALCULATION, 1);
1.79 + //lists are filled elementwise:
1.80 + ch = (CalcHead) ci.getElement();
1.81 + assertEquals(
1.82 + ch.getModel().getFind().getItems().elementAt(1).toString(),
1.83 + "incomplete valuesFor [a]");
1.84 + ct.autoCalculate(IToCalc.SCOPE_CALCULATION, 1);
1.85 + ch = (CalcHead) ci.getElement();
1.86 + assertEquals(
1.87 + ch.getModel().getFind().getItems().elementAt(1).toString(),
1.88 + "correct valuesFor [a, b]");
1.89 + ct.autoCalculate(IToCalc.SCOPE_CALCULATION, 1);
1.90 + ct.autoCalculate(IToCalc.SCOPE_CALCULATION, 1);
1.91 + ch = (CalcHead) ci.getElement();
1.92 + System.out.println(ch.getModel().toString());
1.93 + //now the Model is complete; for completing the CalcHead by completing
1.94 + // the Specification see testEditItems
1.95 + System.out.println(".end step_c-----");
1.96 + //end step_c ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1.97 +
1.98 + System.out.println("---END isac.bridge.TestModel#testAddItems");
1.99 + }
1.100 +
1.101 + /**
1.102 + * {\bf\UC{Having \isac{} Complete the
1.103 + * CalcHead}\label{SPECIFY:COMPLETE:all}\\} The user requests a CalcHead,
1.104 + * containing some input, to be completed automatically. WN0506 What kind of
1.105 + * messed input should be overwritten/corredted ???
1.106 + *
1.107 + * @see isac.functest.specify.TestModel#testCompleteCalcHead() for how this
1.108 + * looks like on the CalcHeadPanel
1.109 + */
1.110 + public void testCompleteCalcHead() throws Exception {
1.111 + System.out
1.112 + .println("---BEGIN isac.bridge.TestModel#testCompleteCalcHead");
1.113 +
1.114 + //start the calculation
1.115 + IToCalc ct = me_.startCalculation(fmz_);
1.116 + IToUser user = new MockIToUser();
1.117 + ct.addDataChangeListener(user);
1.118 + CalcChangedEvent cce = null;
1.119 + ICalcIterator ci = ct.getActiveFormula();
1.120 + CalcHead ch = null;
1.121 + System.out.println(".end step_a-----");
1.122 + //end step_a ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1.123 +
1.124 + //complete the CalcHead with ONE SPECIAL BUTTON ...
1.125 + ct.completeCalcHead();
1.126 + ch = (CalcHead) ci.getElement();
1.127 + //the model is complete
1.128 + assertEquals(ch.getModel().getGiven().getItems().elementAt(0)
1.129 + .toString(), "correct fixedValues [r = Arbfix]");
1.130 + assertEquals(
1.131 + ch.getModel().getFind().getItems().elementAt(0).toString(),
1.132 + "correct maximum A");
1.133 + assertEquals(
1.134 + ch.getModel().getFind().getItems().elementAt(1).toString(),
1.135 + "correct valuesFor [a, b]");
1.136 + assertEquals(ch.getModel().getRelate().getItems().elementAt(0)
1.137 + .toString(), "correct relations [A = a * b, "
1.138 + + "(a / 2) ^^^ 2 + (b / 2) ^^^ 2 = r ^^^ 2]");
1.139 + //the Specification is complete
1.140 + assertEquals(ch.getSpecification().toSMLString(), "\"DiffApp.thy\","
1.141 + + "[\"maximum_of\",\"function\"],"
1.142 + + "[\"DiffApp\",\"max_by_calculus\"]");
1.143 + System.out.println(".end step_b-----");
1.144 + //end step_b
1.145 + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1.146 + System.out.println("---END isac.bridge.TestModel#testCompleteCalcHead");
1.147 + }
1.148 +
1.149 + /**
1.150 + * complete the Model by hitting ONE SPECIFIC BUTTON. WN0506 What kind of
1.151 + * messed input should be overwritten/corredted ???
1.152 + *
1.153 + * @see isac.functest.specify.TestModel#testCompleteModel() for how this
1.154 + * looks like on the CalcHeadPanel
1.155 + */
1.156 + public void testCompleteModel() throws Exception {
1.157 + System.out.println("---BEGIN isac.bridge.TestModel#testCompleteModel");
1.158 +
1.159 + //start the calculation
1.160 + IToCalc ct = me_.startCalculation(fmz_);
1.161 + IToUser user = new MockIToUser();
1.162 + ct.addDataChangeListener(user);
1.163 + CalcChangedEvent cce = null;
1.164 + ICalcIterator ci = ct.getActiveFormula();
1.165 + CalcHead ch = null;
1.166 + System.out.println(".end step_a-----");
1.167 + //end step_a ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1.168 +
1.169 + //complete the Model with ONE SPECIAL BUTTON ...
1.170 + ct.autoCalculate(IToCalc.SCOPE_MODEL, 0);
1.171 + ch = (CalcHead) ci.getElement();
1.172 + assertEquals(ch.getModel().getGiven().getItems().elementAt(0)
1.173 + .toString(), "correct fixedValues [r = Arbfix]");
1.174 + assertEquals(
1.175 + ch.getModel().getFind().getItems().elementAt(0).toString(),
1.176 + "correct maximum A");
1.177 + assertEquals(
1.178 + ch.getModel().getFind().getItems().elementAt(1).toString(),
1.179 + "correct valuesFor [a, b]");
1.180 + assertEquals(ch.getModel().getRelate().getItems().elementAt(0)
1.181 + .toString(), "correct relations [A = a * b, "
1.182 + + "(a / 2) ^^^ 2 + (b / 2) ^^^ 2 = r ^^^ 2]");
1.183 + System.out.println(".end step_b-----");
1.184 + //end step_b
1.185 + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1.186 +
1.187 + System.out.println("---END isac.bridge.TestModel#testCompleteModel");
1.188 + }
1.189 +
1.190 + /**
1.191 + * complete the Model by manual input of the Items; any number of inputs;;
1.192 + * direct calls of the math-engine
1.193 + *
1.194 + * @see isac.functest.specify.TestModel#testEditItems() for how this looks
1.195 + * like on the CalcHeadPanel
1.196 + */
1.197 + public void testEditItems() throws Exception {
1.198 + System.out.println("---BEGIN isac.bridge.TestModel#testEditItems");
1.199 +
1.200 + //start the calculation
1.201 + IToCalc ct = me_.startCalculation(fmz_);
1.202 + IToUser user = new MockIToUser();
1.203 + ct.addDataChangeListener(user);
1.204 + CalcChangedEvent cce = null;
1.205 + ICalcIterator ci = ct.getActiveFormula();
1.206 + CalcHead ch = null;
1.207 + System.out.println(".end step_a-----");
1.208 + //end step_a ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1.209 +
1.210 + //TOOODO.WN050627 goon here
1.211 +
1.212 + System.out.println("---END isac.bridge.TestModel#testEditItems");
1.213 + }
1.214 +
1.215 + /**
1.216 + * {\bf\UC{Having \isac{} Complete One Field of the
1.217 + * Model}\label{SPECIFY:COMPLETE:modelone}\\}
1.218 + *
1.219 + * @see isac.functest.specify.TestModel#testCompleteOneFieldOfModel() for
1.220 + * how this looks like on the CalcHeadPanel
1.221 + *
1.222 + * related SML is not implemented; would also require the bridge to send the
1.223 + * Items' status from Java to SML
1.224 + */
1.225 + public void testCompleteOneFieldOfModel() throws Exception {
1.226 + System.out
1.227 + .println("---BEGIN isac.bridge.TestModel#testCompleteOneFieldOfModel");
1.228 + System.out.println("TODO");
1.229 + assertEquals("TODO", "TODO");
1.230 + System.out
1.231 + .println("---END isac.bridge.TestModel#testCompleteOneFieldOfModel");
1.232 + }
1.233 +
1.234 + /**
1.235 + * hit the 'Problems'-button on the front-end while the activeFormula is on
1.236 + * the Worksheet;; direct calls of the math-engine (and NOT on a
1.237 + * CalcHeadPanel)
1.238 + *
1.239 + * This testcase requires to run a different example as defined in the
1.240 + * setup.
1.241 + */
1.242 + public void testKBfromWorksheet() throws Exception {
1.243 + System.out
1.244 + .println("---BEGIN isac.bridge.TestBridgeSpecify#testKBfromWorksheet");
1.245 + //load the file of the example,
1.246 + //see TestKEStoreServices#testLoadContentMinisubpbl
1.247 + KEStoreServices ks = new KEStoreServices("isac/xmldata");
1.248 + Vector vec = ks.loadContent("exp", "exp_IsacCore_Tests_1b.xml");
1.249 //parse out the Formalization
1.250 //see TestFormalizationDigest#testParseExplMini
1.251 String xmlstr = (String) vec.firstElement();
1.252 FormalizationDigest fd = new FormalizationDigest();
1.253 Formalization fmz = fd.parseFormalization((String) xmlstr);
1.254 - System.out.println(".end step_a-----");
1.255 - //end step_a ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1.256 -
1.257 //start the calculation
1.258 MathEngine.init("localhost");
1.259 MathEngine me = MathEngine.getMathEngine();
1.260 -
1.261 IToCalc ct = me.startCalculation(fmz);
1.262 IToUser user = new MockIToUser();
1.263 ct.addDataChangeListener(user);
1.264 CalcChangedEvent cce = null;
1.265 - System.out.println(".end step_b-----");
1.266 - //end step_b
1.267 - // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1.268 + ICalcIterator ci = ct.getActiveFormula();
1.269 + CalcHead ch = null;
1.270 + System.out.println(".end step_a-----");
1.271 + //end step_a ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1.272
1.273 - //fill the CalcHead with Descriptions by 2-times <NEXT>:
1.274 - //tac = Model_Problem ...
1.275 - ct.autoCalculate(IToCalc.SCOPE_CALCULATION, 1);
1.276 - //and one field: tac = Add_Given "equality (x ^^^ 2 + 4 * x + 5 = 2)"
1.277 - ct.autoCalculate(IToCalc.SCOPE_CALCULATION, 1);
1.278 - ICalcIterator ci = ct.getActiveFormula();
1.279 - //end step_c
1.280 - // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1.281 - //trymatch ... go into the problem-hierarchy with this CalcHeads Model
1.282 - //this Match will show some incomplete items
1.283 - ProblemID id = new ProblemID();
1.284 - id.addString("univariate");
1.285 - id.addString("equation");
1.286 - Match m = ci.tryMatchProblem(id);
1.287 - assertEquals(m.getHeadline().toSMLString(), "??.empty");//...TODO.WN050626
1.288 - assertEquals(m.getKEStoreID().toSMLString(),
1.289 - "[\"univariate\",\"equation\"]");
1.290 - assertEquals(m.getModel().getGiven().toString(),
1.291 - "[\"incomplete solveFor\", "
1.292 - + "\"correct equality (x ^^^ 2 + 4 * x + 5 = 2)\"]");
1.293 - assertEquals(m.getModel().getWhere().toString(),
1.294 - "[\"correct matches (?a = ?b) (x ^^^ 2 + 4 * x + 5 = 2)\"]");
1.295 - assertEquals(m.getModel().getFind().toString(),
1.296 - "[\"incomplete solutions []\"]");
1.297 - assertEquals(m.getModel().getRelate().toString(), "[]");
1.298 - assertEquals(m.getStatus(), "incorrect");
1.299 - //end step_d
1.300 - // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1.301 -
1.302 - //complete the CalcHeads Model in the Worksheet by 2-times <NEXT>:
1.303 - //tac = Add_Given "solveFor x"
1.304 - ct.autoCalculate(IToCalc.SCOPE_CALCULATION, 1);
1.305 - //tac = Add_Find "solutions L"
1.306 - ct.autoCalculate(IToCalc.SCOPE_CALCULATION, 1);
1.307 - //end step_e
1.308 - // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1.309 - //trymatch ... go into the problem-hierarchy with this CalcHeads Model
1.310 - //this Match will show all items complete:
1.311 - m = ci.tryMatchProblem(id);
1.312 - assertEquals(m.getHeadline().toSMLString(), "??.empty");//...TODO.WN050626
1.313 - assertEquals(m.getModel().getGiven().toString(),
1.314 - "[\"correct equality (x ^^^ 2 + 4 * x + 5 = 2)\", "
1.315 - + "\"correct solveFor x\"]");
1.316 - assertEquals(m.getModel().getFind().toString(),
1.317 - "[\"correct solutions L\"]");
1.318 - assertEquals(m.getStatus(), "incorrect");//the specification is
1.319 - // missing! TODO.WN0506 correct Match in SML !!!
1.320 + //complete the example and set the activeFormula somewhere on the
1.321 + // Worksheet
1.322 + ct.autoCalculate(IToCalc.SCOPE_CALCULATION, 0);
1.323 + //set the activeFormula within the root-problem
1.324
1.325 - //this _NOT_ a matching problem:
1.326 - id = new ProblemID();
1.327 - id.addString("linear");
1.328 - id.addString("univariate");
1.329 - id.addString("equation");
1.330 - m = ci.tryMatchProblem(id);
1.331 - assertEquals(
1.332 - m.getModel().getWhere().toString(),
1.333 - "[\"false False\", "//WN050626 this seems to be for SMLtesting
1.334 - + "\"correct ~ lhs (x ^^^ 2 + 4 * x + 5 = 2) is_polyrat_in x\", "
1.335 - + "\"correct ~ rhs (x ^^^ 2 + 4 * x + 5 = 2) is_polyrat_in x\", "
1.336 - + "\"false lhs (x ^^^ 2 + 4 * x + 5 = 2) has_degree_in x = 1\", "
1.337 - + "\"false rhs (x ^^^ 2 + 4 * x + 5 = 2) has_degree_in x = 1\"]");
1.338 - //end step_f
1.339 - // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1.340 -
1.341 - //search for a matching problem in the problem-hierarchy:
1.342 - //this search _FAILES_ because refine does _NOT_ return a new ProblemID
1.343 - m = ci.tryRefineProblem(id);
1.344 - assertEquals(m.getKEStoreID().toSMLString(),
1.345 - "[\"linear\",\"univariate\",\"equation\"]");
1.346 - //this search is _SUCCESSFUL_ because it returns a _NEW_ ProblemID
1.347 - //(and in this case the Model will _ALWAYS_ be "correct"!)
1.348 - id = new ProblemID();
1.349 - id.addString("univariate");
1.350 - id.addString("equation");
1.351 - m = ci.tryRefineProblem(id);
1.352 - assertEquals(m.getKEStoreID().toSMLString(),
1.353 - "[\"normalize\",\"polynomial\",\"univariate\",\"equation\"]");
1.354 - //end step_g
1.355 - // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1.356 -
1.357 - //transfer the problem found back to the Worksheet
1.358 - Vector keylist = new Vector();
1.359 - keylist.add("normalize");
1.360 - keylist.add("polynomial");
1.361 - keylist.add("univariate");
1.362 - keylist.add("equation");
1.363 - Tactic tac = new StringListTactic("Specify_Problem", keylist);
1.364 - ct.setNextTactic(tac);
1.365 - //ct.autoCalculate(IToCalc.SCOPE_CALCULATION, 1);
1.366 - //TODO.WN0506 ... still implicit in setNextTactic
1.367 - CalcHead ch = (CalcHead) ci.getElement();
1.368 - //FIXXME.WN050426 in the CalcHead above the Problem should be set !!!
1.369 - //and the calchead_status_ should be still "incomplete" due to
1.370 - // ..incomplete specification (theory, method missing)
1.371 - //after inserting Theory and Method the CalcHead is complete:
1.372 - ct.autoCalculate(IToCalc.SCOPE_CALCULATION, 1);
1.373 - ct.autoCalculate(IToCalc.SCOPE_CALCULATION, 1);
1.374 - ch = (CalcHead) ci.getElement();
1.375 - assertEquals(ch.getStatusString(), "correct");
1.376 -
1.377 - System.out.println("---END isac.bridge.TestModel#testMatchRefine");
1.378 +
1.379 +
1.380 + System.out
1.381 + .println("---END isac.bridge.TestBridgeSpecify#testKBfromWorksheet");
1.382 }
1.383
1.384 - // /**
1.385 - // * demonstrate steps of interactive specification by using the <NEXT>
1.386 - // * button;; direct calls of the math-engine
1.387 - // */
1.388 - // public void testAddItems() throws Exception {
1.389 - // System.out
1.390 - // .println("---BEGIN isac.bridge.TestModel#testAddItems");
1.391 - // System.out.println("---END isac.bridge.TestModel#testAddItems");
1.392 - // }
1.393 - //
1.394 - // /**
1.395 - // * demonstrate steps of interactive specification by user input;; direct
1.396 - // * calls of the math-engine
1.397 - // */
1.398 - // public void testEditItems() throws Exception {
1.399 - // System.out
1.400 - // .println("---BEGIN isac.bridge.TestModel#testEditItems");
1.401 - // System.out
1.402 - // .println("---END isac.bridge.TestModel#testEditItems");
1.403 - // }
1.404 - //
1.405 - // public void testCompleteModel() {
1.406 - // System.out
1.407 - // .println("---BEGIN isac.bridge.TestModel#testCompleteModel");
1.408 - // System.out.println("TODO");
1.409 - // assertEquals("TODO", "TODO");
1.410 - // System.out.println("---END isac.bridge.TestModel#testCompleteModel");
1.411 - // }
1.412 - //
1.413 - // public void testCompleteOneFieldOfModel() {
1.414 - // System.out
1.415 - // .println("---BEGIN isac.bridge.TestModel#testCompleteOneFieldOfModel");
1.416 - // System.out.println("TODO");
1.417 - // assertEquals("TODO", "TODO");
1.418 - // System.out
1.419 - // .println("---END isac.bridge.TestModel#testCompleteOneFieldOfModel");
1.420 - // }
1.421 - //
1.422 - // /**
1.423 - // * demonstrate steps of interactive specification by user input;; direct
1.424 - // * calls of the math-engine
1.425 - // */
1.426 - // public void testKBfromWorksheet() throws Exception {
1.427 - // System.out
1.428 - // .println("---BEGIN isac.bridge.TestBridgeSpecify#testKBfromWorksheet");
1.429 - // System.out
1.430 - // .println("---END isac.bridge.TestBridgeSpecify#testKBfromWorksheet");
1.431 - // }
1.432 -
1.433 }
1.434 \ No newline at end of file
2.1 --- a/src/java-tests/isac/bridge/TestSpecify.java Mon Jun 27 15:01:06 2005 +0200
2.2 +++ b/src/java-tests/isac/bridge/TestSpecify.java Mon Jun 27 18:12:55 2005 +0200
2.3 @@ -8,31 +8,292 @@
2.4 */
2.5 package isac.bridge;
2.6
2.7 +import isac.kestore.KEStoreServices;
2.8 +import isac.util.CalcChangedEvent;
2.9 +import isac.util.Formalization;
2.10 +import isac.util.formulae.CalcHead;
2.11 +import isac.util.formulae.Match;
2.12 +import isac.util.formulae.ProblemID;
2.13 +import isac.util.interfaces.ICalcIterator;
2.14 +import isac.util.interfaces.IToCalc;
2.15 +import isac.util.interfaces.IToUser;
2.16 +import isac.util.parser.FormalizationDigest;
2.17 +import isac.util.tactics.SimpleTactic;
2.18 +import isac.util.tactics.StringListTactic;
2.19 +import isac.util.tactics.Tactic;
2.20 +
2.21 +import java.util.Vector;
2.22 +
2.23 import junit.framework.TestCase;
2.24
2.25 /**
2.26 - * @author neuper
2.27 - *
2.28 - * TODO To change the template for this generated type comment go to
2.29 - * Window - Preferences - Java - Code Style - Code Templates
2.30 + * @author Walther Neuper Sep 28, 2004, 3:37:02 PM
2.31 + * @version 1.0
2.32 + * @see isac.functest.specify.TestSpecify for related tests
2.33 */
2.34 public class TestSpecify extends TestCase {
2.35
2.36 - public void testCompleteSpecification() {
2.37 + Formalization fmz_;
2.38 +
2.39 + MathEngine me_;
2.40 +
2.41 + /*
2.42 + * @see TestCase#setUp()
2.43 + */
2.44 + protected void setUp() throws Exception {
2.45 + super.setUp();
2.46 + //load the file of the example,
2.47 + //see TestKEStoreServices#testLoadContentMinisubpbl
2.48 + KEStoreServices ks = new KEStoreServices("isac/xmldata");
2.49 + Vector vec = ks.loadContent("exp", "exp_IsacCore_Tests_7a.xml");
2.50 + //parse out the Formalization
2.51 + //see TestFormalizationDigest#testParseExplMini
2.52 + String xmlstr = (String) vec.firstElement();
2.53 + FormalizationDigest fd = new FormalizationDigest();
2.54 + fmz_ = fd.parseFormalization((String) xmlstr);
2.55 +
2.56 + MathEngine.init("localhost");
2.57 + me_ = MathEngine.getMathEngine();
2.58 + }
2.59 +
2.60 + /**
2.61 + * {\bf\UC{Having \isac{} Complete the
2.62 + * Specification}\label{SPECIFY:COMPLETE:spec_}\\} this is done with the
2.63 + * same button as 'complete CalcHead'
2.64 + *
2.65 + * @see isac.bridge.TestSpecify#testCompleteSpecification() for how this
2.66 + * looks like on the fron-end
2.67 + */
2.68 + public void testCompleteSpecification() throws Exception {
2.69 System.out
2.70 .println("---BEGIN isac.bridge.TestSpecify#testCompleteSpecification");
2.71 - System.out.println("TODO");
2.72 - assertEquals("TODO", "TODO");
2.73 +
2.74 + //start the calculation
2.75 + IToCalc ct = me_.startCalculation(fmz_);
2.76 + IToUser user = new MockIToUser();
2.77 + ct.addDataChangeListener(user);
2.78 + CalcChangedEvent cce = null;
2.79 + ICalcIterator ci = ct.getActiveFormula();
2.80 + CalcHead ch = null;
2.81 + System.out.println(".end step_a-----");
2.82 + //end step_a ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2.83 +
2.84 + //complete the Model ...
2.85 + ct.autoCalculate(IToCalc.SCOPE_MODEL, 0);//FIXXXME.WN0504 completeModel
2.86 + System.out.println(".end step_b-----");
2.87 + //end step_b ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2.88 +
2.89 + //complete the Specification by completeCalcHead
2.90 + ch = (CalcHead) ci.getElement();
2.91 + assertEquals(ch.getSpecification().toSMLString(),
2.92 + "\"e_domID\",[\"e_pblID\"],[\"e_metID\"]");
2.93 + ct.completeCalcHead();
2.94 + ch = (CalcHead) ci.getElement();
2.95 + assertEquals(ch.getSpecification().toSMLString(), "\"DiffApp.thy\","
2.96 + + "[\"maximum_of\",\"function\"],"
2.97 + + "[\"DiffApp\",\"max_by_calculus\"]");
2.98 System.out
2.99 .println("---END isac.bridge.TestSpecify#testCompleteSpecification");
2.100 }
2.101
2.102 - public void testCompleteOneFieldOfSpecification() {
2.103 + /**
2.104 + * {\bf\UC{Having \isac{} Complete One Field of the
2.105 + * Specification}\label{SPECIFY:COMPLETE:specone}\\}
2.106 + *
2.107 + * @see isac.bridge.TestSpecify#testCompleteOneFieldOfSpecification() for
2.108 + * how this looks like on the fron-end
2.109 + */
2.110 + public void testCompleteOneFieldOfSpecification() throws Exception {
2.111 System.out
2.112 .println("---BEGIN isac.bridge.TestSpecify#testCompleteOneFieldOfSpecification");
2.113 - System.out.println("TODO");
2.114 - assertEquals("TODO", "TODO");
2.115 +
2.116 +
2.117 + //start the calculation
2.118 + IToCalc ct = me_.startCalculation(fmz_);
2.119 + IToUser user = new MockIToUser();
2.120 + ct.addDataChangeListener(user);
2.121 + CalcChangedEvent cce = null;
2.122 + ICalcIterator ci = ct.getActiveFormula();
2.123 + CalcHead ch = null;
2.124 + System.out.println(".end step_a-----");
2.125 + //end step_a ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2.126 +
2.127 + //complete the Model ...
2.128 + ct.autoCalculate(IToCalc.SCOPE_MODEL, 0);
2.129 + System.out.println(".end step_b-----");
2.130 + //end step_b ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2.131 +
2.132 + //complete the Specification
2.133 + //could be continued by autoCalculate, i.e. by <Next>-button,
2.134 + //but here by stepwise input
2.135 + ch = (CalcHead) ci.getElement();
2.136 + assertEquals(ch.getSpecification().toSMLString(),
2.137 + "\"e_domID\",[\"e_pblID\"],[\"e_metID\"]");
2.138 + //input the Theory ...
2.139 + Tactic tac = new SimpleTactic("Specify_Theory", "DiffApp.thy");
2.140 + ct.setNextTactic(tac);
2.141 + ch = (CalcHead) ci.getElement();
2.142 + assertEquals(ch.getSpecification().toSMLString(),
2.143 + "\"DiffApp.thy\",[\"e_pblID\"],[\"e_metID\"]");
2.144 + //input the Problem ...
2.145 + Vector keylist = new Vector();
2.146 + keylist.add("maximum_of");
2.147 + keylist.add("function");
2.148 + tac = new StringListTactic("Specify_Problem", keylist);
2.149 + ct.setNextTactic(tac);
2.150 + //input the Method ...
2.151 + keylist = new Vector();
2.152 + keylist.add("DiffApp");
2.153 + keylist.add("max_by_calculus");
2.154 + tac = new StringListTactic("Specify_Method", keylist);
2.155 + ct.setNextTactic(tac);
2.156 + ch = (CalcHead) ci.getElement();
2.157 + assertEquals(ch.getSpecification().toSMLString(), "\"DiffApp.thy\","
2.158 + + "[\"maximum_of\",\"function\"],"
2.159 + + "[\"DiffApp\",\"max_by_calculus\"]");
2.160 System.out
2.161 .println("---END isac.bridge.TestSpecify#testCompleteOneFieldOfSpecification");
2.162 }
2.163 -}
2.164 +
2.165 + /**
2.166 + * {\bf\UC{Having \isac{} Refine the Problem
2.167 + * Automatically}\label{SPECIFY:refine-auto}\\} test match and refine with
2.168 + * x^^^2 + 4*x + 5 = 2 sml/systest/FE-interface.sml --- tryMatchProblem,
2.169 + * tryRefineProblem ---
2.170 + *
2.171 + * @see isac.functest.problems.TestRefinement#testAutomaticallyRefinement()
2.172 + * for how this looks like at the front-end.
2.173 + *
2.174 + * this run requires another example !!!
2.175 + */
2.176 + public void testMatchRefine() throws Exception {
2.177 + System.out.println("---BEGIN isac.bridge.TestModel#testMatchRefine");
2.178 +
2.179 + //load the file of the example,
2.180 + //see TestKEStoreServices#testLoadContentMinisubpbl
2.181 + KEStoreServices ks = new KEStoreServices("isac/xmldata");
2.182 + Vector vec = ks.loadContent("exp", "exp_IsacCore_Tests_1d.xml");
2.183 + //parse out the Formalization
2.184 + //see TestFormalizationDigest#testParseExplMini
2.185 + String xmlstr = (String) vec.firstElement();
2.186 + FormalizationDigest fd = new FormalizationDigest();
2.187 + Formalization fmz = fd.parseFormalization((String) xmlstr);
2.188 + System.out.println(".end step_a-----");
2.189 + //end step_a ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2.190 +
2.191 + //start the calculation
2.192 + MathEngine.init("localhost");
2.193 + MathEngine me = MathEngine.getMathEngine();
2.194 +
2.195 + IToCalc ct = me.startCalculation(fmz);
2.196 + IToUser user = new MockIToUser();
2.197 + ct.addDataChangeListener(user);
2.198 + CalcChangedEvent cce = null;
2.199 + System.out.println(".end step_b-----");
2.200 + //end step_b
2.201 + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2.202 +
2.203 + //fill the CalcHead with Descriptions by 2-times <NEXT>:
2.204 + //tac = Model_Problem ...
2.205 + ct.autoCalculate(IToCalc.SCOPE_CALCULATION, 1);
2.206 + //and one field: tac = Add_Given "equality (x ^^^ 2 + 4 * x + 5 = 2)"
2.207 + ct.autoCalculate(IToCalc.SCOPE_CALCULATION, 1);
2.208 + ICalcIterator ci = ct.getActiveFormula();
2.209 + //end step_c
2.210 + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2.211 + //trymatch ... go into the problem-hierarchy with this CalcHeads Model
2.212 + //this Match will show some incomplete items
2.213 + ProblemID id = new ProblemID();
2.214 + id.addString("univariate");
2.215 + id.addString("equation");
2.216 + Match m = ci.tryMatchProblem(id);
2.217 + assertEquals(m.getHeadline().toSMLString(), "??.empty");//...TODO.WN050626
2.218 + assertEquals(m.getKEStoreID().toSMLString(),
2.219 + "[\"univariate\",\"equation\"]");
2.220 + assertEquals(m.getModel().getGiven().toString(),
2.221 + "[\"incomplete solveFor\", "
2.222 + + "\"correct equality (x ^^^ 2 + 4 * x + 5 = 2)\"]");
2.223 + assertEquals(m.getModel().getWhere().toString(),
2.224 + "[\"correct matches (?a = ?b) (x ^^^ 2 + 4 * x + 5 = 2)\"]");
2.225 + assertEquals(m.getModel().getFind().toString(),
2.226 + "[\"incomplete solutions []\"]");
2.227 + assertEquals(m.getModel().getRelate().toString(), "[]");
2.228 + assertEquals(m.getStatus(), "incorrect");
2.229 + //end step_d
2.230 + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2.231 +
2.232 + //complete the CalcHeads Model in the Worksheet by 2-times <NEXT>:
2.233 + //tac = Add_Given "solveFor x"
2.234 + ct.autoCalculate(IToCalc.SCOPE_CALCULATION, 1);
2.235 + //tac = Add_Find "solutions L"
2.236 + ct.autoCalculate(IToCalc.SCOPE_CALCULATION, 1);
2.237 + //end step_e
2.238 + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2.239 + //trymatch ... go into the problem-hierarchy with this CalcHeads Model
2.240 + //this Match will show all items complete:
2.241 + m = ci.tryMatchProblem(id);
2.242 + assertEquals(m.getHeadline().toSMLString(), "??.empty");//...TODO.WN050626
2.243 + assertEquals(m.getModel().getGiven().toString(),
2.244 + "[\"correct equality (x ^^^ 2 + 4 * x + 5 = 2)\", "
2.245 + + "\"correct solveFor x\"]");
2.246 + assertEquals(m.getModel().getFind().toString(),
2.247 + "[\"correct solutions L\"]");
2.248 + assertEquals(m.getStatus(), "incorrect");//the specification is
2.249 + // missing! TODO.WN0506 correct Match in SML !!!
2.250 +
2.251 + //this _NOT_ a matching problem:
2.252 + id = new ProblemID();
2.253 + id.addString("linear");
2.254 + id.addString("univariate");
2.255 + id.addString("equation");
2.256 + m = ci.tryMatchProblem(id);
2.257 + assertEquals(
2.258 + m.getModel().getWhere().toString(),
2.259 + "[\"false False\", "//WN050626 this seems to be for SMLtesting
2.260 + + "\"correct ~ lhs (x ^^^ 2 + 4 * x + 5 = 2) is_polyrat_in x\", "
2.261 + + "\"correct ~ rhs (x ^^^ 2 + 4 * x + 5 = 2) is_polyrat_in x\", "
2.262 + + "\"false lhs (x ^^^ 2 + 4 * x + 5 = 2) has_degree_in x = 1\", "
2.263 + + "\"false rhs (x ^^^ 2 + 4 * x + 5 = 2) has_degree_in x = 1\"]");
2.264 + //end step_f
2.265 + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2.266 +
2.267 + //search for a matching problem in the problem-hierarchy:
2.268 + //this search _FAILES_ because refine does _NOT_ return a new ProblemID
2.269 + m = ci.tryRefineProblem(id);
2.270 + assertEquals(m.getKEStoreID().toSMLString(),
2.271 + "[\"linear\",\"univariate\",\"equation\"]");
2.272 + //this search is _SUCCESSFUL_ because it returns a _NEW_ ProblemID
2.273 + //(and in this case the Model will _ALWAYS_ be "correct"!)
2.274 + id = new ProblemID();
2.275 + id.addString("univariate");
2.276 + id.addString("equation");
2.277 + m = ci.tryRefineProblem(id);
2.278 + assertEquals(m.getKEStoreID().toSMLString(),
2.279 + "[\"normalize\",\"polynomial\",\"univariate\",\"equation\"]");
2.280 + //end step_g
2.281 + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2.282 +
2.283 + //transfer the problem found back to the Worksheet
2.284 + Vector keylist = new Vector();
2.285 + keylist.add("normalize");
2.286 + keylist.add("polynomial");
2.287 + keylist.add("univariate");
2.288 + keylist.add("equation");
2.289 + Tactic tac = new StringListTactic("Specify_Problem", keylist);
2.290 + ct.setNextTactic(tac);
2.291 + //ct.autoCalculate(IToCalc.SCOPE_CALCULATION, 1);
2.292 + //TODO.WN0506 ... still implicit in setNextTactic
2.293 + CalcHead ch = (CalcHead) ci.getElement();
2.294 + //FIXXME.WN050426 in the CalcHead above the Problem should be set !!!
2.295 + //and the calchead_status_ should be still "incomplete" due to
2.296 + // ..incomplete specification (theory, method missing)
2.297 + //after inserting Theory and Method the CalcHead is complete:
2.298 + ct.autoCalculate(IToCalc.SCOPE_CALCULATION, 1);
2.299 + ct.autoCalculate(IToCalc.SCOPE_CALCULATION, 1);
2.300 + ch = (CalcHead) ci.getElement();
2.301 + assertEquals(ch.getStatusString(), "correct");
2.302 +
2.303 + System.out.println("---END isac.bridge.TestModel#testMatchRefine");
2.304 + }
2.305 +
2.306 +}
2.307 \ No newline at end of file
3.1 --- a/src/java-tests/isac/functest/problems/TestProblemHierarchy.java Mon Jun 27 15:01:06 2005 +0200
3.2 +++ b/src/java-tests/isac/functest/problems/TestProblemHierarchy.java Mon Jun 27 18:12:55 2005 +0200
3.3 @@ -44,4 +44,24 @@
3.4 .println("---END isac.functest.TestProblemHierarchy#testOverviewProblems");
3.5 }
3.6
3.7 + /**
3.8 + * {\bf\UC{Toggle a problem from instantiated to
3.9 + * non-instantiated}\label{UC:match-toggle-no}\\} The problem browser has
3.10 + * been called from a worksheet, and shows the problem instantiated from the
3.11 + * worksheet's context. A toggle-button switches to the plain problem
3.12 + * without instantiation. And vice versa.
3.13 + *
3.14 + * WN050618 diesen UC bitte an JL uebergeben (gehoert dort vermutlich zu
3.15 + * isac.functest.problems.TestProblemHierarchy
3.16 + */
3.17 + public void testToggleProblemInstantiation() {
3.18 + System.out
3.19 + .println("---BEGIN isac.functest.TestModel#testToggleProblemInstantiation");
3.20 + System.out.println("TODO");
3.21 + assertEquals("TODO", "TODO");
3.22 + System.out
3.23 + .println("---END isac.functest.TestModel#testToggleProblemInstantiation");
3.24 + }
3.25 +
3.26 +
3.27 }
3.28 \ No newline at end of file
4.1 --- a/src/java-tests/isac/functest/problems/TestRefinement.java Mon Jun 27 15:01:06 2005 +0200
4.2 +++ b/src/java-tests/isac/functest/problems/TestRefinement.java Mon Jun 27 18:12:55 2005 +0200
4.3 @@ -22,8 +22,9 @@
4.4 * refine the Problem to a best match of the data entered into the Model so
4.5 * far.
4.6 *
4.7 - * @see isac.bridge.TestModel#testMatchRefine() for how the
4.8 - * math-engine's methods are called for this task
4.9 + * @see isac.bridge.TestModel#testMatchRefine() for how the math-engine's
4.10 + * methods are called for this task and for a meaningful context for
4.11 + * refining
4.12 *
4.13 * @todo implement
4.14 * @author JL
5.1 --- a/src/java-tests/isac/functest/specify/TestModel.java Mon Jun 27 15:01:06 2005 +0200
5.2 +++ b/src/java-tests/isac/functest/specify/TestModel.java Mon Jun 27 18:12:55 2005 +0200
5.3 @@ -28,8 +28,8 @@
5.4 * each item with respect to the problem from the hidden specification. No
5.5 * fields of the Specification will be changed.
5.6 *
5.7 - * @see isac.bridge.TestModel#testEditItems() for related
5.8 - * methodcalls directly to the math-engine
5.9 + * @see isac.bridge.TestModel#testEditItems() for related methodcalls
5.10 + * directly to the math-engine
5.11 */
5.12 public void testEditItems() {
5.13 System.out.println("---BEGIN isac.functest.TestModel#testEditItems");
5.14 @@ -41,10 +41,27 @@
5.15 /**
5.16 * {\bf\UC{Having \isac{} Complete the
5.17 * CalcHead}\label{SPECIFY:COMPLETE:all}\\} The user requests a CalcHead,
5.18 - * containing some input, to be completed automatically.
5.19 + * containing some input, to be completed automatically. WN0506 What kind of messed
5.20 + * input should be overwritten/corredted ???
5.21 *
5.22 - * @see isac.bridge.TestModel#testCompleteModel() for related
5.23 - * methodcalls directly to the math-engine
5.24 + * @see isac.bridge.TestModel#testCompleteCalcHead() for related methodcalls
5.25 + * directly to the math-engine
5.26 + */
5.27 + public void testCompleteCalcHead() {
5.28 + System.out
5.29 + .println("---BEGIN isac.functest.TestModel#testCompleteModel");
5.30 + System.out.println("TODO");
5.31 + assertEquals("TODO", "TODO");
5.32 + System.out.println("---END isac.functest.TestModel#testCompleteModel");
5.33 + }
5.34 +
5.35 + /**
5.36 + * The user requests the Model of a CalcHead, containing some input, to be
5.37 + * completed automatically. WN0506 What kind of messed
5.38 + * input should be overwritten/corredted ???
5.39 + *
5.40 + * @see isac.bridge.TestModel#testCompleteModel() for related methodcalls
5.41 + * directly to the math-engine
5.42 */
5.43 public void testCompleteModel() {
5.44 System.out
5.45 @@ -72,23 +89,4 @@
5.46 .println("---END isac.functest.TestModel#testCompleteOneFieldOfModel");
5.47 }
5.48
5.49 - /**
5.50 - * {\bf\UC{Toggle a problem from instantiated to
5.51 - * non-instantiated}\label{UC:match-toggle-no}\\} The problem browser has
5.52 - * been called from a worksheet, and shows the problem instantiated from the
5.53 - * worksheet's context. A toggle-button switches to the plain problem
5.54 - * without instantiation. And vice versa.
5.55 - *
5.56 - * WN050618 diesen UC bitte an JL uebergeben (gehoert dort vermutlich zu
5.57 - * isac.functest.problems.TestProblemHierarchy
5.58 - */
5.59 - public void testToggleProblemInstantiation() {
5.60 - System.out
5.61 - .println("---BEGIN isac.functest.TestModel#testToggleProblemInstantiation");
5.62 - System.out.println("TODO");
5.63 - assertEquals("TODO", "TODO");
5.64 - System.out
5.65 - .println("---END isac.functest.TestModel#testToggleProblemInstantiation");
5.66 - }
5.67 -
5.68 }
5.69 \ No newline at end of file