|
From: <jom...@us...> - 2009-03-17 17:00:37
|
Revision: 1471
http://jason.svn.sourceforge.net/jason/?rev=1471&view=rev
Author: jomifred
Date: 2009-03-17 17:00:23 +0000 (Tue, 17 Mar 2009)
Log Message:
-----------
improve tests for vars as plan body
Modified Paths:
--------------
trunk/applications/as-unit-test/src/jason/tests/TestPlanbodyAsTerm.java
trunk/src/jason/JasonException.java
trunk/src/jason/asSemantics/TransitionSystem.java
trunk/src/test/ASParserTest.java
Modified: trunk/applications/as-unit-test/src/jason/tests/TestPlanbodyAsTerm.java
===================================================================
--- trunk/applications/as-unit-test/src/jason/tests/TestPlanbodyAsTerm.java 2009-03-16 22:06:38 UTC (rev 1470)
+++ trunk/applications/as-unit-test/src/jason/tests/TestPlanbodyAsTerm.java 2009-03-17 17:00:23 UTC (rev 1471)
@@ -21,8 +21,16 @@
"+!test3 <- !g2(-1 + 2)."+
"+!test4 <- X = {a(1); b; c}; !g(X)."+
+ "+!test5 <- !g5(R); jason.asunit.print(R). "+
+ "+!g5(X) <- C; .print(errrrrror). "+
+ "-!g5(X)[error(I),error_msg(M)] <- jason.asunit.print(I,M); X = ok. "+
+
+ "+!test6 <- A = { a }; B = { A }; C = { B }; C; jason.asunit.print(end). "+
+
+ "+!test7(X) <- A = { jason.asunit.print(a,X); jason.asunit.print(b,X*2) }; A; jason.asunit.print(end,X/2). "+
+
"+!g({A; R}) <- A; !g(R). "+
- "+!g(A) <- A." +
+ "+!g(A) <- A." +
"+!g2(A) <- jason.asunit.print(A)."
);
}
@@ -31,7 +39,7 @@
public void testProgram1a() {
ag.addGoal("start");
ag.assertBel("g({a(1);b;c})", 5);
- ag.assertAct("a(1)", 4);
+ ag.assertAct("a(1)", 5);
ag.assertAct("b", 4);
ag.assertAct("c", 4);
}
@@ -56,4 +64,25 @@
ag.assertPrint("1", 5);
}
+ @Test
+ public void test5() {
+ ag.addGoal("test5");
+ ag.assertPrint("body_var_ungroundstringcode:1: Variable 'C' must be ground.",10);
+ ag.assertPrint("ok", 10);
+ }
+
+ @Test
+ public void test6() {
+ ag.addGoal("test6");
+ ag.assertAct("a", 5);
+ ag.assertPrint("end", 5);
+ }
+
+ @Test
+ public void test7() {
+ ag.addGoal("test7(100)");
+ ag.assertPrint("a100", 5);
+ ag.assertPrint("b200", 5);
+ ag.assertPrint("end50", 5);
+ }
}
Modified: trunk/src/jason/JasonException.java
===================================================================
--- trunk/src/jason/JasonException.java 2009-03-16 22:06:38 UTC (rev 1470)
+++ trunk/src/jason/JasonException.java 2009-03-17 17:00:23 UTC (rev 1471)
@@ -118,15 +118,5 @@
return ASSyntax.createList(
ASSyntax.createStructure("error", id),
ASSyntax.createStructure("error_msg", ASSyntax.createString(msg)));
- /*
- ListTerm failAnnots = new ListTermImpl();
- Structure e = new Structure("error", 1);
- e.addTerm(id);
- failAnnots.add(e);
- Structure m = new Structure("error_msg", 1);
- m.addTerm(new StringTermImpl(msg));
- failAnnots.add(m);
- return failAnnots;
- */
}
}
Modified: trunk/src/jason/asSemantics/TransitionSystem.java
===================================================================
--- trunk/src/jason/asSemantics/TransitionSystem.java 2009-03-16 22:06:38 UTC (rev 1470)
+++ trunk/src/jason/asSemantics/TransitionSystem.java 2009-03-17 17:00:23 UTC (rev 1471)
@@ -430,26 +430,32 @@
}
Unifier u = im.unif;
PlanBody h = im.getCurrentStep();
-
+
Term bTerm = h.getBodyTerm();
// de-var bTerm
- while (bTerm instanceof VarTerm) { // TODO: test var in var
+ while (bTerm instanceof VarTerm) {
// h should be ground
Term bValue = u.get((VarTerm)bTerm);
if (bValue == null) { // the case of !A with A not ground
- if (!generateGoalDeletion(conf.C.SI, null)) {
- logger.log(Level.SEVERE, h.getSrcInfo()+": "+ "Variable '"+bTerm+"' must be ground.");
+ String msg = h.getSrcInfo()+": "+ "Variable '"+bTerm+"' must be ground.";
+ if (!generateGoalDeletion(conf.C.SI, JasonException.createBasicErrorAnnots("body_var_unground", msg))) {
+ logger.log(Level.SEVERE, msg);
}
return;
}
if (bValue.isPlanBody()) {
- if (h.getBodyType() != BodyType.action) { // the case of !A with A unified with +g
- if (!generateGoalDeletion(conf.C.SI, null)) {
- logger.log(Level.SEVERE, h.getSrcInfo()+": "+ "The operator '"+h.getBodyType()+"' is lost with the variable unified with a plan body. ");
+ if (h.getBodyType() != BodyType.action) { // the case of ...; A = { !g }; +g; ....
+ String msg = h.getSrcInfo()+": "+ "The operator '"+h.getBodyType()+"' is lost with the variable '"+bTerm+"' unified with a plan body '"+bValue+"'. ";
+ if (!generateGoalDeletion(conf.C.SI, JasonException.createBasicErrorAnnots("body_var_with_op", msg))) {
+ logger.log(Level.SEVERE, msg);
}
return;
}
- h = (PlanBody)bValue; // TODO: change the current plan for the apply of the plan of VAR // the case of A unified with {a;b;c}
+ h = (PlanBody)bValue;
+ if (h.getPlanSize() > 1) { // the case of A unified with {a;b;c}
+ h.add(im.getCurrentStep().getBodyNext());
+ im.insertAsNextStep(h.getBodyNext());
+ }
bTerm = h.getBodyTerm();
} else {
bTerm = bValue;
@@ -678,7 +684,6 @@
IntendedMeans topIM = i.pop();
Literal topLiteral = topIM.getTrigger().getLiteral();
if (logger.isLoggable(Level.FINE)) logger.fine("Returning from IM "+topIM.getPlan().getLabel()+", te="+topIM.getPlan().getTrigger());
-
// if finished a failure handling IM ...
if (im.getTrigger().isGoal() && !im.getTrigger().isAddition() && i.size() > 0) {
// needs to get rid of the IM until a goal that
@@ -691,8 +696,9 @@
// should became
// +!s: !z
im = i.peek();
- if (im.isFinished() || !im.unif.unifies(im.getCurrentStep().getBodyTerm(), topLiteral))
+ if (im.isFinished() || !im.unif.unifies(im.getCurrentStep().getBodyTerm(), topLiteral) || im.getCurrentStep().getBodyTerm() instanceof VarTerm) {
im = i.pop(); // +!c above
+ }
while (i.size() > 0 &&
!im.unif.unifies(im.getTrigger().getLiteral(), topLiteral) &&
!im.unif.unifies(im.getCurrentStep().getBodyTerm(), topLiteral)) {
@@ -703,30 +709,11 @@
im = i.peek(); // +!s or +?s
if (!im.isFinished()) {
// removes !b or ?s
- /* I am trying against comments below and use topIM.getTrigger!
- * since I don't remember why the trigger cann't be used
- * probably the reason is the old buggy makeVarAnnos
-
- Term g = im.removeCurrentStep();
- // make the TE of finished plan ground and unify that
- // with goal/test in the body (to "return" values).
- // (it must be the plan TE and not the IM.trigger because the
- // vars have name only in the plan TE, in the IM.trigger
- // they are anonymous)
- Literal tel = topIM.getPlan().getTrigger().getLiteral();
- // but import annots from IM.trigger
- tel.addAnnots(topIM.getTrigger().getLiteral().getAnnots());
- tel.topLiteral.makeVarsAnnon(topIM.unif);
- */
// unifies the final event with the body that called it
topLiteral.apply(topIM.unif);
im.unif.unifies(im.removeCurrentStep(), topLiteral);
}
}
-
- // the new top may have become
- // empty! need to keep checking.
- //applyClrInt(i);
}
}
@@ -924,7 +911,7 @@
// code
if (eventLiteral.getAnnots("code").isEmpty())
- eventLiteral.addAnnot(ASSyntax.createStructure("code", bodyterm));
+ eventLiteral.addAnnot(ASSyntax.createStructure("code", ASSyntax.createString(bodyterm.toString())));
// ASL source
if (eventLiteral.getAnnots("code_src").isEmpty())
Modified: trunk/src/test/ASParserTest.java
===================================================================
--- trunk/src/test/ASParserTest.java 2009-03-16 22:06:38 UTC (rev 1470)
+++ trunk/src/test/ASParserTest.java 2009-03-17 17:00:23 UTC (rev 1471)
@@ -20,6 +20,7 @@
import jason.asSyntax.Structure;
import jason.asSyntax.Term;
import jason.asSyntax.Trigger;
+import jason.asSyntax.PlanBody.BodyType;
import jason.asSyntax.parser.ParseException;
import jason.asSyntax.parser.as2j;
import jason.infra.centralised.CentralisedAgArch;
@@ -194,6 +195,11 @@
pb = (PlanBody)ASSyntax.parseTerm("{ }");
assertEquals(0, pb.getPlanSize());
+
+ pb = (PlanBody)ASSyntax.parseTerm("{ a; B}");
+ assertEquals(2, pb.getPlanSize());
+ assertEquals(BodyType.action, pb.getBodyType());
+ assertEquals(BodyType.action, pb.getBodyNext().getBodyType()); // B must be considered as action, see TS
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|