wneuper@4710
|
1 |
package isac.bridge;
|
wneuper@4710
|
2 |
|
wneuper@4748
|
3 |
import isac.bridge.xml.IntCalcFormula;
|
wneuper@4748
|
4 |
import isac.bridge.xml.IntCChanged;
|
wneuper@4748
|
5 |
import isac.bridge.xml.IntIntCompound;
|
wneuper@4748
|
6 |
import isac.bridge.xml.IntFormHead;
|
wneuper@4748
|
7 |
import isac.bridge.xml.IntFormulas;
|
wneuper@4748
|
8 |
import isac.bridge.xml.IntPosition;
|
wneuper@4758
|
9 |
import isac.bridge.xml.DataTypes; //.scala
|
wneuper@4748
|
10 |
import isac.bridge.xml.JavaToIsa; //.scala
|
wneuper@4748
|
11 |
import isac.bridge.xml.IsaToJava; //.scala
|
wneuper@4748
|
12 |
|
wneuper@4748
|
13 |
import isac.util.formulae.CalcFormula;
|
wneuper@4748
|
14 |
import isac.util.formulae.CalcHead;
|
wneuper@4725
|
15 |
import isac.util.formulae.CalcHeadSimpleID;
|
wneuper@4725
|
16 |
import isac.util.formulae.HierarchyKey;
|
wneuper@4748
|
17 |
import isac.util.formulae.Model;
|
wneuper@4748
|
18 |
import isac.util.formulae.ModelItem;
|
wneuper@4748
|
19 |
import isac.util.formulae.Position;
|
wneuper@4725
|
20 |
import isac.util.formulae.Specification;
|
wneuper@4748
|
21 |
import isac.util.Formalization;
|
wneuper@4725
|
22 |
import isac.util.Variant;
|
wneuper@4724
|
23 |
|
wneuper@4710
|
24 |
import edu.tum.cs.isabelle.japi.JSystem;
|
wneuper@4710
|
25 |
import edu.tum.cs.isabelle.japi.Operations;
|
wneuper@4715
|
26 |
import isabelle.XML;
|
wneuper@4710
|
27 |
|
wneuper@4710
|
28 |
import java.io.File;
|
wneuper@4715
|
29 |
import java.math.BigInteger;
|
wneuper@4716
|
30 |
import java.util.Vector;
|
wneuper@4710
|
31 |
import junit.framework.TestCase;
|
wneuper@4710
|
32 |
|
wneuper@4710
|
33 |
public class TestPIDE extends TestCase {
|
wneuper@4710
|
34 |
|
wneuper@4733
|
35 |
/*
|
wneuper@4733
|
36 |
* ISABELLE_HOME is set by "isabelle.Isabelle_System.init",
|
wneuper@4733
|
37 |
* the connection to Isabelle/Isac by "JSystem.instance".
|
wneuper@4710
|
38 |
*/
|
wneuper@4710
|
39 |
public void testConnection() {
|
wneuper@4710
|
40 |
System.out.println("/--BEGIN isac.bridge.TestPIDE#testConnection");
|
wneuper@4710
|
41 |
|
wneuper@4710
|
42 |
System.out.println("---1 isac.bridge.TestPIDE#testConnection");
|
wneuper@4714
|
43 |
isabelle.Isabelle_System.init("/usr/local/isabisac", "");
|
wneuper@4729
|
44 |
|
wneuper@4729
|
45 |
System.out.println("---2 isac.bridge.TestPIDE#testConnection");
|
wneuper@4714
|
46 |
JSystem sys = JSystem.instance(new File("/home/wneuper/proto4/libisabelle/."), "Protocol");
|
wneuper@4710
|
47 |
|
wneuper@4729
|
48 |
System.out.println("---3 isac.bridge.TestPIDE#testConnection");
|
wneuper@4714
|
49 |
String hello_out = sys.invoke(Operations.HELLO, "should-be-returned");
|
wneuper@4710
|
50 |
|
wneuper@4729
|
51 |
System.out.println("---4 isac.bridge.TestPIDE#testConnection");
|
wneuper@4714
|
52 |
assertEquals(hello_out,"Hello should-be-returned");
|
wneuper@4710
|
53 |
|
wneuper@4729
|
54 |
System.out.println("---5 isac.bridge.TestPIDE#testConnection");
|
wneuper@4729
|
55 |
sys.dispose();
|
wneuper@4729
|
56 |
|
wneuper@4729
|
57 |
System.out.println("\\--END isac.bridge.TestPIDE#testConnection");
|
wneuper@4710
|
58 |
}
|
wneuper@4710
|
59 |
|
wneuper@4710
|
60 |
/*
|
wneuper@4710
|
61 |
* transfer the minimal test from libisabelle to isac-java:
|
wneuper@4710
|
62 |
* https://github.com/wneuper/libisabelle/blob/master/examples/src/main/java/Mini_Test.java
|
wneuper@4710
|
63 |
* which has been derived from:
|
wneuper@4710
|
64 |
* https://github.com/wneuper/libisabelle/blob/master/doc/test--isac-Java--isac-kernel.txt
|
wneuper@4710
|
65 |
*/
|
wneuper@4710
|
66 |
public void testMini_Test() {
|
wneuper@4710
|
67 |
System.out.println("/--BEGIN isac.bridge.TestPIDE#testMini_Test");
|
wneuper@4715
|
68 |
|
wneuper@4715
|
69 |
isabelle.Isabelle_System.init("/usr/local/isabisac", "");
|
wneuper@4715
|
70 |
JSystem sys = JSystem.instance(new File("/home/wneuper/proto4/libisabelle/."), "Protocol");
|
wneuper@4715
|
71 |
|
wneuper@4716
|
72 |
//----- step 1 ----------------------------------------------------------------
|
wneuper@4725
|
73 |
//build Formalization in Java and then convert to XML
|
wneuper@4725
|
74 |
CalcHeadSimpleID thy = new CalcHeadSimpleID();
|
wneuper@4725
|
75 |
thy.setID("Test");
|
wneuper@4725
|
76 |
HierarchyKey pbl = new HierarchyKey();
|
wneuper@4725
|
77 |
pbl.addString("sqroot-test");
|
wneuper@4725
|
78 |
pbl.addString("univariate");
|
wneuper@4725
|
79 |
pbl.addString("equation");
|
wneuper@4725
|
80 |
pbl.addString("test");
|
wneuper@4725
|
81 |
HierarchyKey met = new HierarchyKey();
|
wneuper@4725
|
82 |
met.addString("Test");
|
wneuper@4725
|
83 |
met.addString("squ-equ-test-subpbl1");
|
wneuper@4725
|
84 |
Specification spec = new Specification();
|
wneuper@4725
|
85 |
spec.setTheory(thy);
|
wneuper@4725
|
86 |
spec.setProblem(pbl);
|
wneuper@4725
|
87 |
spec.setMethod(met);
|
wneuper@4725
|
88 |
Variant vat = new Variant();
|
wneuper@4725
|
89 |
vat.addNewIsaString("equality (x+1=(2::real))");
|
wneuper@4725
|
90 |
vat.addNewIsaString("solveFor x");
|
wneuper@4725
|
91 |
vat.addNewIsaString("solutions L");
|
wneuper@4725
|
92 |
vat.setSpecification(spec);
|
wneuper@4725
|
93 |
Formalization fmz = new Formalization();
|
wneuper@4725
|
94 |
fmz.addNewVariant(vat);
|
wneuper@4716
|
95 |
XML.Tree CALC_TREE_out = sys.invoke(Operations.CALC_TREE,
|
wneuper@4758
|
96 |
DataTypes.xml_of_Formalization(fmz));
|
wneuper@4724
|
97 |
int calcid = (IsaToJava.calc_tree_out(CALC_TREE_out)).intValue();
|
wneuper@4717
|
98 |
assertEquals(calcid, 1);
|
wneuper@4729
|
99 |
System.out.println("# 1 # " + CALC_TREE_out);
|
wneuper@4725
|
100 |
|
wneuper@4716
|
101 |
//----- step 2 ----------------------------------------------------------------
|
wneuper@4716
|
102 |
XML.Tree ITERATOR_out = sys.invoke(Operations.ITERATOR,
|
wneuper@4715
|
103 |
new scala.math.BigInt(BigInteger.valueOf(calcid)));
|
wneuper@4724
|
104 |
IntIntCompound int_int = IsaToJava.iterator_out(ITERATOR_out);
|
wneuper@4717
|
105 |
calcid = int_int.get_calcid().intValue();
|
wneuper@4717
|
106 |
int userid = int_int.get_userid().intValue();
|
wneuper@4717
|
107 |
assertEquals(calcid, 1);
|
wneuper@4717
|
108 |
assertEquals(userid, 1);
|
wneuper@4729
|
109 |
System.out.println("# 2 # " + ITERATOR_out);
|
wneuper@4715
|
110 |
|
wneuper@4716
|
111 |
//----- step 3 ----------------------------------------------------------------
|
wneuper@4716
|
112 |
XML.Tree MOVE_ACTIVE_ROOT_out = sys.invoke(Operations.MOVE_ACTIVE_ROOT,
|
wneuper@4715
|
113 |
new scala.math.BigInt(BigInteger.valueOf(calcid)));
|
wneuper@4724
|
114 |
IntPosition calcid_pos = IsaToJava.move_active_root_out(MOVE_ACTIVE_ROOT_out);
|
wneuper@4722
|
115 |
calcid = calcid_pos.getCalcId();
|
wneuper@4722
|
116 |
Position pos = calcid_pos.getPos();
|
wneuper@4717
|
117 |
assertEquals(pos.toSMLString(), "([],Pbl)");
|
wneuper@4729
|
118 |
System.out.println("# 3 # " + MOVE_ACTIVE_ROOT_out);
|
wneuper@4715
|
119 |
|
wneuper@4727
|
120 |
//----- step 4 ----------------------------------------------------------------
|
wneuper@4727
|
121 |
Position from = new Position();
|
wneuper@4727
|
122 |
from.setKind("Pbl");
|
wneuper@4727
|
123 |
Position to = new Position();
|
wneuper@4727
|
124 |
to.setKind("Pbl");
|
wneuper@4727
|
125 |
int level = 0;
|
wneuper@4749
|
126 |
boolean rules = false;
|
wneuper@4727
|
127 |
XML.Tree GET_FORMULAE_out = sys.invoke(Operations.GET_FORMULAE,
|
wneuper@4727
|
128 |
JavaToIsa.get_formulae(new scala.math.BigInt(BigInteger.valueOf(calcid)),
|
wneuper@4727
|
129 |
from, to, new scala.math.BigInt(BigInteger.valueOf(level)), rules));
|
wneuper@4729
|
130 |
IntFormulas calcid_forms = IsaToJava.get_formulae_out(GET_FORMULAE_out);
|
wneuper@4729
|
131 |
calcid = calcid_forms.getCalcId();
|
wneuper@4729
|
132 |
Vector<CalcFormula> forms = calcid_forms.getCalcFormulas();
|
wneuper@4729
|
133 |
assertEquals(forms.size(), 1);
|
wneuper@4729
|
134 |
assertEquals(((CalcFormula)forms.elementAt(0)).getFormula(), "solve (x + 1 = 2, x)");
|
wneuper@4729
|
135 |
System.out.println("# 4 # " + GET_FORMULAE_out);
|
wneuper@4715
|
136 |
|
wneuper@4716
|
137 |
//----- step 6 ----------------------------------------------------------------
|
wneuper@4727
|
138 |
pos = new Position();
|
wneuper@4727
|
139 |
pos.setKind("Pbl");
|
wneuper@4716
|
140 |
XML.Tree REF_FORMULA_out = sys.invoke(Operations.REF_FORMULA,
|
wneuper@4727
|
141 |
JavaToIsa.ref_formula(new scala.math.BigInt(BigInteger.valueOf(calcid)), pos));
|
wneuper@4731
|
142 |
System.out.println("# 6 before IsaToJava.ref_formula_out");
|
wneuper@4748
|
143 |
IntFormHead calcid_formhead = IsaToJava.ref_formula_out(REF_FORMULA_out);
|
wneuper@4748
|
144 |
calcid = calcid_formhead.getCalcId();
|
wneuper@4748
|
145 |
assertEquals(calcid, 1);
|
wneuper@4748
|
146 |
|
wneuper@4748
|
147 |
CalcHead ch = (CalcHead)(calcid_formhead.getFormHead());
|
wneuper@4748
|
148 |
assertEquals(ch.getPosition().toSMLString(), "([],Pbl)");
|
wneuper@4748
|
149 |
assertEquals(ch.getHeadLine().toSMLString(), "solve (x + 1 = 2, x)");
|
wneuper@4748
|
150 |
|
wneuper@4748
|
151 |
Model model = ch.getModel();
|
wneuper@4748
|
152 |
assertEquals(model.getGiven().getItems().size(), 0);
|
wneuper@4748
|
153 |
assertEquals(model.getWhere().getItems().size(), 1);
|
wneuper@4748
|
154 |
assertEquals(((ModelItem)model.getWhere().getItems().elementAt(0)).getItemStatus(), "false");
|
wneuper@4748
|
155 |
assertEquals(((ModelItem)model.getWhere().getItems().elementAt(0)).toSMLString(), "precond_rootpbl v_v");
|
wneuper@4748
|
156 |
|
wneuper@4748
|
157 |
assertEquals(ch.getBelongsTo(), "Pbl");
|
wneuper@4748
|
158 |
|
wneuper@4748
|
159 |
spec = ch.getSpecification();
|
wneuper@4748
|
160 |
assertEquals(spec.getTheory().toString(), "e_domID\n");
|
wneuper@4748
|
161 |
assertEquals(spec.getProblem().toSMLString(), "[\"e_pblID\"]");
|
wneuper@4748
|
162 |
assertEquals(spec.getMethod().toSMLString(), "[\"e_metID\"]");
|
wneuper@4729
|
163 |
|
wneuper@4729
|
164 |
System.out.println("# 6 # " + REF_FORMULA_out);
|
wneuper@4715
|
165 |
|
wneuper@4716
|
166 |
//----- step 7 ----------------------------------------------------------------
|
wneuper@4753
|
167 |
String scope = "CompleteCalc";
|
wneuper@4716
|
168 |
XML.Tree AUTO_CALC_out = sys.invoke(Operations.AUTO_CALC,
|
wneuper@4753
|
169 |
JavaToIsa.auto_calculate(new scala.math.BigInt(BigInteger.valueOf(calcid)), scope,
|
wneuper@4753
|
170 |
new scala.math.BigInt(BigInteger.valueOf(0))));
|
wneuper@4724
|
171 |
IntCChanged calcid_cc = IsaToJava.auto_calc_out(AUTO_CALC_out);
|
wneuper@4722
|
172 |
calcid = calcid_cc.getCalcId();
|
wneuper@4722
|
173 |
CChanged cc = calcid_cc.getCChanged();
|
wneuper@4722
|
174 |
assertEquals(cc.getLastUnchanged().toSMLString(), "([],Pbl)");
|
wneuper@4722
|
175 |
assertEquals(cc.getLastDeleted().toSMLString(), "([],Pbl)");
|
wneuper@4722
|
176 |
assertEquals(cc.getLastGenerated().toSMLString(), "([],Res)");
|
wneuper@4729
|
177 |
System.out.println("# 7 # " + AUTO_CALC_out);
|
wneuper@4715
|
178 |
|
wneuper@4716
|
179 |
//----- step 10 ---------------------------------------------------------------
|
wneuper@4727
|
180 |
pos = new Position();
|
wneuper@4727
|
181 |
pos.setKind("Res");
|
wneuper@4716
|
182 |
REF_FORMULA_out = sys.invoke(Operations.REF_FORMULA,
|
wneuper@4727
|
183 |
JavaToIsa.ref_formula(new scala.math.BigInt(BigInteger.valueOf(calcid)), pos));
|
wneuper@4731
|
184 |
|
wneuper@4748
|
185 |
calcid_formhead = IsaToJava.ref_formula_out(REF_FORMULA_out);
|
wneuper@4731
|
186 |
calcid = calcid_formhead.getCalcId().intValue();
|
wneuper@4731
|
187 |
// later here we shall check for CalcFormula OR CalcHead
|
wneuper@4731
|
188 |
CalcFormula form = (CalcFormula)calcid_formhead.getFormHead();
|
wneuper@4731
|
189 |
form.getFormula();
|
wneuper@4731
|
190 |
assertEquals(form.getPosition().toSMLString(), "([],Res)");
|
wneuper@4731
|
191 |
assertEquals(form.toString(), "[x = 1]");
|
wneuper@4715
|
192 |
System.out.println("# 10 # " + REF_FORMULA_out);
|
wneuper@4715
|
193 |
|
wneuper@4716
|
194 |
//----- step 13 ---------------------------------------------------------------
|
wneuper@4716
|
195 |
XML.Tree DEL_CALC_out = sys.invoke(Operations.DEL_CALC,
|
wneuper@4715
|
196 |
new scala.math.BigInt(BigInteger.valueOf(calcid)));
|
wneuper@4724
|
197 |
calcid = IsaToJava.del_calc_out(DEL_CALC_out).intValue();
|
wneuper@4717
|
198 |
assertEquals(calcid, 1);
|
wneuper@4715
|
199 |
System.out.println("# 13 # " + DEL_CALC_out);
|
wneuper@4715
|
200 |
|
wneuper@4715
|
201 |
sys.dispose();
|
wneuper@4715
|
202 |
|
wneuper@4710
|
203 |
System.out.println("\\--END isac.bridge.TestPIDE##testMini_Test");
|
wneuper@4710
|
204 |
}
|
wneuper@4710
|
205 |
}
|