Skip to content

Commit fa80986

Browse files
authored
Version 2 beta files for review
1 parent e8b320b commit fa80986

File tree

4 files changed

+187
-25
lines changed

4 files changed

+187
-25
lines changed

BehaviouralFeature.java

Lines changed: 73 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -183,31 +183,55 @@ else if (parameters.size() == 0) {}
183183

184184
public Vector testCases()
185185
{ Vector allattributes = getParameters();
186+
Vector preattributes = new Vector();
187+
preattributes.addAll(allattributes);
188+
if (entity != null)
189+
{ preattributes.addAll(entity.getLocalFeatures()); }
190+
186191
String nme = getName();
187192
Vector res = new Vector();
188-
if (allattributes == null || allattributes.size() == 0)
189-
{ res.add("-- no test for operation " + nme + "\n");
190-
return res;
191-
}
192-
Vector test0 = new Vector();
193-
test0.add(nme);
194-
test0.add("-- test for operation " + nme + "\n");
195-
res.add(test0);
193+
if (preattributes == null || preattributes.size() == 0)
194+
{ res.add("-- no test for operation " + nme + "\n");
195+
return res;
196+
}
197+
198+
java.util.Map upperBounds = new java.util.HashMap();
199+
java.util.Map lowerBounds = new java.util.HashMap();
200+
201+
Vector test0 = new Vector();
202+
test0.add(nme);
203+
test0.add("-- tests for operation " + nme + "\n");
204+
res.add(test0);
205+
206+
Expression pre = precondition();
207+
if (pre != null)
208+
{ Vector bounds = new Vector();
209+
java.util.Map aBounds = new java.util.HashMap();
210+
pre.getParameterBounds(preattributes,bounds,aBounds);
211+
212+
213+
identifyUpperBounds(allattributes,aBounds,upperBounds);
214+
identifyLowerBounds(allattributes,aBounds,lowerBounds);
215+
System.out.println(".>> Parameter bounds for operation " + nme + " : " + aBounds);
216+
System.out.println(".>> Upper bounds map for operation " + nme + " : " + upperBounds);
217+
System.out.println(".>> Lower bounds map for operation " + nme + " : " + lowerBounds);
218+
}
196219

197220
for (int i = 0; i < allattributes.size(); i++)
198221
{ Vector newres = new Vector();
199222
Attribute att = (Attribute) allattributes.get(i);
200-
Vector testassignments = att.testCases("parameters");
223+
Vector testassignments = att.testCases("parameters", lowerBounds, upperBounds);
224+
201225
for (int j = 0; j < res.size(); j++)
202226
{ Vector oldtest = (Vector) res.get(j);
203-
String tst = (String) oldtest.get(1);
227+
String tst = (String) oldtest.get(1);
204228
for (int k = 0; k < testassignments.size(); k++)
205229
{ String kstr = (String) testassignments.get(k);
206230
if (kstr.length() > 0)
207231
{ String newtst = tst + "\n" + kstr;
208-
Vector optest = new Vector();
209-
optest.add(nme);
210-
optest.add(newtst);
232+
Vector optest = new Vector();
233+
optest.add(nme);
234+
optest.add(newtst);
211235
newres.add(optest);
212236
}
213237
}
@@ -216,7 +240,39 @@ public Vector testCases()
216240
res.addAll(newres);
217241
}
218242
return res;
219-
}
243+
}
244+
245+
private void identifyUpperBounds(Vector atts, java.util.Map boundConstraints, java.util.Map upperBounds)
246+
{ for (int i = 0; i < atts.size(); i++)
247+
{ Attribute att = (Attribute) atts.get(i);
248+
String aname = att.getName();
249+
Vector bpreds = (Vector) boundConstraints.get(aname);
250+
if (bpreds != null)
251+
{ for (int j = 0; j < bpreds.size(); j++)
252+
{ BinaryExpression pred = (BinaryExpression) bpreds.get(j);
253+
Expression ubound = pred.getUpperBound(aname);
254+
if (ubound != null)
255+
{ upperBounds.put(aname,ubound); }
256+
}
257+
}
258+
}
259+
}
260+
261+
private void identifyLowerBounds(Vector atts, java.util.Map boundConstraints, java.util.Map lowerBounds)
262+
{ for (int i = 0; i < atts.size(); i++)
263+
{ Attribute att = (Attribute) atts.get(i);
264+
String aname = att.getName();
265+
Vector bpreds = (Vector) boundConstraints.get(aname);
266+
if (bpreds != null)
267+
{ for (int j = 0; j < bpreds.size(); j++)
268+
{ BinaryExpression pred = (BinaryExpression) bpreds.get(j);
269+
Expression lbound = pred.getLowerBound(aname);
270+
if (lbound != null)
271+
{ lowerBounds.put(aname,lbound); }
272+
}
273+
}
274+
}
275+
}
220276

221277
public Vector getReadFrame()
222278
{ if (readfr != null) { return readfr; } // to avoid recursion
@@ -397,6 +453,9 @@ public void setPost(Expression p)
397453
public void setPrecondition(Expression p)
398454
{ pre = p; }
399455

456+
public Expression precondition()
457+
{ return pre; }
458+
400459
public void setPostcondition(Expression p)
401460
{ post = p; }
402461

BinaryExpression.java

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2014,7 +2014,72 @@ public Expression excel2Ocl(Entity target, Vector entities, Vector qvars, Vector
20142014
enew.right = right.excel2Ocl(target, entities, qvars, antes);
20152015
return enew;
20162016
}
2017+
2018+
public void getParameterBounds(Vector atts, Vector bounds, java.util.Map attBounds)
2019+
{ if ("&".equals(operator))
2020+
{ left.getParameterBounds(atts,bounds,attBounds);
2021+
right.getParameterBounds(atts,bounds,attBounds);
2022+
}
2023+
else if ("<".equals(operator) || "<=".equals(operator) || ">".equals(operator) || "=".equals(operator) ||
2024+
">=".equals(operator))
2025+
{ bounds.add(this);
2026+
2027+
for (int i = 0; i < atts.size(); i++)
2028+
{ Attribute attr = (Attribute) atts.get(i);
2029+
if ((left + "").equals(attr + "") ||
2030+
(right + "").equals(attr + ""))
2031+
{ Vector abounds = (Vector) attBounds.get(attr + "");
2032+
if (abounds == null)
2033+
{ abounds = new Vector(); }
2034+
abounds.add(this);
2035+
attBounds.put(attr + "", abounds);
2036+
}
2037+
}
2038+
}
2039+
}
20172040

2041+
public Expression getUpperBound(String attname)
2042+
{ if (("<".equals(operator) ||
2043+
"<=".equals(operator) ||
2044+
"=".equals(operator)) &&
2045+
attname.equals(left + "") &&
2046+
(right.umlkind == VALUE ||
2047+
Expression.isValue(right))
2048+
)
2049+
{ return right; }
2050+
2051+
if ((">".equals(operator) ||
2052+
">=".equals(operator) ||
2053+
"=".equals(operator)) &&
2054+
attname.equals(right + "") &&
2055+
(left.umlkind == VALUE || Expression.isValue(left))
2056+
)
2057+
{ return left; }
2058+
2059+
return null;
2060+
}
2061+
2062+
public Expression getLowerBound(String attname)
2063+
{ if (("<".equals(operator) ||
2064+
"<=".equals(operator) ||
2065+
"=".equals(operator)) &&
2066+
attname.equals(right + "") &&
2067+
(left.umlkind == VALUE || Expression.isValue(left))
2068+
)
2069+
{ return left; }
2070+
2071+
if ((">".equals(operator) ||
2072+
">=".equals(operator) ||
2073+
"=".equals(operator)) &&
2074+
attname.equals(left + "") &&
2075+
(right.umlkind == VALUE || Expression.isValue(right))
2076+
)
2077+
{ return right; }
2078+
2079+
return null;
2080+
}
2081+
2082+
20182083
// The following turns x : e & P & l = g & Q into [x,P,l,Q] in allvars
20192084
public Vector splitToCond0Cond1(Vector conds, Vector pars,
20202085
Vector qvars, Vector lvars, Vector allvars)

Expression.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,42 @@ public int upperBound()
243243
return 1;
244244
}
245245

246+
public void getParameterBounds(Vector pars, Vector bounds, java.util.Map attBounds)
247+
{ }
248+
249+
public static void identifyUpperBounds(Vector atts, java.util.Map boundConstraints, java.util.Map upperBounds)
250+
{ for (int i = 0; i < atts.size(); i++)
251+
{ Attribute att = (Attribute) atts.get(i);
252+
String aname = att.getName();
253+
Vector bpreds = (Vector) boundConstraints.get(aname);
254+
if (bpreds != null)
255+
{ for (int j = 0; j < bpreds.size(); j++)
256+
{ BinaryExpression pred = (BinaryExpression) bpreds.get(j);
257+
Expression ubound = pred.getUpperBound(aname);
258+
if (ubound != null)
259+
{ upperBounds.put(aname,ubound); }
260+
}
261+
}
262+
}
263+
}
264+
265+
public static void identifyLowerBounds(Vector atts, java.util.Map boundConstraints, java.util.Map lowerBounds)
266+
{ for (int i = 0; i < atts.size(); i++)
267+
{ Attribute att = (Attribute) atts.get(i);
268+
String aname = att.getName();
269+
Vector bpreds = (Vector) boundConstraints.get(aname);
270+
if (bpreds != null)
271+
{ for (int j = 0; j < bpreds.size(); j++)
272+
{ BinaryExpression pred = (BinaryExpression) bpreds.get(j);
273+
Expression lbound = pred.getLowerBound(aname);
274+
if (lbound != null)
275+
{ lowerBounds.put(aname,lbound); }
276+
}
277+
}
278+
}
279+
}
280+
281+
246282
public static boolean isSimpleEntity(Expression ee)
247283
{ if (ee == null)
248284
{ return false; }

UCDArea.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20047,17 +20047,19 @@ public void testCases()
2004720047
Vector optests = e.operationTestCases();
2004820048
System.out.println("*** Test cases for entity " + e.getName() + " operations written to output/tests");
2004920049
for (int j = 0; j < optests.size(); j++)
20050-
{ Vector otest = (Vector) optests.get(j);
20051-
String oname = (String) otest.get(0);
20052-
String otxt = (String) otest.get(1);
20053-
try
20054-
{ PrintWriter rout = new PrintWriter(
20055-
new BufferedWriter(
20056-
new FileWriter("output/tests/" + oname + "test" + e.getName() + "_" + j + ".txt")));
20057-
rout.println(otxt);
20058-
rout.close();
20059-
}
20060-
catch (Exception _x) { }
20050+
{ if (optests.get(j) instanceof Vector)
20051+
{ Vector otest = (Vector) optests.get(j);
20052+
String oname = otest.get(0) + "";
20053+
String otxt = otest.get(1) + "";
20054+
try
20055+
{ PrintWriter rout = new PrintWriter(
20056+
new BufferedWriter(
20057+
new FileWriter("output/tests/" + oname + "test" + e.getName() + "_" + j + ".txt")));
20058+
rout.println(otxt);
20059+
rout.close();
20060+
}
20061+
catch (Exception _x) { }
20062+
}
2006120063
}
2006220064
}
2006320065

0 commit comments

Comments
 (0)